moment-dt
TypeScript icon, indicating that this package has built-in type declarations

1.0.7 • Public • Published

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" 
// }

Package Sidebar

Install

npm i moment-dt

Weekly Downloads

8

Version

1.0.7

License

MIT

Unpacked Size

61.1 kB

Total Files

15

Last publish

Collaborators

  • smartin85