1.0.7 • Published 3 years ago

moment-dt v1.0.7

Weekly downloads
8
License
MIT
Repository
github
Last release
3 years ago

moment-dt

MIT License npm version npm downloads Build Status Coverage Status Known Vulnerabilities

Buy me a coffee

Convert utc-unix-timestamp-with-timezone-objects from and to moment.js

Getting Started

moment-dt can be included in your app by different ways:

Node.js

moment-dt can be installed with npm and required into a script:

npm install --save moment-dt
var moment = require('moment-timezone');
require('moment-dt');

Browser

Just include the momentjs script and then the moment-dt script:

<script src="moment.js"></script>
<script src="moment-timezone-with-data.js"></script>
<script src="moment-dt.min.js"></script>

Browser with Require.js

define(["moment-timezone-with-data", "moment-dt"], function (moment) {
    // you probably won´t need a reference to moment-dt istself, so include it last
});

Bower

bower install --save moment-dt

Creating a moment from a dt-object

var obj = { ts: 1486920600, tz: "Europe/Berlin" };
var myMoment = moment.dt(obj);

myMoment.format();
// "2017-02-12T18:30:00+01:00"

moment.dt({ ts: null, tz: "Europe/Berlin" }).format(); 
// "Invalid date"

moment.dt({ ts: 1486920600, tz: null }).format(); 
// ERR: Moment Timezone has no data for invalid timezone.
// "2017-02-12T18:30:00+01:00" local time

Creating a dt-object from a moment

moment.dt({ ts: 1486920600, tz: "Europe/Berlin" }).dt();
// { 
//     ts: 1486920600, 
//     tz: "Europe/Berlin" 
// }

moment.dt({ ts: null, tz: "Europe/Berlin" }).dt();
// { 
//     ts: null, 
//     tz: "Europe/Berlin" 
// }

moment.dt({ ts: 1486920600, tz: null }).dt();
// ERR: Moment Timezone has no data for invalid timezone.
// { 
//     ts: 1486920600, 
//     tz: null 
// }

moment.dt({ ts: 1486920600, tz: "Europe/Berlin" }).add(1, 'year').dt();
// { 
//     ts: 1518456600, 
//     tz: "Europe/Berlin" 
// }
1.0.7

3 years ago

1.0.6

6 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago