From ad53e8e341ed9ac9f6952459c308b882e34f1859 Mon Sep 17 00:00:00 2001 From: Michael Lechner Date: Mon, 13 Mar 2017 19:20:02 -0600 Subject: [PATCH 01/23] added grunt, updated tests, all 'from' conversions --- .eslintrc | 3 +- Gruntfile.js | 38 +++++++ moment-msdate.js | 169 ++++++++++++++++++++++------- package.json | 6 +- test/test.js | 269 ++++++++++++++++++++++++++++++----------------- 5 files changed, 351 insertions(+), 134 deletions(-) create mode 100644 Gruntfile.js diff --git a/.eslintrc b/.eslintrc index 6dfcd86..a7eca29 100644 --- a/.eslintrc +++ b/.eslintrc @@ -21,6 +21,7 @@ }], "comma-dangle": [2, "never"], "no-underscore-dangle": 0, - "no-empty-function": 1 + "no-empty-function": 1, + "no-param-reassign": 0 } } \ No newline at end of file diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 0000000..1b895d2 --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,38 @@ +'use strict'; + +module.exports = (grunt) => { + grunt.initConfig({ + eslint: { + target: ['**/*.js', '!node_modules/**'] + }, + mochaTest: { + test: { + options: { + reporter: 'nyan' + }, + src: ['test/**/*.js'] + } + }, + watch: { + config: { + files: './Gruntfile.js', + options: { + reload: true + } + }, + tests: { + files: ['test/**.js', '!node_modules/**', './moment-msdate.js'], + tasks: ['test'], + options: { + spawn: true + } + } + } + }); + + grunt.loadNpmTasks('grunt-mocha-test'); + grunt.loadNpmTasks('grunt-eslint'); + grunt.loadNpmTasks('grunt-contrib-watch'); + + grunt.registerTask('test', ['eslint', 'mochaTest']); +}; diff --git a/moment-msdate.js b/moment-msdate.js index 14995ed..352bdb9 100644 --- a/moment-msdate.js +++ b/moment-msdate.js @@ -1,15 +1,107 @@ 'use strict'; -(function() { +(function(root, factory) { + /*global define*/ + if (typeof define === 'function' && define.amd) { + define(['moment', 'moment-timezone'], factory); // AMD + } else if (typeof module === 'object' && module.exports) { + module.exports = factory(require('moment'), require('moment-timezone')); // Node + } else { + factory(root.moment); // Browser + } +}(this, (moment) => { + const DAY_MILLISECONDS = 86400000; + const MINUTE_MILLISECONDS = 60000; + const MS_DAY_OFFSET = 25569; + + const momentVersion = moment.version.split('.'); + const major = +momentVersion[0]; + const minor = +momentVersion[1]; + + // Moment.js version check + if (major < 2 || (major === 2 && minor < 6)) { + throw new Error(`moment-msdate requires Moment.js >= 2.6.0. You are using Moment.js ${moment.version}. See momentjs.com`); + } + + if (!moment.tz) { + throw new Error('moment-msdate requires moment-timezone.js. see momentjs.com/timezone'); + } + + moment.updateLocale('en', { invalidDate: undefined }); + + const oaDateToTicks = function(oaDate) { + return ((oaDate - MS_DAY_OFFSET) * DAY_MILLISECONDS) + (oaDate >= 0.0 ? 0.5 : -0.5); + }; + + /** + * @description takes an oaDate that is in utc and converts it to a utc moment + * + * @param {double} oaDate + * @returns moment + */ + moment.fromOADate = function(oaDate) { + return moment(oaDateToTicks(oaDate)).utc(); + }; + + /** + * @description takes an oaDate that is not in utc and converts it to a utc moment offset by a number of minutes + * + * @param {double} oaDate + * @param {string} offsetToUtcInMinutes + * @returns moment + */ + moment.fromOADateOffsetToUtcByMinutes = function(oaDate, offsetToUtcInMinutes) { + const offsetInTicks = offsetToUtcInMinutes * MINUTE_MILLISECONDS; + const ticks = oaDateToTicks(oaDate); + return moment(ticks + offsetInTicks).utc(); + }; + + /** + * @description takes an oaDate that is not in utc and converts it to a utc moment offset by the specified timezone + * + * @param {double} oaDate + * @param {string} timezone + * @returns moment + */ + moment.fromOADateOffsetToUtcByTimezone = function(oaDate, timezone) { + const ticks = oaDateToTicks(oaDate); + const offset = moment.tz(timezone).utcOffset() * MINUTE_MILLISECONDS; + return moment.tz(ticks - offset, timezone).utc(); + }; + + /** + * @description converts an ISO 8601 date time string to a UTC OLE automation date represented as a double + * + * @param {string} iso8601String + * @returns {double} + */ + moment.toOADateFromIso8601String = function(iso8601String) { + return iso8601String; + }; + + /** + * @description converts a moment to a UTC OLE automation date represented as a double + * + * @returns {double} + */ + moment.fn.toOADate = function() { + + }; + + return moment; +})); + + +// (function() { /** * Constants */ - const DAY_MILLISECONDS = 86400000; - const MINUTE_MILLISECONDS = 60000; - const MS_DAY_OFFSET = 25569; + // const DAY_MILLISECONDS = 86400000; + // const MINUTE_MILLISECONDS = 60000; + // const MS_DAY_OFFSET = 25569; - const moment = (typeof require !== 'undefined' && require !== null) && !require.amd ? require('moment-timezone') : this.moment; + // const moment = (typeof require !== 'undefined' && require !== null) && !require.amd ? require('moment-timezone') : this.moment; /** * @description To JavaScript date from OLE Automation date @@ -18,12 +110,17 @@ * @param offsetToUtcInMinutes An offset from the msDate to UTC. If not supplied the offset from the system timezone will be used. * @returns moment */ - moment.fromOADate = function(msDate, offsetToUtcInMinutes) { - let jO = new Date(((msDate - MS_DAY_OFFSET) * DAY_MILLISECONDS) + (msDate >= 0.0 ? 0.5 : -0.5)); - const tz = isNaN(parseInt(offsetToUtcInMinutes, 10)) ? jO.getTimezoneOffset() : offsetToUtcInMinutes; - jO = new Date((((msDate - MS_DAY_OFFSET) + (tz / (60 * 24))) * DAY_MILLISECONDS) + (msDate >= 0.0 ? 0.5 : -0.5)); - return moment(jO); - }; + // moment.fromOADate = function(msDate, offsetToUtcInMinutes) { + // let jO = new Date(((msDate - MS_DAY_OFFSET) * DAY_MILLISECONDS) + (msDate >= 0.0 ? 0.5 : -0.5)); + // const tz = isNaN(parseInt(offsetToUtcInMinutes, 10)) ? jO.getTimezoneOffset() : offsetToUtcInMinutes; + // jO = new Date((((msDate - MS_DAY_OFFSET) + (tz / (60 * 24))) * DAY_MILLISECONDS) + (msDate >= 0.0 ? 0.5 : -0.5)); + // return moment(jO); + // }; + + // fromOADate returns a UTC moment + // moment.fromOADate = function(oaDate) { + // return moment(((oaDate - MS_DAY_OFFSET) * DAY_MILLISECONDS) + (oaDate >= 0.0 ? 0.5 : -0.5)).utc(); + // }; /** * To OLE Automation date from JavaScript date @@ -31,41 +128,41 @@ * @param jsDate A JavaScript date object to convert to OA Date. Defaults to existing moment instance or new Date * @returns Floating-point number, e.g., 41502.558798240745 */ - moment.fn.toOADate = function(jsDateInput) { - const jsDate = jsDateInput || this._d || new Date(); - const timezoneOffset = jsDate.getTimezoneOffset() / (60 * 24); - const msDateObj = (jsDate.getTime() / DAY_MILLISECONDS) + (MS_DAY_OFFSET - timezoneOffset); - return msDateObj; - }; + // moment.fn.toOADate = function(jsDateInput) { + // const jsDate = jsDateInput || this._d || new Date(); + // const timezoneOffset = jsDate.getTimezoneOffset() / (60 * 24); + // const msDateObj = (jsDate.getTime() / DAY_MILLISECONDS) + (MS_DAY_OFFSET - timezoneOffset); + // return msDateObj; + // }; - moment.updateLocale('en', { - invalidDate: undefined - }); + // moment.updateLocale('en', { + // invalidDate: undefined + // }); /** * Converts an OLE Automation date to a moment (baking in a timezone if one is supplied) * Returns a UTC Moment object instance */ - moment.fromOADateWithZone = function(msDate, timeZone) { - const jsTicks = (msDate - MS_DAY_OFFSET) * DAY_MILLISECONDS; - const offset = moment.tz(timeZone).utcOffset() * MINUTE_MILLISECONDS; - if (timeZone) { - return moment.tz(jsTicks - offset, timeZone).utc(); - } - return moment.utc(jsTicks); - }; + // moment.fromOADateWithZone = function(msDate, timeZone) { + // const jsTicks = (msDate - MS_DAY_OFFSET) * DAY_MILLISECONDS; + // const offset = moment.tz(timeZone).utcOffset() * MINUTE_MILLISECONDS; + // if (timeZone) { + // return moment.tz(jsTicks - offset, timeZone).utc(); + // } + // return moment.utc(jsTicks); + // }; /** * Converts a moment (with timezone) to an OLE Automation date in UTC * Returns an OLE Automation date in the form of a double */ - moment.fn.toOADateWithZone = function() { - const nMsDate = (this.valueOf() / DAY_MILLISECONDS) + MS_DAY_OFFSET; - return nMsDate; - }; +// moment.fn.toOADateWithZone = function() { +// const nMsDate = (this.valueOf() / DAY_MILLISECONDS) + MS_DAY_OFFSET; +// return nMsDate; +// }; - if ((typeof module !== 'undefined' && module !== null ? module.exports : undefined) !== null) { - module.exports = moment; - } +// if ((typeof module !== 'undefined' && module !== null ? module.exports : undefined) !== null) { +// module.exports = moment; +// } -}).call(this); +// }).call(this); diff --git a/package.json b/package.json index 56bc7d9..f5b7cc2 100644 --- a/package.json +++ b/package.json @@ -51,6 +51,10 @@ "eslint-plugin-import": "^2.2.0", "eslint-plugin-jsx-a11y": "^3.0.2", "eslint-plugin-react": "^6.9.0", + "grunt": "^1.0.1", + "grunt-contrib-watch": "^1.0.0", + "grunt-eslint": "^19.0.0", + "grunt-mocha-test": "^0.13.2", "mocha": "^3.2.0" } -} \ No newline at end of file +} diff --git a/test/test.js b/test/test.js index 3729553..a3fa973 100644 --- a/test/test.js +++ b/test/test.js @@ -3,124 +3,201 @@ const assert = require('assert'); const moment = require('../moment-msdate'); -describe('moment-msdate: moment.fromOADate', () => { - it('should convert an OLE Automation date to a moment with a 0 offset to UTC', () => { - // 1/19/2017 8:02:26 PM - const date = moment.fromOADate(42754.835023148145, 0); // UTC - assert.equal('2017-01-19T20:02:26.000Z', date.toISOString()); - }); +describe('moment-msdate', () => { + const dateTime = '2015-10-21T16:29:00.000Z'; - it('should convert an OLE Automation date to a moment with a 300 minute offset to UTC', () => { - // 1/19/2017 8:02:26 PM - const date = moment.fromOADate(42754.835023148145, 300); // ET - assert.equal('2017-01-20T01:02:26.000Z', date.toISOString()); - }); + console.log('***************************************************'); + console.log(`*** great scott!! it's ${dateTime} ***`); + console.log('***************************************************'); - it('should convert an OLE Automation date to a moment with a 360 minute offset to UTC', () => { - // 1/19/2017 8:02:26 PM - const date = moment.fromOADate(42754.835023148145, 360); // CT - assert.equal('2017-01-20T02:02:26.000Z', date.toISOString()); - }); + describe('moment.fromOADate', () => { + it('should convert 42298.6868055556 to 2015-10-21T16:29:00.000Z', () => { + assert.equal(moment.fromOADate(42298.6868055556).toISOString(), dateTime); + }); - it('should convert an OLE Automation date to a moment with a 420 minute offset to UTC', () => { - // 1/19/2017 8:02:26 PM - const date = moment.fromOADate(42754.835023148145, 420); // MT - assert.equal('2017-01-20T03:02:26.000Z', date.toISOString()); + it('should have a timezone of utc', () => { + const myMoment = moment.fromOADate(42298.6868055556); + assert.ok(myMoment.isUtc()); + }); }); -}); -describe('moment-msdate', () => { - it('should parse an OLE Automation date int', () => { - const date = moment.fromOADate(41493); - assert.equal(date.toString().search('Wed Aug 07 2013 00:00:00'), 0); - }); + describe('moment.fromOADateOffsetToUtcByMinutes', () => { + it('should convert 42298.6868055556 to 2015-10-21T16:29:00.000Z', () => { + assert.equal(moment.fromOADateOffsetToUtcByMinutes(42298.6868055556, 0).toISOString(), dateTime); + }); - it('should parse an OLE Automation date double', () => { - const date = moment.fromOADate(41493.706892280097000); - assert.equal(date.toString().search('Wed Aug 07 2013 16:57:55'), 0); - }); + it('should convert 42298.6868055556 to 2015-10-21T20:29:00.000Z', () => { + assert.equal(moment.fromOADateOffsetToUtcByMinutes(42298.6868055556, 240).toISOString(), '2015-10-21T20:29:00.000Z'); + }); - it('should handle rounding quirks', () => { - const date = moment.fromOADate(42681.501388888886); - assert.equal(date.toString().search('Mon Nov 07 2016 12:02:00'), 0); - }); -}); + it('should convert 42298.6868055556 to 2015-10-21T21:29:00.000Z', () => { + assert.equal(moment.fromOADateOffsetToUtcByMinutes(42298.6868055556, 300).toISOString(), '2015-10-21T21:29:00.000Z'); + }); -describe('moment-msdate: moment.toOADate', () => { - it('return an OLE automation date from a jsDate input', () => { + it('should convert 42298.6868055556 to 2015-10-21T22:29:00.000Z', () => { + assert.equal(moment.fromOADateOffsetToUtcByMinutes(42298.6868055556, 360).toISOString(), '2015-10-21T22:29:00.000Z'); + }); - }); -}); + it('should convert 42298.6868055556 to 2015-10-21T23:29:00.000Z', () => { + assert.equal(moment.fromOADateOffsetToUtcByMinutes(42298.6868055556, 420).toISOString(), '2015-10-21T23:29:00.000Z'); + }); -describe('moment-msdate: moment.fn.toOADate', () => { - it('should convert an empty JavaScript date to an OLE Automation date of 0', () => { - const date = new Date(1899, 11, 30, 0, 0, 0); - const oaDate = moment(date).toOADate(); - assert.equal(oaDate, 0); + it('should have a timezone of utc', () => { + const myMoment = moment.fromOADateOffsetToUtcByMinutes(42298.6868055556, 240); + assert.ok(myMoment.isUtc()); + }); }); - it('should convert a JavaScript date to an OLE Automation date int', () => { - const date = new Date(2012, 9, 15); - const oaDate = moment(date).toOADate(); - assert.equal(oaDate, 41197); - }); -}); + describe('moment.fromOADateOffsetToUtcByTimezone', () => { + it('should convert 42298.6868055556 to 2015-10-21T20:29:00.000Z', () => { + assert.equal(moment.fromOADateOffsetToUtcByTimezone(42298.6868055556, 'America/New_York').toISOString(), '2015-10-21T20:29:00.000Z'); + }); -describe('moment-msdate: moment.fromOADateWithZone', () => { - it('should convert an OLE automation date with an ET timezone to a utc moment', () => { - // 1/19/2017 8:02:26 PM - const date = moment.fromOADateWithZone('42754.835023148145', 'America/New_York'); - assert.equal('2017-01-20T01:02:25.999Z', date.toISOString()); - }); + it('should convert 42298.6868055556 to 2015-10-21T21:29:00.000Z', () => { + assert.equal(moment.fromOADateOffsetToUtcByTimezone(42298.6868055556, 'America/Chicago').toISOString(), '2015-10-21T21:29:00.000Z'); + }); - it('should convert an OLE automation date with a CT timezone to a utc moment', () => { - // 1/19/2017 8:02:26 PM - const date = moment.fromOADateWithZone('42754.835023148145', 'America/Chicago'); - assert.equal('2017-01-20T02:02:25.999Z', date.toISOString()); - }); + it('should convert 42298.6868055556 to 2015-10-21T22:29:00.000Z', () => { + assert.equal(moment.fromOADateOffsetToUtcByTimezone(42298.6868055556, 'America/Denver').toISOString(), '2015-10-21T22:29:00.000Z'); + }); - it('should convert an OLE automation date with a MT timezone to a utc moment', () => { - // 1/19/2017 8:02:26 PM - const date = moment.fromOADateWithZone('42754.835023148145', 'America/Denver'); - assert.equal('2017-01-20T03:02:25.999Z', date.toISOString()); - }); -}); + it('should convert 42298.6868055556 to 2015-10-21T23:29:00.000Z', () => { + assert.equal(moment.fromOADateOffsetToUtcByTimezone(42298.6868055556, 'America/Los_Angeles').toISOString(), '2015-10-21T23:29:00.000Z'); + }); -describe('moment-msdate: moment.fn.toOADateWithZone', () => { - it('should convert a moment with a UTC offset to a UTC OLE automation date', () => { - const momentDate = moment.parseZone('2017-01-19T20:02:26.000Z'); - const oaDate = momentDate.toOADateWithZone(); - // 1/19/2017 8:02:26 PM - assert.equal(42754.835023148145, oaDate); + it('should have a timezone of utc', () => { + const myMoment = moment.fromOADateOffsetToUtcByTimezone(42298.6868055556, 'America/New_York'); + assert.ok(myMoment.isUtc()); + }); }); - it('should convert a moment with a ET offset to a UTC OLE automation date', () => { - const momentDate = moment.parseZone('2017-01-19T20:02:26-05:00'); - const oaDate = momentDate.toOADateWithZone(); - assert.equal(42755.04335648148, oaDate); - // 1/20/2017 1:02:26 AM - }); + describe('moment.toOADateFromIso8601String', () => { - it('should convert a moment with a CT offset to a UTC OLE automation date', () => { - const momentDate = moment.parseZone('2017-01-19T20:02:26-06:00'); - const oaDate = momentDate.toOADateWithZone(); - assert.equal(42755.085023148145, oaDate); - // 1/20/2017 2:02:26 AM }); - it('should convert a moment with a MT offset to a UTC OLE automation date', () => { - const momentDate = moment.parseZone('2017-01-19T20:02:26-07:00'); - const oaDate = momentDate.toOADateWithZone(); - assert.equal(42755.12668981482, oaDate); - // 1/20/2017 3:02:26 AM - }); + describe('moment.fn.toOADate', () => { - it('should convert a moment to a UTC OLE automation date if timezone (tz) is set', () => { - const momentDate = moment('2017-01-19T20:02:26.000Z'); - momentDate.tz('America/New_York'); - const oaDate = momentDate.toOADateWithZone(); - assert.equal(42754.835023148145, oaDate); - // 1/19/2017 8:02:26 PM }); }); +// describe('moment-msdate: moment.fromOADate', () => { +// it('should convert an OLE Automation date to a moment with a 0 offset to UTC', () => { +// // 1/19/2017 8:02:26 PM +// const date = moment.fromOADate(42754.835023148145, 0); // UTC +// assert.equal('2017-01-19T20:02:26.000Z', date.toISOString()); +// }); + +// it('should convert an OLE Automation date to a moment with a 300 minute offset to UTC', () => { +// // 1/19/2017 8:02:26 PM +// const date = moment.fromOADate(42754.835023148145, 300); // ET +// assert.equal('2017-01-20T01:02:26.000Z', date.toISOString()); +// }); + +// it('should convert an OLE Automation date to a moment with a 360 minute offset to UTC', () => { +// // 1/19/2017 8:02:26 PM +// const date = moment.fromOADate(42754.835023148145, 360); // CT +// assert.equal('2017-01-20T02:02:26.000Z', date.toISOString()); +// }); + +// it('should convert an OLE Automation date to a moment with a 420 minute offset to UTC', () => { +// // 1/19/2017 8:02:26 PM +// const date = moment.fromOADate(42754.835023148145, 420); // MT +// assert.equal('2017-01-20T03:02:26.000Z', date.toISOString()); +// }); +// }); + +// describe('moment-msdate', () => { +// it('should parse an OLE Automation date int', () => { +// const date = moment.fromOADate(41493); +// assert.equal(date.toString().search('Wed Aug 07 2013 00:00:00'), 0); +// }); + +// it('should parse an OLE Automation date double', () => { +// const date = moment.fromOADate(41493.706892280097000); +// assert.equal(date.toString().search('Wed Aug 07 2013 16:57:55'), 0); +// }); + +// it('should handle rounding quirks', () => { +// const date = moment.fromOADate(42681.501388888886); +// assert.equal(date.toString().search('Mon Nov 07 2016 12:02:00'), 0); +// }); +// }); + +// describe('moment-msdate: moment.toOADate', () => { +// it('return an OLE automation date from a jsDate input', () => { + +// }); +// }); + +// describe('moment-msdate: moment.fn.toOADate', () => { +// it('should convert an empty JavaScript date to an OLE Automation date of 0', () => { +// const date = new Date(1899, 11, 30, 0, 0, 0); +// const oaDate = moment(date).toOADate(); +// assert.equal(oaDate, 0); +// }); + +// it('should convert a JavaScript date to an OLE Automation date int', () => { +// const date = new Date(2012, 9, 15); +// const oaDate = moment(date).toOADate(); +// assert.equal(oaDate, 41197); +// }); +// }); + +// describe('moment-msdate: moment.fromOADateWithZone', () => { +// it('should convert an OLE automation date with an ET timezone to a utc moment', () => { +// // 1/19/2017 8:02:26 PM +// const date = moment.fromOADateWithZone('42754.835023148145', 'America/New_York'); +// assert.equal('2017-01-20T01:02:25.999Z', date.toISOString()); +// }); + +// it('should convert an OLE automation date with a CT timezone to a utc moment', () => { +// // 1/19/2017 8:02:26 PM +// const date = moment.fromOADateWithZone('42754.835023148145', 'America/Chicago'); +// assert.equal('2017-01-20T02:02:25.999Z', date.toISOString()); +// }); + +// it('should convert an OLE automation date with a MT timezone to a utc moment', () => { +// // 1/19/2017 8:02:26 PM +// const date = moment.fromOADateWithZone('42754.835023148145', 'America/Denver'); +// assert.equal('2017-01-20T03:02:25.999Z', date.toISOString()); +// }); +// }); + +// describe('moment-msdate: moment.fn.toOADateWithZone', () => { +// it('should convert a moment with a UTC offset to a UTC OLE automation date', () => { +// const momentDate = moment.parseZone('2017-01-19T20:02:26.000Z'); +// const oaDate = momentDate.toOADateWithZone(); +// // 1/19/2017 8:02:26 PM +// assert.equal(42754.835023148145, oaDate); +// }); + +// it('should convert a moment with a ET offset to a UTC OLE automation date', () => { +// const momentDate = moment.parseZone('2017-01-19T20:02:26-05:00'); +// const oaDate = momentDate.toOADateWithZone(); +// assert.equal(42755.04335648148, oaDate); +// // 1/20/2017 1:02:26 AM +// }); + +// it('should convert a moment with a CT offset to a UTC OLE automation date', () => { +// const momentDate = moment.parseZone('2017-01-19T20:02:26-06:00'); +// const oaDate = momentDate.toOADateWithZone(); +// assert.equal(42755.085023148145, oaDate); +// // 1/20/2017 2:02:26 AM +// }); + +// it('should convert a moment with a MT offset to a UTC OLE automation date', () => { +// const momentDate = moment.parseZone('2017-01-19T20:02:26-07:00'); +// const oaDate = momentDate.toOADateWithZone(); +// assert.equal(42755.12668981482, oaDate); +// // 1/20/2017 3:02:26 AM +// }); + +// it('should convert a moment to a UTC OLE automation date if timezone (tz) is set', () => { +// const momentDate = moment('2017-01-19T20:02:26.000Z'); +// momentDate.tz('America/New_York'); +// const oaDate = momentDate.toOADateWithZone(); +// assert.equal(42754.835023148145, oaDate); +// // 1/19/2017 8:02:26 PM +// }); +// }); + From bf7a8cde4a229ee58ffc41c87adb41860c721a1c Mon Sep 17 00:00:00 2001 From: Michael Lechner Date: Mon, 13 Mar 2017 19:36:21 -0600 Subject: [PATCH 02/23] cleaning up global define and tests --- moment-msdate.js | 9 +++++---- test/.eslintrc | 3 ++- test/test.js | 12 +++++------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/moment-msdate.js b/moment-msdate.js index 352bdb9..a300b52 100644 --- a/moment-msdate.js +++ b/moment-msdate.js @@ -7,9 +7,10 @@ } else if (typeof module === 'object' && module.exports) { module.exports = factory(require('moment'), require('moment-timezone')); // Node } else { - factory(root.moment); // Browser + // correct way to load moment-timezone? + factory(root.moment, root.moment.tz); // Browser } -}(this, (moment) => { +}(this, (moment, momentTimezone) => { const DAY_MILLISECONDS = 86400000; const MINUTE_MILLISECONDS = 60000; const MS_DAY_OFFSET = 25569; @@ -23,11 +24,11 @@ throw new Error(`moment-msdate requires Moment.js >= 2.6.0. You are using Moment.js ${moment.version}. See momentjs.com`); } - if (!moment.tz) { + if (!momentTimezone || !moment.tz) { throw new Error('moment-msdate requires moment-timezone.js. see momentjs.com/timezone'); } - moment.updateLocale('en', { invalidDate: undefined }); + // moment.updateLocale('en', { invalidDate: undefined }); // needs to move to the users config for moment const oaDateToTicks = function(oaDate) { return ((oaDate - MS_DAY_OFFSET) * DAY_MILLISECONDS) + (oaDate >= 0.0 ? 0.5 : -0.5); diff --git a/test/.eslintrc b/test/.eslintrc index b63f20f..54e01b6 100644 --- a/test/.eslintrc +++ b/test/.eslintrc @@ -4,6 +4,7 @@ }, "rules":{ // assert.throws doesnt respond to lambda syntax - "prefer-arrow-callback": 0 + "prefer-arrow-callback": 0, + "no-console": 0 } } \ No newline at end of file diff --git a/test/test.js b/test/test.js index a3fa973..f904a6e 100644 --- a/test/test.js +++ b/test/test.js @@ -4,15 +4,13 @@ const assert = require('assert'); const moment = require('../moment-msdate'); describe('moment-msdate', () => { - const dateTime = '2015-10-21T16:29:00.000Z'; - - console.log('***************************************************'); - console.log(`*** great scott!! it's ${dateTime} ***`); - console.log('***************************************************'); + console.log('********************************************************'); + console.log('*** great scott!! it\'s 2015-10-21T16:29:00.000-07:00 ***'); + console.log('********************************************************'); describe('moment.fromOADate', () => { it('should convert 42298.6868055556 to 2015-10-21T16:29:00.000Z', () => { - assert.equal(moment.fromOADate(42298.6868055556).toISOString(), dateTime); + assert.equal(moment.fromOADate(42298.6868055556).toISOString(), '2015-10-21T16:29:00.000Z'); }); it('should have a timezone of utc', () => { @@ -23,7 +21,7 @@ describe('moment-msdate', () => { describe('moment.fromOADateOffsetToUtcByMinutes', () => { it('should convert 42298.6868055556 to 2015-10-21T16:29:00.000Z', () => { - assert.equal(moment.fromOADateOffsetToUtcByMinutes(42298.6868055556, 0).toISOString(), dateTime); + assert.equal(moment.fromOADateOffsetToUtcByMinutes(42298.6868055556, 0).toISOString(), '2015-10-21T16:29:00.000Z'); }); it('should convert 42298.6868055556 to 2015-10-21T20:29:00.000Z', () => { From d06ac08a8afb32f7816cd5cf08f2c0ec3120321c Mon Sep 17 00:00:00 2001 From: michael lechner Date: Tue, 14 Mar 2017 16:54:03 -0600 Subject: [PATCH 03/23] toOADate and tests --- moment-msdate.js | 10 ++++++++-- test/test.js | 23 ++++++++++++++++++++++- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/moment-msdate.js b/moment-msdate.js index a300b52..6b6d98b 100644 --- a/moment-msdate.js +++ b/moment-msdate.js @@ -34,6 +34,9 @@ return ((oaDate - MS_DAY_OFFSET) * DAY_MILLISECONDS) + (oaDate >= 0.0 ? 0.5 : -0.5); }; + const ticksToOADate = function(milliseconds) { + return (milliseconds / DAY_MILLISECONDS) + MS_DAY_OFFSET; + }; /** * @description takes an oaDate that is in utc and converts it to a utc moment * @@ -77,7 +80,9 @@ * @returns {double} */ moment.toOADateFromIso8601String = function(iso8601String) { - return iso8601String; + const myMoment = moment(iso8601String).utc(); + const milliseconds = myMoment.valueOf(); + return ticksToOADate(milliseconds); }; /** @@ -86,7 +91,8 @@ * @returns {double} */ moment.fn.toOADate = function() { - + const milliseconds = this.valueOf(); + return ticksToOADate(milliseconds); }; return moment; diff --git a/test/test.js b/test/test.js index f904a6e..5ed24b2 100644 --- a/test/test.js +++ b/test/test.js @@ -70,11 +70,32 @@ describe('moment-msdate', () => { }); describe('moment.toOADateFromIso8601String', () => { + it('should convert 2015-10-21T16:29:00.000Z to 42298.6868055556', () => { + assert.equal(moment.toOADateFromIso8601String('2015-10-21T16:29:00.000Z'), 42298.68680555555); + }); + + it('should convert 2015-10-21T16:29:00.000-04:00 to 42298.6868055556', () => { + assert.equal(moment.toOADateFromIso8601String('2015-10-21T16:29:00.000-04:00'), 42298.853472222225); + }); + + it('should convert 2015-10-21T16:29:00.000-04:00 to 42298.6868055556', () => { + assert.equal(moment.toOADateFromIso8601String('2015-10-21T16:29:00.000-05:00'), 42298.89513888889); + }); + it('should convert 2015-10-21T16:29:00.000-04:00 to 42298.6868055556', () => { + assert.equal(moment.toOADateFromIso8601String('2015-10-21T16:29:00.000-06:00'), 42298.93680555555); + }); + + it('should convert 2015-10-21T16:29:00.000-04:00 to 42298.6868055556', () => { + assert.equal(moment.toOADateFromIso8601String('2015-10-21T16:29:00.000-07:00'), 42298.978472222225); + }); }); describe('moment.fn.toOADate', () => { - + it('should convert 2015-10-21T16:29:00.000Z to 42298.6868055556', () => { + const myMoment = moment('2015-10-21T16:29:00.000Z').utc(); + assert.equal(myMoment.toOADate(), 42298.68680555555); + }); }); }); From 562953bd75d83995f5b88c2f5d855d8eabbdb51e Mon Sep 17 00:00:00 2001 From: Michael Lechner Date: Wed, 15 Mar 2017 09:03:30 -0600 Subject: [PATCH 04/23] toOADate tests --- moment-msdate.js | 4 +--- test/test.js | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/moment-msdate.js b/moment-msdate.js index 6b6d98b..a944d2c 100644 --- a/moment-msdate.js +++ b/moment-msdate.js @@ -19,7 +19,6 @@ const major = +momentVersion[0]; const minor = +momentVersion[1]; - // Moment.js version check if (major < 2 || (major === 2 && minor < 6)) { throw new Error(`moment-msdate requires Moment.js >= 2.6.0. You are using Moment.js ${moment.version}. See momentjs.com`); } @@ -28,8 +27,6 @@ throw new Error('moment-msdate requires moment-timezone.js. see momentjs.com/timezone'); } - // moment.updateLocale('en', { invalidDate: undefined }); // needs to move to the users config for moment - const oaDateToTicks = function(oaDate) { return ((oaDate - MS_DAY_OFFSET) * DAY_MILLISECONDS) + (oaDate >= 0.0 ? 0.5 : -0.5); }; @@ -37,6 +34,7 @@ const ticksToOADate = function(milliseconds) { return (milliseconds / DAY_MILLISECONDS) + MS_DAY_OFFSET; }; + /** * @description takes an oaDate that is in utc and converts it to a utc moment * diff --git a/test/test.js b/test/test.js index 5ed24b2..e6c5f67 100644 --- a/test/test.js +++ b/test/test.js @@ -96,6 +96,26 @@ describe('moment-msdate', () => { const myMoment = moment('2015-10-21T16:29:00.000Z').utc(); assert.equal(myMoment.toOADate(), 42298.68680555555); }); + + it('should convert 2015-10-21T16:29:00.000-04:00 to 42298.6868055556', () => { + const myMoment = moment('2015-10-21T16:29:00.000-04:00').utc(); + assert.equal(myMoment.toOADate(), 42298.853472222225); + }); + + it('should convert 2015-10-21T16:29:00.000-04:00 to 42298.6868055556', () => { + const myMoment = moment('2015-10-21T16:29:00.000-05:00').utc(); + assert.equal(myMoment.toOADate(), 42298.89513888889); + }); + + it('should convert 2015-10-21T16:29:00.000-04:00 to 42298.6868055556', () => { + const myMoment = moment('2015-10-21T16:29:00.000-06:00'); + assert.equal(myMoment.toOADate(), 42298.93680555555); + }); + + it('should convert 2015-10-21T16:29:00.000-04:00 to 42298.6868055556', () => { + const myMoment = moment('2015-10-21T16:29:00.000-07:00'); + assert.equal(myMoment.toOADate(), 42298.978472222225); + }); }); }); From 9c5ec3f7cdd884b6c9c0b72fa4b7bf80a16a99e1 Mon Sep 17 00:00:00 2001 From: Michael Lechner Date: Wed, 15 Mar 2017 09:05:43 -0600 Subject: [PATCH 05/23] updating version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f5b7cc2..308eee5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "moment-msdate", - "version": "0.2.0", + "version": "1.0.0", "description": "Adds OLE Automation parsing capabilities to Moment.js", "main": "moment-msdate.js", "scripts": { From d2ec73b63961181b9270906835ff0ea79f79f8a5 Mon Sep 17 00:00:00 2001 From: Michael Lechner Date: Wed, 15 Mar 2017 11:33:00 -0600 Subject: [PATCH 06/23] updating readme and additional tests --- README.md | 62 ++++++++++---------- moment-msdate.js | 76 ------------------------ test/test.js | 147 ++++++++--------------------------------------- 3 files changed, 58 insertions(+), 227 deletions(-) diff --git a/README.md b/README.md index a58a849..877fd47 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # moment-msdate [![Build Status](https://travis-ci.org/markitondemand/moment-msdate.svg?branch=master)](https://travis-ci.org/markitondemand/moment-msdate) [![npm version](https://badge.fury.io/js/moment-msdate.svg)](https://badge.fury.io/js/moment-msdate) -A [Moment.js](http://momentjs.com/) plugin for parsing OLE Automation dates. +A [Moment.js](http://momentjs.com/) and [Moment-timezone.js](http://momentjs.com/timezone) plugin for parsing OLE Automation dates. Visit [http://markitondemand.github.io/moment-msdate/](http://markitondemand.github.io/moment-msdate/) for more information and examples. @@ -12,55 +12,59 @@ Read more [about OLE Automation on MSDN](http://msdn.microsoft.com/en-us/library ## Usage -### toOADate() - -Convert a `moment` to an OA date: - -`moment().toOADate();` - -This API returns a floating-point number (the OA date), so once the conversion has been made, you no longer have a `moment` object. +### fromOADate(oaDate) -### fromOADate() +Convert an OA date to a `moment`: -Convert an OA date to a `moment` (or to a JavaScript date): +`moment.fromOADate(42298.6868055556)` returns `2015-10-21T16:29:00.000Z` -`moment.fromOADate(41493)` returns `Wed Aug 07 2013 00:00:00 GMT-0600 (MDT)` +### fromOADateOffsetToUtcByMinutes(oaDate, offsetToUtcInMinutes) -For exact date _and_ time (time is the value right of the decimal): +Convert an OA date with a known offset to UTC to a `moment` in UTC time -`moment.fromOADate(41493.706892280097000)` returns `Wed Aug 07 2013 16:57:55 GMT-0600 (MDT)` +`moment.fromOADate(42298.6868055556, 240)` returns `2015-10-21T20:29:00.000Z` -By default moment.fromOADate() uses the server time as the offset to UTC a second argument can be provided that indicates the offset of the OA date to UTC in minutes. +### fromOADateOffsetToUtcByTimezone(oaDate, timezone) -`moment.fromOADate(42754.835023148145, 360)` returns `Fri Jan 20 2017 02:02:25 GMT+0000 (UTC)` +`moment.fromOADate(42298.6868055556, 'America/New_York')` returns `2015-10-21T20:29:00.000Z` For Moment formatting: ``` -//convert OA date into Moment (JavaScript date) -var momentDate = moment.fromOADate(41493.706892280097000); +// convert OA date into Moment (OA Date is assumed to be in UTC) +var momentDate = moment.fromOADate(42298.6868055556); -//use Moment's awesomeness -var formattedDate = momentDate.format('MMM Do YY); +// if OA date is not in UTC and the offset to UTC is known it can be specified during the moment creation in minutes +var momentDate = moment.fromOADateOffsetToUtcByMinutes(42298.6868055556, 240) +momentDate.toISOString() returns '2015-10-21T20:29:00.000Z' (UTC) +momentDate.format('LLLL') returns 'Wednesday, October 21, 2015 8:29 PM' (UTC) + +// if OA date is not in UTC and the offset to UTC is known it can be specified during the moment creation as a timezone +var momentDate = moment.fromOADateOffsetToUtcByMinutes(42298.6868055556, 'America/New_York') +momentDate.toISOString() returns '2015-10-21T20:29:00.000Z' (UTC) +momentDate.format('LLLL') returns 'Wednesday, October 21, 2015 8:29 PM' (UTC) + +// once the date is in UTC it can than easily be converted to any other timezone using moment-timezone.js +var momentDate = moment.fromOADateOffsetToUtcByMinutes(42298.6868055556, 240) +momentDate.tz('America/New_York') +momentDate.toISOString() returns '2015-10-21T20:29:00.000Z' (UTC) +momentDate.format('LLLL') returns 'Wednesday, October 21, 2015 4:29 PM' (ET) -//formattedDate === "Aug 7th 13" ``` -This could easily be chained together as: +**Note**: OLE Automation dates are unspecified and they’re based on the local timezone by default. The moment library normalizes all time to UTC and as a result this library will return all values based on UTC time. -`moment.fromOADate(41493.706892280097000).format('MMM Do YY); //Aug 7th 13` +### toOADate() -**Note**: OLE Automation dates are unspecified, meaning they’re based on the local timezone by default. +Convert a `moment` to a floating point OA date in UTC: -### fromOADateWithZone() -Converts an OLE Automation date to a moment (baking in a timezone if one is supplied) and returns a UTC Moment object instance. +`moment().toOADate();` -`moment.fromOADateWithZone('42754.835023148145', 'America/Denver');` returns `Fri Jan 20 2017 03:02:25 GMT+0000 (UTC)` +### toOADateFromIso8601String(iso8601String) -### toOADateWithZone() -Converts a moment (with timezone) to an OLE Automation date in UTC. +Convert an ISO 8601 String to a floating point OA date in UTC -`moment('2017-01-19T20:02:26.000Z').toOADateWithZone()` returns `42754.835023148145` +`moment.toOADateFromIso8601String(iso8601String)` ## License diff --git a/moment-msdate.js b/moment-msdate.js index a944d2c..d4ccfa5 100644 --- a/moment-msdate.js +++ b/moment-msdate.js @@ -95,79 +95,3 @@ return moment; })); - - -// (function() { - - /** - * Constants - */ - // const DAY_MILLISECONDS = 86400000; - // const MINUTE_MILLISECONDS = 60000; - // const MS_DAY_OFFSET = 25569; - - // const moment = (typeof require !== 'undefined' && require !== null) && !require.amd ? require('moment-timezone') : this.moment; - - /** - * @description To JavaScript date from OLE Automation date - * - * @param msDate An OLE Automation date. Required. - * @param offsetToUtcInMinutes An offset from the msDate to UTC. If not supplied the offset from the system timezone will be used. - * @returns moment - */ - // moment.fromOADate = function(msDate, offsetToUtcInMinutes) { - // let jO = new Date(((msDate - MS_DAY_OFFSET) * DAY_MILLISECONDS) + (msDate >= 0.0 ? 0.5 : -0.5)); - // const tz = isNaN(parseInt(offsetToUtcInMinutes, 10)) ? jO.getTimezoneOffset() : offsetToUtcInMinutes; - // jO = new Date((((msDate - MS_DAY_OFFSET) + (tz / (60 * 24))) * DAY_MILLISECONDS) + (msDate >= 0.0 ? 0.5 : -0.5)); - // return moment(jO); - // }; - - // fromOADate returns a UTC moment - // moment.fromOADate = function(oaDate) { - // return moment(((oaDate - MS_DAY_OFFSET) * DAY_MILLISECONDS) + (oaDate >= 0.0 ? 0.5 : -0.5)).utc(); - // }; - - /** - * To OLE Automation date from JavaScript date - * - * @param jsDate A JavaScript date object to convert to OA Date. Defaults to existing moment instance or new Date - * @returns Floating-point number, e.g., 41502.558798240745 - */ - // moment.fn.toOADate = function(jsDateInput) { - // const jsDate = jsDateInput || this._d || new Date(); - // const timezoneOffset = jsDate.getTimezoneOffset() / (60 * 24); - // const msDateObj = (jsDate.getTime() / DAY_MILLISECONDS) + (MS_DAY_OFFSET - timezoneOffset); - // return msDateObj; - // }; - - // moment.updateLocale('en', { - // invalidDate: undefined - // }); - - /** - * Converts an OLE Automation date to a moment (baking in a timezone if one is supplied) - * Returns a UTC Moment object instance - */ - // moment.fromOADateWithZone = function(msDate, timeZone) { - // const jsTicks = (msDate - MS_DAY_OFFSET) * DAY_MILLISECONDS; - // const offset = moment.tz(timeZone).utcOffset() * MINUTE_MILLISECONDS; - // if (timeZone) { - // return moment.tz(jsTicks - offset, timeZone).utc(); - // } - // return moment.utc(jsTicks); - // }; - - /** - * Converts a moment (with timezone) to an OLE Automation date in UTC - * Returns an OLE Automation date in the form of a double - */ -// moment.fn.toOADateWithZone = function() { -// const nMsDate = (this.valueOf() / DAY_MILLISECONDS) + MS_DAY_OFFSET; -// return nMsDate; -// }; - -// if ((typeof module !== 'undefined' && module !== null ? module.exports : undefined) !== null) { -// module.exports = moment; -// } - -// }).call(this); diff --git a/test/test.js b/test/test.js index e6c5f67..eca4d6a 100644 --- a/test/test.js +++ b/test/test.js @@ -13,6 +13,12 @@ describe('moment-msdate', () => { assert.equal(moment.fromOADate(42298.6868055556).toISOString(), '2015-10-21T16:29:00.000Z'); }); + it('should convert 42298.978472222225 to America/Los_Angeles timezone', () => { + const myMoment = moment.fromOADate(42298.978472222225); + myMoment.tz('America/Los_Angeles'); + assert.equal(myMoment.format('LLLL'), 'Wednesday, October 21, 2015 4:29 PM'); + }); + it('should have a timezone of utc', () => { const myMoment = moment.fromOADate(42298.6868055556); assert.ok(myMoment.isUtc()); @@ -26,6 +32,7 @@ describe('moment-msdate', () => { it('should convert 42298.6868055556 to 2015-10-21T20:29:00.000Z', () => { assert.equal(moment.fromOADateOffsetToUtcByMinutes(42298.6868055556, 240).toISOString(), '2015-10-21T20:29:00.000Z'); + assert.equal(moment.fromOADateOffsetToUtcByMinutes(42298.6868055556, 240).format('LLLL'), 'Wednesday, October 21, 2015 8:29 PM'); }); it('should convert 42298.6868055556 to 2015-10-21T21:29:00.000Z', () => { @@ -40,10 +47,21 @@ describe('moment-msdate', () => { assert.equal(moment.fromOADateOffsetToUtcByMinutes(42298.6868055556, 420).toISOString(), '2015-10-21T23:29:00.000Z'); }); + it('should convert 42298.6868055556 to 2015-10-21T23:29:00.000Z', () => { + assert.equal(moment.fromOADateOffsetToUtcByMinutes(42298.6868055556, 420).toISOString(), '2015-10-21T23:29:00.000Z'); + }); + it('should have a timezone of utc', () => { const myMoment = moment.fromOADateOffsetToUtcByMinutes(42298.6868055556, 240); assert.ok(myMoment.isUtc()); }); + + it('should not interfere with moment-timezone', () => { + const myMoment = moment.fromOADateOffsetToUtcByMinutes(42298.6868055556, 240); + myMoment.tz('America/New_York'); + assert.equal(myMoment.toISOString(), '2015-10-21T20:29:00.000Z'); + assert.equal(myMoment.format('LLLL'), 'Wednesday, October 21, 2015 4:29 PM'); + }); }); describe('moment.fromOADateOffsetToUtcByTimezone', () => { @@ -67,6 +85,13 @@ describe('moment-msdate', () => { const myMoment = moment.fromOADateOffsetToUtcByTimezone(42298.6868055556, 'America/New_York'); assert.ok(myMoment.isUtc()); }); + + it('should not interfere with moment-timezone', () => { + const myMoment = moment.fromOADateOffsetToUtcByTimezone(42298.6868055556, 'America/New_York'); + myMoment.tz('America/New_York'); + assert.equal(myMoment.toISOString(), '2015-10-21T20:29:00.000Z'); + assert.equal(myMoment.format('LLLL'), 'Wednesday, October 21, 2015 4:29 PM'); + }); }); describe('moment.toOADateFromIso8601String', () => { @@ -118,125 +143,3 @@ describe('moment-msdate', () => { }); }); }); - -// describe('moment-msdate: moment.fromOADate', () => { -// it('should convert an OLE Automation date to a moment with a 0 offset to UTC', () => { -// // 1/19/2017 8:02:26 PM -// const date = moment.fromOADate(42754.835023148145, 0); // UTC -// assert.equal('2017-01-19T20:02:26.000Z', date.toISOString()); -// }); - -// it('should convert an OLE Automation date to a moment with a 300 minute offset to UTC', () => { -// // 1/19/2017 8:02:26 PM -// const date = moment.fromOADate(42754.835023148145, 300); // ET -// assert.equal('2017-01-20T01:02:26.000Z', date.toISOString()); -// }); - -// it('should convert an OLE Automation date to a moment with a 360 minute offset to UTC', () => { -// // 1/19/2017 8:02:26 PM -// const date = moment.fromOADate(42754.835023148145, 360); // CT -// assert.equal('2017-01-20T02:02:26.000Z', date.toISOString()); -// }); - -// it('should convert an OLE Automation date to a moment with a 420 minute offset to UTC', () => { -// // 1/19/2017 8:02:26 PM -// const date = moment.fromOADate(42754.835023148145, 420); // MT -// assert.equal('2017-01-20T03:02:26.000Z', date.toISOString()); -// }); -// }); - -// describe('moment-msdate', () => { -// it('should parse an OLE Automation date int', () => { -// const date = moment.fromOADate(41493); -// assert.equal(date.toString().search('Wed Aug 07 2013 00:00:00'), 0); -// }); - -// it('should parse an OLE Automation date double', () => { -// const date = moment.fromOADate(41493.706892280097000); -// assert.equal(date.toString().search('Wed Aug 07 2013 16:57:55'), 0); -// }); - -// it('should handle rounding quirks', () => { -// const date = moment.fromOADate(42681.501388888886); -// assert.equal(date.toString().search('Mon Nov 07 2016 12:02:00'), 0); -// }); -// }); - -// describe('moment-msdate: moment.toOADate', () => { -// it('return an OLE automation date from a jsDate input', () => { - -// }); -// }); - -// describe('moment-msdate: moment.fn.toOADate', () => { -// it('should convert an empty JavaScript date to an OLE Automation date of 0', () => { -// const date = new Date(1899, 11, 30, 0, 0, 0); -// const oaDate = moment(date).toOADate(); -// assert.equal(oaDate, 0); -// }); - -// it('should convert a JavaScript date to an OLE Automation date int', () => { -// const date = new Date(2012, 9, 15); -// const oaDate = moment(date).toOADate(); -// assert.equal(oaDate, 41197); -// }); -// }); - -// describe('moment-msdate: moment.fromOADateWithZone', () => { -// it('should convert an OLE automation date with an ET timezone to a utc moment', () => { -// // 1/19/2017 8:02:26 PM -// const date = moment.fromOADateWithZone('42754.835023148145', 'America/New_York'); -// assert.equal('2017-01-20T01:02:25.999Z', date.toISOString()); -// }); - -// it('should convert an OLE automation date with a CT timezone to a utc moment', () => { -// // 1/19/2017 8:02:26 PM -// const date = moment.fromOADateWithZone('42754.835023148145', 'America/Chicago'); -// assert.equal('2017-01-20T02:02:25.999Z', date.toISOString()); -// }); - -// it('should convert an OLE automation date with a MT timezone to a utc moment', () => { -// // 1/19/2017 8:02:26 PM -// const date = moment.fromOADateWithZone('42754.835023148145', 'America/Denver'); -// assert.equal('2017-01-20T03:02:25.999Z', date.toISOString()); -// }); -// }); - -// describe('moment-msdate: moment.fn.toOADateWithZone', () => { -// it('should convert a moment with a UTC offset to a UTC OLE automation date', () => { -// const momentDate = moment.parseZone('2017-01-19T20:02:26.000Z'); -// const oaDate = momentDate.toOADateWithZone(); -// // 1/19/2017 8:02:26 PM -// assert.equal(42754.835023148145, oaDate); -// }); - -// it('should convert a moment with a ET offset to a UTC OLE automation date', () => { -// const momentDate = moment.parseZone('2017-01-19T20:02:26-05:00'); -// const oaDate = momentDate.toOADateWithZone(); -// assert.equal(42755.04335648148, oaDate); -// // 1/20/2017 1:02:26 AM -// }); - -// it('should convert a moment with a CT offset to a UTC OLE automation date', () => { -// const momentDate = moment.parseZone('2017-01-19T20:02:26-06:00'); -// const oaDate = momentDate.toOADateWithZone(); -// assert.equal(42755.085023148145, oaDate); -// // 1/20/2017 2:02:26 AM -// }); - -// it('should convert a moment with a MT offset to a UTC OLE automation date', () => { -// const momentDate = moment.parseZone('2017-01-19T20:02:26-07:00'); -// const oaDate = momentDate.toOADateWithZone(); -// assert.equal(42755.12668981482, oaDate); -// // 1/20/2017 3:02:26 AM -// }); - -// it('should convert a moment to a UTC OLE automation date if timezone (tz) is set', () => { -// const momentDate = moment('2017-01-19T20:02:26.000Z'); -// momentDate.tz('America/New_York'); -// const oaDate = momentDate.toOADateWithZone(); -// assert.equal(42754.835023148145, oaDate); -// // 1/19/2017 8:02:26 PM -// }); -// }); - From accfd435942cd6ffa14c7834ffe4c2ee433de663 Mon Sep 17 00:00:00 2001 From: Michael Lechner Date: Wed, 15 Mar 2017 11:58:41 -0600 Subject: [PATCH 07/23] readme cleanup --- README.md | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 877fd47..cc325dd 100644 --- a/README.md +++ b/README.md @@ -30,26 +30,31 @@ Convert an OA date with a known offset to UTC to a `moment` in UTC time For Moment formatting: -``` -// convert OA date into Moment (OA Date is assumed to be in UTC) -var momentDate = moment.fromOADate(42298.6868055556); -// if OA date is not in UTC and the offset to UTC is known it can be specified during the moment creation in minutes -var momentDate = moment.fromOADateOffsetToUtcByMinutes(42298.6868055556, 240) +convert OA date into Moment (OA Date is assumed to be in UTC) +``` +const momentDate = moment.fromOADate(42298.6868055556); +``` +if OA date is not in UTC and the offset to UTC is known it can be specified during the moment creation in minutes +``` +const momentDate = moment.fromOADateOffsetToUtcByMinutes(42298.6868055556, 240) momentDate.toISOString() returns '2015-10-21T20:29:00.000Z' (UTC) momentDate.format('LLLL') returns 'Wednesday, October 21, 2015 8:29 PM' (UTC) +``` -// if OA date is not in UTC and the offset to UTC is known it can be specified during the moment creation as a timezone -var momentDate = moment.fromOADateOffsetToUtcByMinutes(42298.6868055556, 'America/New_York') +if OA date is not in UTC and the offset to UTC is known it can be specified during the moment creation as a timezone +``` +const momentDate = moment.fromOADateOffsetToUtcByMinutes(42298.6868055556, 'America/New_York') momentDate.toISOString() returns '2015-10-21T20:29:00.000Z' (UTC) momentDate.format('LLLL') returns 'Wednesday, October 21, 2015 8:29 PM' (UTC) +``` -// once the date is in UTC it can than easily be converted to any other timezone using moment-timezone.js -var momentDate = moment.fromOADateOffsetToUtcByMinutes(42298.6868055556, 240) +once the date is in UTC it can than easily be converted to any other timezone using moment-timezone.js +``` +const momentDate = moment.fromOADateOffsetToUtcByMinutes(42298.6868055556, 240) momentDate.tz('America/New_York') momentDate.toISOString() returns '2015-10-21T20:29:00.000Z' (UTC) momentDate.format('LLLL') returns 'Wednesday, October 21, 2015 4:29 PM' (ET) - ``` **Note**: OLE Automation dates are unspecified and they’re based on the local timezone by default. The moment library normalizes all time to UTC and as a result this library will return all values based on UTC time. @@ -58,7 +63,10 @@ momentDate.format('LLLL') returns 'Wednesday, October 21, 2015 4:29 PM' (ET) Convert a `moment` to a floating point OA date in UTC: -`moment().toOADate();` +``` +const momentDate = moment('2015-10-21T16:29:00.000-07:00') +moment.toOADate() returns 42298.978472222225 +``` ### toOADateFromIso8601String(iso8601String) From f53f7700904af52462874596f1c0dedf8b34767b Mon Sep 17 00:00:00 2001 From: Michael Lechner Date: Wed, 15 Mar 2017 12:00:58 -0600 Subject: [PATCH 08/23] readme cleanup --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index cc325dd..f3caec0 100644 --- a/README.md +++ b/README.md @@ -71,8 +71,9 @@ moment.toOADate() returns 42298.978472222225 ### toOADateFromIso8601String(iso8601String) Convert an ISO 8601 String to a floating point OA date in UTC - -`moment.toOADateFromIso8601String(iso8601String)` +``` +moment.toOADateFromIso8601String('2015-10-21T16:29:00.000-07:00') returns 42298.978472222225 +``` ## License From 098608bd7fbeffa785012a43a4076b14fb7b277d Mon Sep 17 00:00:00 2001 From: Michael Lechner Date: Wed, 15 Mar 2017 12:01:48 -0600 Subject: [PATCH 09/23] readme cleanup --- README.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index f3caec0..c2b68e2 100644 --- a/README.md +++ b/README.md @@ -30,26 +30,26 @@ Convert an OA date with a known offset to UTC to a `moment` in UTC time For Moment formatting: - -convert OA date into Moment (OA Date is assumed to be in UTC) +Convert OA date into Moment (OA Date is assumed to be in UTC) ``` const momentDate = moment.fromOADate(42298.6868055556); ``` -if OA date is not in UTC and the offset to UTC is known it can be specified during the moment creation in minutes + +If OA date is not in UTC and the offset to UTC is known it can be specified during the moment creation in minutes ``` const momentDate = moment.fromOADateOffsetToUtcByMinutes(42298.6868055556, 240) momentDate.toISOString() returns '2015-10-21T20:29:00.000Z' (UTC) momentDate.format('LLLL') returns 'Wednesday, October 21, 2015 8:29 PM' (UTC) ``` -if OA date is not in UTC and the offset to UTC is known it can be specified during the moment creation as a timezone +If OA date is not in UTC and the offset to UTC is known it can be specified during the moment creation as a timezone ``` const momentDate = moment.fromOADateOffsetToUtcByMinutes(42298.6868055556, 'America/New_York') momentDate.toISOString() returns '2015-10-21T20:29:00.000Z' (UTC) momentDate.format('LLLL') returns 'Wednesday, October 21, 2015 8:29 PM' (UTC) ``` -once the date is in UTC it can than easily be converted to any other timezone using moment-timezone.js +Once the date is in UTC it can than easily be converted to any other timezone using moment-timezone.js ``` const momentDate = moment.fromOADateOffsetToUtcByMinutes(42298.6868055556, 240) momentDate.tz('America/New_York') @@ -62,7 +62,6 @@ momentDate.format('LLLL') returns 'Wednesday, October 21, 2015 4:29 PM' (ET) ### toOADate() Convert a `moment` to a floating point OA date in UTC: - ``` const momentDate = moment('2015-10-21T16:29:00.000-07:00') moment.toOADate() returns 42298.978472222225 From f589b474ec0e87f2a5dd078a1f8545a5be74b53a Mon Sep 17 00:00:00 2001 From: Michael Lechner Date: Wed, 15 Mar 2017 14:06:47 -0600 Subject: [PATCH 10/23] refactored to overload fromOADate --- README.md | 18 +++--------- moment-msdate.js | 42 +++++++++++++-------------- test/test.js | 75 ++++++++++++++++++++++-------------------------- 3 files changed, 60 insertions(+), 75 deletions(-) diff --git a/README.md b/README.md index c2b68e2..2465082 100644 --- a/README.md +++ b/README.md @@ -18,14 +18,11 @@ Convert an OA date to a `moment`: `moment.fromOADate(42298.6868055556)` returns `2015-10-21T16:29:00.000Z` -### fromOADateOffsetToUtcByMinutes(oaDate, offsetToUtcInMinutes) +### fromOADate(oaDate, offset) Convert an OA date with a known offset to UTC to a `moment` in UTC time `moment.fromOADate(42298.6868055556, 240)` returns `2015-10-21T20:29:00.000Z` - -### fromOADateOffsetToUtcByTimezone(oaDate, timezone) - `moment.fromOADate(42298.6868055556, 'America/New_York')` returns `2015-10-21T20:29:00.000Z` For Moment formatting: @@ -37,21 +34,21 @@ const momentDate = moment.fromOADate(42298.6868055556); If OA date is not in UTC and the offset to UTC is known it can be specified during the moment creation in minutes ``` -const momentDate = moment.fromOADateOffsetToUtcByMinutes(42298.6868055556, 240) +const momentDate = moment.fromOADate(42298.6868055556, 240) momentDate.toISOString() returns '2015-10-21T20:29:00.000Z' (UTC) momentDate.format('LLLL') returns 'Wednesday, October 21, 2015 8:29 PM' (UTC) ``` If OA date is not in UTC and the offset to UTC is known it can be specified during the moment creation as a timezone ``` -const momentDate = moment.fromOADateOffsetToUtcByMinutes(42298.6868055556, 'America/New_York') +const momentDate = moment.fromOADate(42298.6868055556, 'America/New_York') momentDate.toISOString() returns '2015-10-21T20:29:00.000Z' (UTC) momentDate.format('LLLL') returns 'Wednesday, October 21, 2015 8:29 PM' (UTC) ``` Once the date is in UTC it can than easily be converted to any other timezone using moment-timezone.js ``` -const momentDate = moment.fromOADateOffsetToUtcByMinutes(42298.6868055556, 240) +const momentDate = moment.fromOADate(42298.6868055556, 240) momentDate.tz('America/New_York') momentDate.toISOString() returns '2015-10-21T20:29:00.000Z' (UTC) momentDate.format('LLLL') returns 'Wednesday, October 21, 2015 4:29 PM' (ET) @@ -67,13 +64,6 @@ const momentDate = moment('2015-10-21T16:29:00.000-07:00') moment.toOADate() returns 42298.978472222225 ``` -### toOADateFromIso8601String(iso8601String) - -Convert an ISO 8601 String to a floating point OA date in UTC -``` -moment.toOADateFromIso8601String('2015-10-21T16:29:00.000-07:00') returns 42298.978472222225 -``` - ## License Copyright © 2014 Markit On Demand, Inc. diff --git a/moment-msdate.js b/moment-msdate.js index d4ccfa5..6b41908 100644 --- a/moment-msdate.js +++ b/moment-msdate.js @@ -31,18 +31,8 @@ return ((oaDate - MS_DAY_OFFSET) * DAY_MILLISECONDS) + (oaDate >= 0.0 ? 0.5 : -0.5); }; - const ticksToOADate = function(milliseconds) { - return (milliseconds / DAY_MILLISECONDS) + MS_DAY_OFFSET; - }; - - /** - * @description takes an oaDate that is in utc and converts it to a utc moment - * - * @param {double} oaDate - * @returns moment - */ - moment.fromOADate = function(oaDate) { - return moment(oaDateToTicks(oaDate)).utc(); + const ticksToOADate = function(ticks) { + return (ticks / DAY_MILLISECONDS) + MS_DAY_OFFSET; }; /** @@ -52,7 +42,7 @@ * @param {string} offsetToUtcInMinutes * @returns moment */ - moment.fromOADateOffsetToUtcByMinutes = function(oaDate, offsetToUtcInMinutes) { + const fromOADateOffsetToUtcByMinutes = function(oaDate, offsetToUtcInMinutes) { const offsetInTicks = offsetToUtcInMinutes * MINUTE_MILLISECONDS; const ticks = oaDateToTicks(oaDate); return moment(ticks + offsetInTicks).utc(); @@ -65,22 +55,32 @@ * @param {string} timezone * @returns moment */ - moment.fromOADateOffsetToUtcByTimezone = function(oaDate, timezone) { + const fromOADateOffsetToUtcByTimezone = function(oaDate, timezone) { + if (!moment.tz.zone(timezone)) { throw new Error('timezone provided is not available in moment-timezone.js', 'moment-msdate.js', 59); } const ticks = oaDateToTicks(oaDate); const offset = moment.tz(timezone).utcOffset() * MINUTE_MILLISECONDS; return moment.tz(ticks - offset, timezone).utc(); }; /** - * @description converts an ISO 8601 date time string to a UTC OLE automation date represented as a double + * @description takes an oaDate that is in utc and converts it to a utc moment or takes an oaDate and an offset to utc and converts it to a utc moment. The offset can be an int representing the offset to utc in minutes or a string indicating the timezone of the oaDate. * - * @param {string} iso8601String - * @returns {double} + * @param {double} oaDate + * @param {string=} {int=} offset + * @returns moment */ - moment.toOADateFromIso8601String = function(iso8601String) { - const myMoment = moment(iso8601String).utc(); - const milliseconds = myMoment.valueOf(); - return ticksToOADate(milliseconds); + moment.fromOADate = function(oaDate, offset) { + if (isNaN(parseInt(oaDate, 10))) { throw new TypeError('fromOADate requires an oaDate that is not null or undefined', 'moment-msdate.js', 72); } + + /* no offset */ + if (!offset) { return fromOADateOffsetToUtcByMinutes(oaDate, 0); } + + /* timezone */ + const parsedOffset = parseInt(offset, 10); + if (isNaN(parsedOffset)) { return fromOADateOffsetToUtcByTimezone(oaDate, offset); } + + /* minutes */ + return fromOADateOffsetToUtcByMinutes(oaDate, parsedOffset); }; /** diff --git a/test/test.js b/test/test.js index eca4d6a..4b3fe1b 100644 --- a/test/test.js +++ b/test/test.js @@ -8,12 +8,29 @@ describe('moment-msdate', () => { console.log('*** great scott!! it\'s 2015-10-21T16:29:00.000-07:00 ***'); console.log('********************************************************'); + describe('moment.fromOADate - error handling', () => { + it('should throw an error if oaDate is null', () => { + assert.throws(function() { moment.fromOADate(null); }, function(e) { return e instanceof TypeError; }); + }); + + it('should throw an error if oaDate is undefined', () => { + assert.throws(function() { moment.fromOADate(undefined); }, function(e) { return e instanceof TypeError; }); + }); + + it('should throw an error if offset is a timezone not available in moment-timezone.js', () => { + assert.throws( + function() { moment.fromOADate(42298.6868055556, 'Roads? Where we\'re going, we don\'t need roads.'); }, + function(e) { return e instanceof Error; } + ); + }); + }); + describe('moment.fromOADate', () => { it('should convert 42298.6868055556 to 2015-10-21T16:29:00.000Z', () => { assert.equal(moment.fromOADate(42298.6868055556).toISOString(), '2015-10-21T16:29:00.000Z'); }); - it('should convert 42298.978472222225 to America/Los_Angeles timezone', () => { + it('should not interfer with moment timezone', () => { const myMoment = moment.fromOADate(42298.978472222225); myMoment.tz('America/Los_Angeles'); assert.equal(myMoment.format('LLLL'), 'Wednesday, October 21, 2015 4:29 PM'); @@ -25,97 +42,75 @@ describe('moment-msdate', () => { }); }); - describe('moment.fromOADateOffsetToUtcByMinutes', () => { + describe('moment.fromOADate - minutes', () => { it('should convert 42298.6868055556 to 2015-10-21T16:29:00.000Z', () => { - assert.equal(moment.fromOADateOffsetToUtcByMinutes(42298.6868055556, 0).toISOString(), '2015-10-21T16:29:00.000Z'); + assert.equal(moment.fromOADate(42298.6868055556, 0).toISOString(), '2015-10-21T16:29:00.000Z'); }); it('should convert 42298.6868055556 to 2015-10-21T20:29:00.000Z', () => { - assert.equal(moment.fromOADateOffsetToUtcByMinutes(42298.6868055556, 240).toISOString(), '2015-10-21T20:29:00.000Z'); - assert.equal(moment.fromOADateOffsetToUtcByMinutes(42298.6868055556, 240).format('LLLL'), 'Wednesday, October 21, 2015 8:29 PM'); + assert.equal(moment.fromOADate(42298.6868055556, 240).toISOString(), '2015-10-21T20:29:00.000Z'); + assert.equal(moment.fromOADate(42298.6868055556, 240).format('LLLL'), 'Wednesday, October 21, 2015 8:29 PM'); }); it('should convert 42298.6868055556 to 2015-10-21T21:29:00.000Z', () => { - assert.equal(moment.fromOADateOffsetToUtcByMinutes(42298.6868055556, 300).toISOString(), '2015-10-21T21:29:00.000Z'); + assert.equal(moment.fromOADate(42298.6868055556, 300).toISOString(), '2015-10-21T21:29:00.000Z'); }); it('should convert 42298.6868055556 to 2015-10-21T22:29:00.000Z', () => { - assert.equal(moment.fromOADateOffsetToUtcByMinutes(42298.6868055556, 360).toISOString(), '2015-10-21T22:29:00.000Z'); + assert.equal(moment.fromOADate(42298.6868055556, 360).toISOString(), '2015-10-21T22:29:00.000Z'); }); it('should convert 42298.6868055556 to 2015-10-21T23:29:00.000Z', () => { - assert.equal(moment.fromOADateOffsetToUtcByMinutes(42298.6868055556, 420).toISOString(), '2015-10-21T23:29:00.000Z'); + assert.equal(moment.fromOADate(42298.6868055556, 420).toISOString(), '2015-10-21T23:29:00.000Z'); }); it('should convert 42298.6868055556 to 2015-10-21T23:29:00.000Z', () => { - assert.equal(moment.fromOADateOffsetToUtcByMinutes(42298.6868055556, 420).toISOString(), '2015-10-21T23:29:00.000Z'); + assert.equal(moment.fromOADate(42298.6868055556, 420).toISOString(), '2015-10-21T23:29:00.000Z'); }); it('should have a timezone of utc', () => { - const myMoment = moment.fromOADateOffsetToUtcByMinutes(42298.6868055556, 240); + const myMoment = moment.fromOADate(42298.6868055556, 240); assert.ok(myMoment.isUtc()); }); it('should not interfere with moment-timezone', () => { - const myMoment = moment.fromOADateOffsetToUtcByMinutes(42298.6868055556, 240); + const myMoment = moment.fromOADate(42298.6868055556, 240); myMoment.tz('America/New_York'); assert.equal(myMoment.toISOString(), '2015-10-21T20:29:00.000Z'); assert.equal(myMoment.format('LLLL'), 'Wednesday, October 21, 2015 4:29 PM'); }); }); - describe('moment.fromOADateOffsetToUtcByTimezone', () => { + describe('moment.fromOADate - timezone', () => { it('should convert 42298.6868055556 to 2015-10-21T20:29:00.000Z', () => { - assert.equal(moment.fromOADateOffsetToUtcByTimezone(42298.6868055556, 'America/New_York').toISOString(), '2015-10-21T20:29:00.000Z'); + assert.equal(moment.fromOADate(42298.6868055556, 'America/New_York').toISOString(), '2015-10-21T20:29:00.000Z'); }); it('should convert 42298.6868055556 to 2015-10-21T21:29:00.000Z', () => { - assert.equal(moment.fromOADateOffsetToUtcByTimezone(42298.6868055556, 'America/Chicago').toISOString(), '2015-10-21T21:29:00.000Z'); + assert.equal(moment.fromOADate(42298.6868055556, 'America/Chicago').toISOString(), '2015-10-21T21:29:00.000Z'); }); it('should convert 42298.6868055556 to 2015-10-21T22:29:00.000Z', () => { - assert.equal(moment.fromOADateOffsetToUtcByTimezone(42298.6868055556, 'America/Denver').toISOString(), '2015-10-21T22:29:00.000Z'); + assert.equal(moment.fromOADate(42298.6868055556, 'America/Denver').toISOString(), '2015-10-21T22:29:00.000Z'); }); it('should convert 42298.6868055556 to 2015-10-21T23:29:00.000Z', () => { - assert.equal(moment.fromOADateOffsetToUtcByTimezone(42298.6868055556, 'America/Los_Angeles').toISOString(), '2015-10-21T23:29:00.000Z'); + assert.equal(moment.fromOADate(42298.6868055556, 'America/Los_Angeles').toISOString(), '2015-10-21T23:29:00.000Z'); }); it('should have a timezone of utc', () => { - const myMoment = moment.fromOADateOffsetToUtcByTimezone(42298.6868055556, 'America/New_York'); + const myMoment = moment.fromOADate(42298.6868055556, 'America/New_York'); assert.ok(myMoment.isUtc()); }); it('should not interfere with moment-timezone', () => { - const myMoment = moment.fromOADateOffsetToUtcByTimezone(42298.6868055556, 'America/New_York'); + const myMoment = moment.fromOADate(42298.6868055556, 'America/New_York'); myMoment.tz('America/New_York'); assert.equal(myMoment.toISOString(), '2015-10-21T20:29:00.000Z'); assert.equal(myMoment.format('LLLL'), 'Wednesday, October 21, 2015 4:29 PM'); }); }); - describe('moment.toOADateFromIso8601String', () => { - it('should convert 2015-10-21T16:29:00.000Z to 42298.6868055556', () => { - assert.equal(moment.toOADateFromIso8601String('2015-10-21T16:29:00.000Z'), 42298.68680555555); - }); - - it('should convert 2015-10-21T16:29:00.000-04:00 to 42298.6868055556', () => { - assert.equal(moment.toOADateFromIso8601String('2015-10-21T16:29:00.000-04:00'), 42298.853472222225); - }); - - it('should convert 2015-10-21T16:29:00.000-04:00 to 42298.6868055556', () => { - assert.equal(moment.toOADateFromIso8601String('2015-10-21T16:29:00.000-05:00'), 42298.89513888889); - }); - - it('should convert 2015-10-21T16:29:00.000-04:00 to 42298.6868055556', () => { - assert.equal(moment.toOADateFromIso8601String('2015-10-21T16:29:00.000-06:00'), 42298.93680555555); - }); - - it('should convert 2015-10-21T16:29:00.000-04:00 to 42298.6868055556', () => { - assert.equal(moment.toOADateFromIso8601String('2015-10-21T16:29:00.000-07:00'), 42298.978472222225); - }); - }); - describe('moment.fn.toOADate', () => { it('should convert 2015-10-21T16:29:00.000Z to 42298.6868055556', () => { const myMoment = moment('2015-10-21T16:29:00.000Z').utc(); From ae51a94b7f71674c9071eb5c8117a13a893c7bf7 Mon Sep 17 00:00:00 2001 From: Michael Lechner Date: Wed, 15 Mar 2017 14:10:02 -0600 Subject: [PATCH 11/23] minor readme cleanup --- README.md | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 2465082..0a060d8 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # moment-msdate [![Build Status](https://travis-ci.org/markitondemand/moment-msdate.svg?branch=master)](https://travis-ci.org/markitondemand/moment-msdate) [![npm version](https://badge.fury.io/js/moment-msdate.svg)](https://badge.fury.io/js/moment-msdate) -A [Moment.js](http://momentjs.com/) and [Moment-timezone.js](http://momentjs.com/timezone) plugin for parsing OLE Automation dates. +A [moment.js](http://momentjs.com/) and [moment-timezone.js](http://momentjs.com/timezone) plugin for parsing OLE Automation dates. Visit [http://markitondemand.github.io/moment-msdate/](http://markitondemand.github.io/moment-msdate/) for more information and examples. @@ -21,11 +21,20 @@ Convert an OA date to a `moment`: ### fromOADate(oaDate, offset) Convert an OA date with a known offset to UTC to a `moment` in UTC time +``` +moment.fromOADate(42298.6868055556, 240) returns 2015-10-21T20:29:00.000Z +moment.fromOADate(42298.6868055556, 'America/New_York') returns `2015-10-21T20:29:00.000Z +``` -`moment.fromOADate(42298.6868055556, 240)` returns `2015-10-21T20:29:00.000Z` -`moment.fromOADate(42298.6868055556, 'America/New_York')` returns `2015-10-21T20:29:00.000Z` +### toOADate() + +Convert a `moment` to a floating point OA date in UTC: +``` +const momentDate = moment('2015-10-21T16:29:00.000-07:00') +moment.toOADate() returns 42298.978472222225 +``` -For Moment formatting: +### Example Moment Formatting: Convert OA date into Moment (OA Date is assumed to be in UTC) ``` @@ -56,14 +65,6 @@ momentDate.format('LLLL') returns 'Wednesday, October 21, 2015 4:29 PM' (ET) **Note**: OLE Automation dates are unspecified and they’re based on the local timezone by default. The moment library normalizes all time to UTC and as a result this library will return all values based on UTC time. -### toOADate() - -Convert a `moment` to a floating point OA date in UTC: -``` -const momentDate = moment('2015-10-21T16:29:00.000-07:00') -moment.toOADate() returns 42298.978472222225 -``` - ## License Copyright © 2014 Markit On Demand, Inc. From bc07ce770a99d68fe41d7fe70462fc72352000af Mon Sep 17 00:00:00 2001 From: Michael Lechner Date: Wed, 15 Mar 2017 14:18:00 -0600 Subject: [PATCH 12/23] minor readme cleanup --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0a060d8..5a3d5df 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,8 @@ An OLE Automation date, or "MSDate" as we call it, is implemented as a floating- Read more [about OLE Automation on MSDN](http://msdn.microsoft.com/en-us/library/dt80be78(v=vs.71).aspx) (including [`DateTime.ToOADate`](http://msdn.microsoft.com/en-us/library/system.datetime.tooadate.aspx) and [`DateTime.FromOADate`](http://msdn.microsoft.com/en-us/library/system.datetime.fromoadate.aspx)). +**Note**: OLE Automation dates are unspecified and they’re based on the local timezone by default. The moment library normalizes all time to UTC and as a result this library will return all values based on UTC time. + ## Usage ### fromOADate(oaDate) @@ -63,8 +65,6 @@ momentDate.toISOString() returns '2015-10-21T20:29:00.000Z' (UTC) momentDate.format('LLLL') returns 'Wednesday, October 21, 2015 4:29 PM' (ET) ``` -**Note**: OLE Automation dates are unspecified and they’re based on the local timezone by default. The moment library normalizes all time to UTC and as a result this library will return all values based on UTC time. - ## License Copyright © 2014 Markit On Demand, Inc. From 065897a5b1e1c7508b7e0ede07dde15d2217c155 Mon Sep 17 00:00:00 2001 From: Michael Lechner Date: Wed, 15 Mar 2017 14:20:45 -0600 Subject: [PATCH 13/23] minor readme cleanup --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index 5a3d5df..ce48005 100644 --- a/README.md +++ b/README.md @@ -14,14 +14,12 @@ Read more [about OLE Automation on MSDN](http://msdn.microsoft.com/en-us/library ## Usage -### fromOADate(oaDate) +### fromOADate(oaDate, [offset]) Convert an OA date to a `moment`: `moment.fromOADate(42298.6868055556)` returns `2015-10-21T16:29:00.000Z` -### fromOADate(oaDate, offset) - Convert an OA date with a known offset to UTC to a `moment` in UTC time ``` moment.fromOADate(42298.6868055556, 240) returns 2015-10-21T20:29:00.000Z From 64d66aba50cb2427c703e486a7e832a5b1f1c9e6 Mon Sep 17 00:00:00 2001 From: Michael Lechner Date: Wed, 15 Mar 2017 14:23:56 -0600 Subject: [PATCH 14/23] v2.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 308eee5..c365716 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "moment-msdate", - "version": "1.0.0", + "version": "2.0.0", "description": "Adds OLE Automation parsing capabilities to Moment.js", "main": "moment-msdate.js", "scripts": { From 7a9373e71b1977e98cbfbaf6054afde5ebf8f44f Mon Sep 17 00:00:00 2001 From: Michael Lechner Date: Wed, 15 Mar 2017 15:21:23 -0600 Subject: [PATCH 15/23] excluding linting on node-modules --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c365716..036719a 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "Adds OLE Automation parsing capabilities to Moment.js", "main": "moment-msdate.js", "scripts": { - "lint": "eslint ./test ./moment-msdate.js", + "lint": "eslint ./test ./moment-msdate.js !./node-modules", "mocha": "mocha --check-leaks --reporter=spec ./test", "test": "npm run lint && npm run mocha" }, From 5371a5052750ad0ad38c2310ab71e2d1d6db2fd0 Mon Sep 17 00:00:00 2001 From: Michael Lechner Date: Wed, 15 Mar 2017 15:34:16 -0600 Subject: [PATCH 16/23] fixing test labels --- test/test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/test.js b/test/test.js index 4b3fe1b..a82850f 100644 --- a/test/test.js +++ b/test/test.js @@ -117,22 +117,22 @@ describe('moment-msdate', () => { assert.equal(myMoment.toOADate(), 42298.68680555555); }); - it('should convert 2015-10-21T16:29:00.000-04:00 to 42298.6868055556', () => { + it('should convert 2015-10-21T16:29:00.000-04:00 to 42298.853472222225', () => { const myMoment = moment('2015-10-21T16:29:00.000-04:00').utc(); assert.equal(myMoment.toOADate(), 42298.853472222225); }); - it('should convert 2015-10-21T16:29:00.000-04:00 to 42298.6868055556', () => { + it('should convert 2015-10-21T16:29:00.000-05:00 to 42298.89513888889', () => { const myMoment = moment('2015-10-21T16:29:00.000-05:00').utc(); assert.equal(myMoment.toOADate(), 42298.89513888889); }); - it('should convert 2015-10-21T16:29:00.000-04:00 to 42298.6868055556', () => { + it('should convert 2015-10-21T16:29:00.000-06:00 to 42298.93680555555', () => { const myMoment = moment('2015-10-21T16:29:00.000-06:00'); assert.equal(myMoment.toOADate(), 42298.93680555555); }); - it('should convert 2015-10-21T16:29:00.000-04:00 to 42298.6868055556', () => { + it('should convert 2015-10-21T16:29:00.000-07:00 to 42298.978472222225', () => { const myMoment = moment('2015-10-21T16:29:00.000-07:00'); assert.equal(myMoment.toOADate(), 42298.978472222225); }); From 3f8ad4876c1d39e4caadd1ceb857a0c760c0318b Mon Sep 17 00:00:00 2001 From: Michael Lechner Date: Fri, 17 Mar 2017 10:35:46 -0600 Subject: [PATCH 17/23] updating documentation to reflect using the toOADate method on a moment instance --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ce48005..1d49ad2 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ moment.fromOADate(42298.6868055556, 'America/New_York') returns `2015-10-21T20:2 Convert a `moment` to a floating point OA date in UTC: ``` const momentDate = moment('2015-10-21T16:29:00.000-07:00') -moment.toOADate() returns 42298.978472222225 +momentDate.toOADate() returns 42298.978472222225 ``` ### Example Moment Formatting: From 0f9ae6511aa4266cca2ac31d41c1587ee793abf9 Mon Sep 17 00:00:00 2001 From: Michael Lechner Date: Mon, 3 Apr 2017 09:55:47 -0600 Subject: [PATCH 18/23] removing comment --- moment-msdate.js | 1 - 1 file changed, 1 deletion(-) diff --git a/moment-msdate.js b/moment-msdate.js index 6b41908..b13f4ce 100644 --- a/moment-msdate.js +++ b/moment-msdate.js @@ -7,7 +7,6 @@ } else if (typeof module === 'object' && module.exports) { module.exports = factory(require('moment'), require('moment-timezone')); // Node } else { - // correct way to load moment-timezone? factory(root.moment, root.moment.tz); // Browser } }(this, (moment, momentTimezone) => { From 1a020cdcb2417ad0c5f5b93c016573bc26947825 Mon Sep 17 00:00:00 2001 From: Michael Lechner Date: Wed, 17 May 2017 13:12:28 -0600 Subject: [PATCH 19/23] 2.0.1-0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 036719a..ce412f6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "moment-msdate", - "version": "2.0.0", + "version": "2.0.1-0", "description": "Adds OLE Automation parsing capabilities to Moment.js", "main": "moment-msdate.js", "scripts": { From fad523041ef77307cae8f328125c23c71c84a597 Mon Sep 17 00:00:00 2001 From: Matt Lackey Date: Tue, 21 Nov 2017 15:26:03 -0700 Subject: [PATCH 20/23] corrects eslint errors --- .eslintrc | 4 +++- moment-msdate.js | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.eslintrc b/.eslintrc index a7eca29..1ef75f1 100644 --- a/.eslintrc +++ b/.eslintrc @@ -22,6 +22,8 @@ "comma-dangle": [2, "never"], "no-underscore-dangle": 0, "no-empty-function": 1, - "no-param-reassign": 0 + "no-param-reassign": 0, + "no-var":"off", + "prefer-arrow-callback": 0 } } \ No newline at end of file diff --git a/moment-msdate.js b/moment-msdate.js index e92a462..55ca5d3 100644 --- a/moment-msdate.js +++ b/moment-msdate.js @@ -9,7 +9,8 @@ } else { factory(root.moment, root.moment.tz); // Browser } -}(this, (moment, momentTimezone) => { +}(this, function(moment, momentTimezone) { + var MINUTE_MILLISECONDS = 60 * 1000; var DAY_MILLISECONDS = 86400000; var MS_DAY_OFFSET = 25569; From 843888511b50ba05aabcee34bf4c5307c51febcc Mon Sep 17 00:00:00 2001 From: Brian Baker Date: Tue, 21 Nov 2017 15:33:24 -0700 Subject: [PATCH 21/23] corrected merge issues though tests still fail --- moment-msdate.js | 5 +- package-lock.json | 769 +++++++++++++++++++++++++++++++++++++++++++++- test/test.js | 4 +- 3 files changed, 773 insertions(+), 5 deletions(-) diff --git a/moment-msdate.js b/moment-msdate.js index e92a462..57c2a0b 100644 --- a/moment-msdate.js +++ b/moment-msdate.js @@ -10,8 +10,9 @@ factory(root.moment, root.moment.tz); // Browser } }(this, (moment, momentTimezone) => { - var DAY_MILLISECONDS = 86400000; - var MS_DAY_OFFSET = 25569; + const DAY_MILLISECONDS = 86400000; + const MINUTE_MILLISECONDS = 60000; + const MS_DAY_OFFSET = 25569; const momentVersion = moment.version.split('.'); const major = +momentVersion[0]; diff --git a/package-lock.json b/package-lock.json index 4a79a48..a7f29c3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,9 +1,15 @@ { "name": "moment-msdate", - "version": "0.2.3", + "version": "2.0.1-0", "lockfileVersion": 1, "requires": true, "dependencies": { + "abbrev": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", + "integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==", + "dev": true + }, "acorn": { "version": "5.2.1", "resolved": "http://maven.markit.partners/artifactory/api/npm/npm_mod/acorn/-/acorn-5.2.1.tgz", @@ -70,6 +76,12 @@ "sprintf-js": "1.0.3" } }, + "array-find-index": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/array-find-index/-/array-find-index-1.0.2.tgz", + "integrity": "sha1-3wEKoSh+Fku9pvlyOwqWoexBh6E=", + "dev": true + }, "array-union": { "version": "1.0.2", "resolved": "http://maven.markit.partners/artifactory/api/npm/npm_mod/array-union/-/array-union-1.0.2.tgz", @@ -101,6 +113,12 @@ "integrity": "sha1-iYUI2iIm84DfkEcoRWhJwVAaSw0=", "dev": true }, + "async": { + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/async/-/async-1.5.2.tgz", + "integrity": "sha1-7GphrlZIDAw8skHJVhjiCJL5Zyo=", + "dev": true + }, "babel-code-frame": { "version": "6.26.0", "resolved": "http://maven.markit.partners/artifactory/api/npm/npm_mod/babel-code-frame/-/babel-code-frame-6.26.0.tgz", @@ -118,6 +136,53 @@ "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", "dev": true }, + "body-parser": { + "version": "1.14.2", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.14.2.tgz", + "integrity": "sha1-EBXLH+LEQ4WCWVgdtTMy+NDPUPk=", + "dev": true, + "requires": { + "bytes": "2.2.0", + "content-type": "1.0.4", + "debug": "2.2.0", + "depd": "1.1.1", + "http-errors": "1.3.1", + "iconv-lite": "0.4.13", + "on-finished": "2.3.0", + "qs": "5.2.0", + "raw-body": "2.1.7", + "type-is": "1.6.15" + }, + "dependencies": { + "debug": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.2.0.tgz", + "integrity": "sha1-+HBX6ZWxofauaklgZkE3vFbwOdo=", + "dev": true, + "requires": { + "ms": "0.7.1" + } + }, + "iconv-lite": { + "version": "0.4.13", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.13.tgz", + "integrity": "sha1-H4irpKsLFQjoMSrMOTRfNumS4vI=", + "dev": true + }, + "ms": { + "version": "0.7.1", + "resolved": "https://registry.npmjs.org/ms/-/ms-0.7.1.tgz", + "integrity": "sha1-nNE8A62/8ltl7/3nzoZO6VIBcJg=", + "dev": true + }, + "qs": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-5.2.0.tgz", + "integrity": "sha1-qfMRQq9GjLcrJbMBNrokVoNJFr4=", + "dev": true + } + } + }, "brace-expansion": { "version": "1.1.8", "resolved": "http://maven.markit.partners/artifactory/api/npm/npm_mod/brace-expansion/-/brace-expansion-1.1.8.tgz", @@ -140,6 +205,12 @@ "integrity": "sha1-Jw8HbFpywC9bZaR9+Uxf46J4iS8=", "dev": true }, + "bytes": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/bytes/-/bytes-2.2.0.tgz", + "integrity": "sha1-/TVGSkA/b5EXwt42Cez/nK4ABYg=", + "dev": true + }, "caller-path": { "version": "0.1.0", "resolved": "http://maven.markit.partners/artifactory/api/npm/npm_mod/caller-path/-/caller-path-0.1.0.tgz", @@ -155,6 +226,22 @@ "integrity": "sha1-r6uWJikQp/M8GaV3WCXGnzTjUMo=", "dev": true }, + "camelcase": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-2.1.1.tgz", + "integrity": "sha1-fB0W1nmhu+WcoCys7PsBHiAfWh8=", + "dev": true + }, + "camelcase-keys": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/camelcase-keys/-/camelcase-keys-2.1.0.tgz", + "integrity": "sha1-MIvur/3ygRkFHvodkyITyRuPkuc=", + "dev": true, + "requires": { + "camelcase": "2.1.1", + "map-obj": "1.0.1" + } + }, "chalk": { "version": "1.1.3", "resolved": "http://maven.markit.partners/artifactory/api/npm/npm_mod/chalk/-/chalk-1.1.3.tgz", @@ -201,6 +288,18 @@ "integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=", "dev": true }, + "coffee-script": { + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/coffee-script/-/coffee-script-1.10.0.tgz", + "integrity": "sha1-EpOLz5vhlI+gBvkuDEyegXBRCMA=", + "dev": true + }, + "colors": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/colors/-/colors-1.1.2.tgz", + "integrity": "sha1-FopHAXVran9RoSzgyXv6KMCE7WM=", + "dev": true + }, "commander": { "version": "2.9.0", "resolved": "http://maven.markit.partners/artifactory/api/npm/npm_mod/commander/-/commander-2.9.0.tgz", @@ -233,12 +332,27 @@ "integrity": "sha1-/ozxhP9mcLa67wGp1IYaXL7EEgo=", "dev": true }, + "content-type": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz", + "integrity": "sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==", + "dev": true + }, "core-util-is": { "version": "1.0.2", "resolved": "http://maven.markit.partners/artifactory/api/npm/npm_mod/core-util-is/-/core-util-is-1.0.2.tgz", "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=", "dev": true }, + "currently-unhandled": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/currently-unhandled/-/currently-unhandled-0.4.1.tgz", + "integrity": "sha1-mI3zP+qxke95mmE2nddsF635V+o=", + "dev": true, + "requires": { + "array-find-index": "1.0.2" + } + }, "d": { "version": "1.0.0", "resolved": "http://maven.markit.partners/artifactory/api/npm/npm_mod/d/-/d-1.0.0.tgz", @@ -254,6 +368,16 @@ "integrity": "sha1-AxkcQyy27qFou3fzpV/9zLiXhRQ=", "dev": true }, + "dateformat": { + "version": "1.0.12", + "resolved": "https://registry.npmjs.org/dateformat/-/dateformat-1.0.12.tgz", + "integrity": "sha1-nxJLZ1lMk3/3BpMuSmQsyo27/uk=", + "dev": true, + "requires": { + "get-stdin": "4.0.1", + "meow": "3.7.0" + } + }, "debug": { "version": "2.6.9", "resolved": "http://maven.markit.partners/artifactory/api/npm/npm_mod/debug/-/debug-2.6.9.tgz", @@ -263,6 +387,12 @@ "ms": "2.0.0" } }, + "decamelize": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", + "integrity": "sha1-9lNNFRSCabIDUue+4m9QH5oZEpA=", + "dev": true + }, "deep-is": { "version": "0.1.3", "resolved": "http://maven.markit.partners/artifactory/api/npm/npm_mod/deep-is/-/deep-is-0.1.3.tgz", @@ -294,6 +424,12 @@ "rimraf": "2.6.2" } }, + "depd": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.1.tgz", + "integrity": "sha1-V4O04cRZ8G+lyif5kfPQbnoxA1k=", + "dev": true + }, "diff": { "version": "3.2.0", "resolved": "http://maven.markit.partners/artifactory/api/npm/npm_mod/diff/-/diff-3.2.0.tgz", @@ -310,6 +446,12 @@ "isarray": "1.0.0" } }, + "ee-first": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", + "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=", + "dev": true + }, "error-ex": { "version": "1.3.1", "resolved": "http://maven.markit.partners/artifactory/api/npm/npm_mod/error-ex/-/error-ex-1.3.1.tgz", @@ -641,6 +783,18 @@ "es5-ext": "0.10.35" } }, + "eventemitter2": { + "version": "0.4.14", + "resolved": "https://registry.npmjs.org/eventemitter2/-/eventemitter2-0.4.14.tgz", + "integrity": "sha1-j2G3XN4BKy6esoTUVFWDtWQ7Yas=", + "dev": true + }, + "exit": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/exit/-/exit-0.1.2.tgz", + "integrity": "sha1-BjJjj42HfMghB9MKD/8aF8uhzQw=", + "dev": true + }, "exit-hook": { "version": "1.1.1", "resolved": "http://maven.markit.partners/artifactory/api/npm/npm_mod/exit-hook/-/exit-hook-1.1.1.tgz", @@ -653,6 +807,15 @@ "integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=", "dev": true }, + "faye-websocket": { + "version": "0.10.0", + "resolved": "https://registry.npmjs.org/faye-websocket/-/faye-websocket-0.10.0.tgz", + "integrity": "sha1-TkkvjQTftviQA1B/btvy1QHnxvQ=", + "dev": true, + "requires": { + "websocket-driver": "0.7.0" + } + }, "figures": { "version": "1.7.0", "resolved": "http://maven.markit.partners/artifactory/api/npm/npm_mod/figures/-/figures-1.7.0.tgz", @@ -683,6 +846,30 @@ "pinkie-promise": "2.0.1" } }, + "findup-sync": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/findup-sync/-/findup-sync-0.3.0.tgz", + "integrity": "sha1-N5MKpdgWt3fANEXhlmzGeQpMCxY=", + "dev": true, + "requires": { + "glob": "5.0.15" + }, + "dependencies": { + "glob": { + "version": "5.0.15", + "resolved": "https://registry.npmjs.org/glob/-/glob-5.0.15.tgz", + "integrity": "sha1-G8k2ueAvSmA/zCIuz3Yz0wuLk7E=", + "dev": true, + "requires": { + "inflight": "1.0.6", + "inherits": "2.0.3", + "minimatch": "3.0.4", + "once": "1.4.0", + "path-is-absolute": "1.0.1" + } + } + } + }, "flat-cache": { "version": "1.3.0", "resolved": "http://maven.markit.partners/artifactory/api/npm/npm_mod/flat-cache/-/flat-cache-1.3.0.tgz", @@ -713,6 +900,15 @@ "integrity": "sha1-pWiZ0+o8m6uHS7l3O3xe3pL0iV0=", "dev": true }, + "gaze": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/gaze/-/gaze-1.1.2.tgz", + "integrity": "sha1-hHIkZ3rbiHDWeSV+0ziP22HkAQU=", + "dev": true, + "requires": { + "globule": "1.2.0" + } + }, "generate-function": { "version": "2.0.0", "resolved": "http://maven.markit.partners/artifactory/api/npm/npm_mod/generate-function/-/generate-function-2.0.0.tgz", @@ -728,6 +924,18 @@ "is-property": "1.0.2" } }, + "get-stdin": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-4.0.1.tgz", + "integrity": "sha1-uWjGsKBDhDJJAui/Gl3zJXmkUP4=", + "dev": true + }, + "getobject": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/getobject/-/getobject-0.1.0.tgz", + "integrity": "sha1-BHpEl4n6Fg0Bj1SG7ZEyC27HiFw=", + "dev": true + }, "glob": { "version": "7.1.2", "resolved": "http://maven.markit.partners/artifactory/api/npm/npm_mod/glob/-/glob-7.1.2.tgz", @@ -762,6 +970,17 @@ "pinkie-promise": "2.0.1" } }, + "globule": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/globule/-/globule-1.2.0.tgz", + "integrity": "sha1-HcScaCLdnoovoAuiopUAboZkvQk=", + "dev": true, + "requires": { + "glob": "7.1.2", + "lodash": "4.17.4", + "minimatch": "3.0.4" + } + }, "graceful-fs": { "version": "4.1.11", "resolved": "http://maven.markit.partners/artifactory/api/npm/npm_mod/graceful-fs/-/graceful-fs-4.1.11.tgz", @@ -780,6 +999,194 @@ "integrity": "sha1-Dqd0NxXbjY3ixe3hd14bRayFwC8=", "dev": true }, + "grunt": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/grunt/-/grunt-1.0.1.tgz", + "integrity": "sha1-6HeHZOlEsY8yuw8QuQeEdcnftWs=", + "dev": true, + "requires": { + "coffee-script": "1.10.0", + "dateformat": "1.0.12", + "eventemitter2": "0.4.14", + "exit": "0.1.2", + "findup-sync": "0.3.0", + "glob": "7.0.6", + "grunt-cli": "1.2.0", + "grunt-known-options": "1.1.0", + "grunt-legacy-log": "1.0.0", + "grunt-legacy-util": "1.0.0", + "iconv-lite": "0.4.19", + "js-yaml": "3.5.5", + "minimatch": "3.0.4", + "nopt": "3.0.6", + "path-is-absolute": "1.0.1", + "rimraf": "2.2.8" + }, + "dependencies": { + "esprima": { + "version": "2.7.3", + "resolved": "https://registry.npmjs.org/esprima/-/esprima-2.7.3.tgz", + "integrity": "sha1-luO3DVd59q1JzQMmc9HDEnZ7pYE=", + "dev": true + }, + "glob": { + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.0.6.tgz", + "integrity": "sha1-IRuvr0nlJbjNkyYNFKsTYVKz9Xo=", + "dev": true, + "requires": { + "fs.realpath": "1.0.0", + "inflight": "1.0.6", + "inherits": "2.0.3", + "minimatch": "3.0.4", + "once": "1.4.0", + "path-is-absolute": "1.0.1" + } + }, + "grunt-cli": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/grunt-cli/-/grunt-cli-1.2.0.tgz", + "integrity": "sha1-VisRnrsGndtGSs4oRVAb6Xs1tqg=", + "dev": true, + "requires": { + "findup-sync": "0.3.0", + "grunt-known-options": "1.1.0", + "nopt": "3.0.6", + "resolve": "1.1.7" + } + }, + "js-yaml": { + "version": "3.5.5", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.5.5.tgz", + "integrity": "sha1-A3fDgBfKvHMisNH7zSWkkWQfL74=", + "dev": true, + "requires": { + "argparse": "1.0.9", + "esprima": "2.7.3" + } + }, + "resolve": { + "version": "1.1.7", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.1.7.tgz", + "integrity": "sha1-IDEU2CrSxe2ejgQRs5ModeiJ6Xs=", + "dev": true + }, + "rimraf": { + "version": "2.2.8", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.2.8.tgz", + "integrity": "sha1-5Dm+Kq7jJzIZUnMPmaiSnk/FBYI=", + "dev": true + } + } + }, + "grunt-contrib-watch": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/grunt-contrib-watch/-/grunt-contrib-watch-1.0.0.tgz", + "integrity": "sha1-hKGnodar0m7VaEE0lscxM+mQAY8=", + "dev": true, + "requires": { + "async": "1.5.2", + "gaze": "1.1.2", + "lodash": "3.10.1", + "tiny-lr": "0.2.1" + }, + "dependencies": { + "lodash": { + "version": "3.10.1", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-3.10.1.tgz", + "integrity": "sha1-W/Rejkm6QYnhfUgnid/RW9FAt7Y=", + "dev": true + } + } + }, + "grunt-eslint": { + "version": "19.0.0", + "resolved": "https://registry.npmjs.org/grunt-eslint/-/grunt-eslint-19.0.0.tgz", + "integrity": "sha1-u3TDeQYVmc7B9mFp3vKonYYthhs=", + "dev": true, + "requires": { + "chalk": "1.1.3", + "eslint": "3.19.0" + } + }, + "grunt-known-options": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/grunt-known-options/-/grunt-known-options-1.1.0.tgz", + "integrity": "sha1-pCdO6zL6dl2lp6OxcSYXzjsUQUk=", + "dev": true + }, + "grunt-legacy-log": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/grunt-legacy-log/-/grunt-legacy-log-1.0.0.tgz", + "integrity": "sha1-+4bxgJhHvAfcR4Q/ns1srLYt8tU=", + "dev": true, + "requires": { + "colors": "1.1.2", + "grunt-legacy-log-utils": "1.0.0", + "hooker": "0.2.3", + "lodash": "3.10.1", + "underscore.string": "3.2.3" + }, + "dependencies": { + "lodash": { + "version": "3.10.1", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-3.10.1.tgz", + "integrity": "sha1-W/Rejkm6QYnhfUgnid/RW9FAt7Y=", + "dev": true + } + } + }, + "grunt-legacy-log-utils": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/grunt-legacy-log-utils/-/grunt-legacy-log-utils-1.0.0.tgz", + "integrity": "sha1-p7ji0Ps1taUPSvmG/BEnSevJbz0=", + "dev": true, + "requires": { + "chalk": "1.1.3", + "lodash": "4.3.0" + }, + "dependencies": { + "lodash": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.3.0.tgz", + "integrity": "sha1-79nEpuxT87BUEkKZFcPkgk5NJaQ=", + "dev": true + } + } + }, + "grunt-legacy-util": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/grunt-legacy-util/-/grunt-legacy-util-1.0.0.tgz", + "integrity": "sha1-OGqnjcbtUJhsKxiVcmWxtIq7m4Y=", + "dev": true, + "requires": { + "async": "1.5.2", + "exit": "0.1.2", + "getobject": "0.1.0", + "hooker": "0.2.3", + "lodash": "4.3.0", + "underscore.string": "3.2.3", + "which": "1.2.14" + }, + "dependencies": { + "lodash": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.3.0.tgz", + "integrity": "sha1-79nEpuxT87BUEkKZFcPkgk5NJaQ=", + "dev": true + } + } + }, + "grunt-mocha-test": { + "version": "0.13.3", + "resolved": "https://registry.npmjs.org/grunt-mocha-test/-/grunt-mocha-test-0.13.3.tgz", + "integrity": "sha512-zQGEsi3d+ViPPi7/4jcj78afKKAKiAA5n61pknQYi25Ugik+aNOuRmiOkmb8mN2CeG8YxT+YdT1H1Q7B/eNkoQ==", + "dev": true, + "requires": { + "hooker": "0.2.3", + "mkdirp": "0.5.1" + } + }, "has": { "version": "1.0.1", "resolved": "http://maven.markit.partners/artifactory/api/npm/npm_mod/has/-/has-1.0.1.tgz", @@ -810,12 +1217,40 @@ "integrity": "sha1-k0EP0hsAlzUVH4howvJx80J+I/0=", "dev": true }, + "hooker": { + "version": "0.2.3", + "resolved": "https://registry.npmjs.org/hooker/-/hooker-0.2.3.tgz", + "integrity": "sha1-uDT3I8xKJCqmWWNFnfbZhMXT2Vk=", + "dev": true + }, "hosted-git-info": { "version": "2.5.0", "resolved": "http://maven.markit.partners/artifactory/api/npm/npm_mod/hosted-git-info/-/hosted-git-info-2.5.0.tgz", "integrity": "sha1-bWDjSzq7yDEwYsO3mO+NkBoHrzw=", "dev": true }, + "http-errors": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.3.1.tgz", + "integrity": "sha1-GX4izevUGYWF6GlO9nhhl7ke2UI=", + "dev": true, + "requires": { + "inherits": "2.0.3", + "statuses": "1.4.0" + } + }, + "http-parser-js": { + "version": "0.4.9", + "resolved": "https://registry.npmjs.org/http-parser-js/-/http-parser-js-0.4.9.tgz", + "integrity": "sha1-6hoE+2St/wJC6ZdPKX3Uw8rSceE=", + "dev": true + }, + "iconv-lite": { + "version": "0.4.19", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.19.tgz", + "integrity": "sha512-oTZqweIP51xaGPI4uPa56/Pri/480R+mo7SeU+YETByQNhDG55ycFyNLIgta9vXhILrxXDmF7ZGhqZIcuN0gJQ==", + "dev": true + }, "ignore": { "version": "3.3.7", "resolved": "http://maven.markit.partners/artifactory/api/npm/npm_mod/ignore/-/ignore-3.3.7.tgz", @@ -828,6 +1263,15 @@ "integrity": "sha1-khi5srkoojixPcT7a21XbyMUU+o=", "dev": true }, + "indent-string": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/indent-string/-/indent-string-2.1.0.tgz", + "integrity": "sha1-ji1INIdCEhtKghi3oTfppSBJ3IA=", + "dev": true, + "requires": { + "repeating": "2.0.1" + } + }, "inflight": { "version": "1.0.6", "resolved": "http://maven.markit.partners/artifactory/api/npm/npm_mod/inflight/-/inflight-1.0.6.tgz", @@ -898,6 +1342,15 @@ "integrity": "sha1-mqIOtq7rv/d/vTPnTKAbM1gdOhY=", "dev": true }, + "is-finite": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/is-finite/-/is-finite-1.0.2.tgz", + "integrity": "sha1-zGZ3aVYCvlUO8R6LSqYwU0K20Ko=", + "dev": true, + "requires": { + "number-is-nan": "1.0.1" + } + }, "is-fullwidth-code-point": { "version": "1.0.0", "resolved": "http://maven.markit.partners/artifactory/api/npm/npm_mod/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz", @@ -973,12 +1426,24 @@ "integrity": "sha1-PMWfAAJRlLarLjjbrmaJJWtmBXI=", "dev": true }, + "is-utf8": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/is-utf8/-/is-utf8-0.2.1.tgz", + "integrity": "sha1-Sw2hRCEE0bM2NA6AeX6GXPOffXI=", + "dev": true + }, "isarray": { "version": "1.0.0", "resolved": "http://maven.markit.partners/artifactory/api/npm/npm_mod/isarray/-/isarray-1.0.0.tgz", "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=", "dev": true }, + "isexe": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", + "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=", + "dev": true + }, "js-tokens": { "version": "3.0.2", "resolved": "http://maven.markit.partners/artifactory/api/npm/npm_mod/js-tokens/-/js-tokens-3.0.2.tgz", @@ -1038,6 +1503,12 @@ "type-check": "0.3.2" } }, + "livereload-js": { + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/livereload-js/-/livereload-js-2.2.2.tgz", + "integrity": "sha1-bIclfmSKtHW8JOoldFftzB+NC8I=", + "dev": true + }, "load-json-file": { "version": "2.0.0", "resolved": "http://maven.markit.partners/artifactory/api/npm/npm_mod/load-json-file/-/load-json-file-2.0.0.tgz", @@ -1148,6 +1619,123 @@ "lodash.isarray": "3.0.4" } }, + "loud-rejection": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/loud-rejection/-/loud-rejection-1.6.0.tgz", + "integrity": "sha1-W0b4AUft7leIcPCG0Eghz5mOVR8=", + "dev": true, + "requires": { + "currently-unhandled": "0.4.1", + "signal-exit": "3.0.2" + } + }, + "map-obj": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/map-obj/-/map-obj-1.0.1.tgz", + "integrity": "sha1-2TPOuSBdgr3PSIb2dCvcK03qFG0=", + "dev": true + }, + "media-typer": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", + "integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=", + "dev": true + }, + "meow": { + "version": "3.7.0", + "resolved": "https://registry.npmjs.org/meow/-/meow-3.7.0.tgz", + "integrity": "sha1-cstmi0JSKCkKu/qFaJJYcwioAfs=", + "dev": true, + "requires": { + "camelcase-keys": "2.1.0", + "decamelize": "1.2.0", + "loud-rejection": "1.6.0", + "map-obj": "1.0.1", + "minimist": "1.2.0", + "normalize-package-data": "2.4.0", + "object-assign": "4.1.1", + "read-pkg-up": "1.0.1", + "redent": "1.0.0", + "trim-newlines": "1.0.0" + }, + "dependencies": { + "load-json-file": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-1.1.0.tgz", + "integrity": "sha1-lWkFcI1YtLq0wiYbBPWfMcmTdMA=", + "dev": true, + "requires": { + "graceful-fs": "4.1.11", + "parse-json": "2.2.0", + "pify": "2.3.0", + "pinkie-promise": "2.0.1", + "strip-bom": "2.0.0" + } + }, + "minimist": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", + "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", + "dev": true + }, + "path-type": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/path-type/-/path-type-1.1.0.tgz", + "integrity": "sha1-WcRPfuSR2nBNpBXaWkBwuk+P5EE=", + "dev": true, + "requires": { + "graceful-fs": "4.1.11", + "pify": "2.3.0", + "pinkie-promise": "2.0.1" + } + }, + "read-pkg": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-1.1.0.tgz", + "integrity": "sha1-9f+qXs0pyzHAR0vKfXVra7KePyg=", + "dev": true, + "requires": { + "load-json-file": "1.1.0", + "normalize-package-data": "2.4.0", + "path-type": "1.1.0" + } + }, + "read-pkg-up": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/read-pkg-up/-/read-pkg-up-1.0.1.tgz", + "integrity": "sha1-nWPBMnbAZZGNV/ACpX9AobZD+wI=", + "dev": true, + "requires": { + "find-up": "1.1.2", + "read-pkg": "1.1.0" + } + }, + "strip-bom": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-2.0.0.tgz", + "integrity": "sha1-YhmoVhZSBJHzV4i9vxRHqZx+aw4=", + "dev": true, + "requires": { + "is-utf8": "0.2.1" + } + } + } + }, + "mime-db": { + "version": "1.30.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.30.0.tgz", + "integrity": "sha1-dMZD2i3Z1qRTmZY0ZbJtXKfXHwE=", + "dev": true + }, + "mime-types": { + "version": "2.1.17", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.17.tgz", + "integrity": "sha1-Cdejk/A+mVp5+K+Fe3Cp4KsWVXo=", + "dev": true, + "requires": { + "mime-db": "1.30.0" + } + }, "minimatch": { "version": "3.0.4", "resolved": "http://maven.markit.partners/artifactory/api/npm/npm_mod/minimatch/-/minimatch-3.0.4.tgz", @@ -1257,6 +1845,15 @@ "integrity": "sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=", "dev": true }, + "nopt": { + "version": "3.0.6", + "resolved": "https://registry.npmjs.org/nopt/-/nopt-3.0.6.tgz", + "integrity": "sha1-xkZdvwirzU2zWTF/eaxopkayj/k=", + "dev": true, + "requires": { + "abbrev": "1.1.1" + } + }, "normalize-package-data": { "version": "2.4.0", "resolved": "http://maven.markit.partners/artifactory/api/npm/npm_mod/normalize-package-data/-/normalize-package-data-2.4.0.tgz", @@ -1298,6 +1895,15 @@ "object-keys": "1.0.11" } }, + "on-finished": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", + "integrity": "sha1-IPEzZIGwg811M3mSoWlxqi2QaUc=", + "dev": true, + "requires": { + "ee-first": "1.1.1" + } + }, "once": { "version": "1.4.0", "resolved": "http://maven.markit.partners/artifactory/api/npm/npm_mod/once/-/once-1.4.0.tgz", @@ -1357,6 +1963,12 @@ "error-ex": "1.3.1" } }, + "parseurl": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.2.tgz", + "integrity": "sha1-/CidTtiZMRlGDBViUyYs3I3mW/M=", + "dev": true + }, "path-exists": { "version": "2.1.0", "resolved": "http://maven.markit.partners/artifactory/api/npm/npm_mod/path-exists/-/path-exists-2.1.0.tgz", @@ -1447,6 +2059,37 @@ "integrity": "sha1-4mDHj2Fhzdmw5WzD4Khd4Xx6V74=", "dev": true }, + "qs": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-5.1.0.tgz", + "integrity": "sha1-TZMuXH6kEcynajEtOaYGIA/VDNk=", + "dev": true + }, + "raw-body": { + "version": "2.1.7", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.1.7.tgz", + "integrity": "sha1-rf6s4uT7MJgFgBTQjActzFl1h3Q=", + "dev": true, + "requires": { + "bytes": "2.4.0", + "iconv-lite": "0.4.13", + "unpipe": "1.0.0" + }, + "dependencies": { + "bytes": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/bytes/-/bytes-2.4.0.tgz", + "integrity": "sha1-fZcZb51br39pNeJZhVSe3SpsIzk=", + "dev": true + }, + "iconv-lite": { + "version": "0.4.13", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.13.tgz", + "integrity": "sha1-H4irpKsLFQjoMSrMOTRfNumS4vI=", + "dev": true + } + } + }, "read-pkg": { "version": "2.0.0", "resolved": "http://maven.markit.partners/artifactory/api/npm/npm_mod/read-pkg/-/read-pkg-2.0.0.tgz", @@ -1514,6 +2157,25 @@ "resolve": "1.5.0" } }, + "redent": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/redent/-/redent-1.0.0.tgz", + "integrity": "sha1-z5Fqsf1fHxbfsggi3W7H9zDCr94=", + "dev": true, + "requires": { + "indent-string": "2.1.0", + "strip-indent": "1.0.1" + } + }, + "repeating": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/repeating/-/repeating-2.0.1.tgz", + "integrity": "sha1-UhTFOpJtNVJwdSf7q0FdvAjQbdo=", + "dev": true, + "requires": { + "is-finite": "1.0.2" + } + }, "require-uncached": { "version": "1.0.3", "resolved": "http://maven.markit.partners/artifactory/api/npm/npm_mod/require-uncached/-/require-uncached-1.0.3.tgz", @@ -1596,6 +2258,12 @@ "rechoir": "0.6.2" } }, + "signal-exit": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz", + "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=", + "dev": true + }, "slice-ansi": { "version": "0.0.4", "resolved": "http://maven.markit.partners/artifactory/api/npm/npm_mod/slice-ansi/-/slice-ansi-0.0.4.tgz", @@ -1629,6 +2297,12 @@ "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=", "dev": true }, + "statuses": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.4.0.tgz", + "integrity": "sha512-zhSCtt8v2NDrRlPQpCNtw/heZLtfUDqxBM1udqikb/Hbk52LK4nQSwr10u77iopCW5LsyHpuXS0GnEc48mLeew==", + "dev": true + }, "string-width": { "version": "1.0.2", "resolved": "http://maven.markit.partners/artifactory/api/npm/npm_mod/string-width/-/string-width-1.0.2.tgz", @@ -1664,6 +2338,15 @@ "integrity": "sha1-IzTBjpx1n3vdVv3vfprj1YjmjtM=", "dev": true }, + "strip-indent": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/strip-indent/-/strip-indent-1.0.1.tgz", + "integrity": "sha1-DHlipq3vp7vUrDZkYKY4VSrhoKI=", + "dev": true, + "requires": { + "get-stdin": "4.0.1" + } + }, "strip-json-comments": { "version": "2.0.1", "resolved": "http://maven.markit.partners/artifactory/api/npm/npm_mod/strip-json-comments/-/strip-json-comments-2.0.1.tgz", @@ -1735,6 +2418,43 @@ "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=", "dev": true }, + "tiny-lr": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/tiny-lr/-/tiny-lr-0.2.1.tgz", + "integrity": "sha1-s/26gC5dVqM8L28QeUsy5Hescp0=", + "dev": true, + "requires": { + "body-parser": "1.14.2", + "debug": "2.2.0", + "faye-websocket": "0.10.0", + "livereload-js": "2.2.2", + "parseurl": "1.3.2", + "qs": "5.1.0" + }, + "dependencies": { + "debug": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.2.0.tgz", + "integrity": "sha1-+HBX6ZWxofauaklgZkE3vFbwOdo=", + "dev": true, + "requires": { + "ms": "0.7.1" + } + }, + "ms": { + "version": "0.7.1", + "resolved": "https://registry.npmjs.org/ms/-/ms-0.7.1.tgz", + "integrity": "sha1-nNE8A62/8ltl7/3nzoZO6VIBcJg=", + "dev": true + } + } + }, + "trim-newlines": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/trim-newlines/-/trim-newlines-1.0.0.tgz", + "integrity": "sha1-WIeWa7WCpFA6QetST301ARgVphM=", + "dev": true + }, "tryit": { "version": "1.0.3", "resolved": "http://maven.markit.partners/artifactory/api/npm/npm_mod/tryit/-/tryit-1.0.3.tgz", @@ -1750,12 +2470,34 @@ "prelude-ls": "1.1.2" } }, + "type-is": { + "version": "1.6.15", + "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.15.tgz", + "integrity": "sha1-yrEPtJCeRByChC6v4a1kbIGARBA=", + "dev": true, + "requires": { + "media-typer": "0.3.0", + "mime-types": "2.1.17" + } + }, "typedarray": { "version": "0.0.6", "resolved": "http://maven.markit.partners/artifactory/api/npm/npm_mod/typedarray/-/typedarray-0.0.6.tgz", "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=", "dev": true }, + "underscore.string": { + "version": "3.2.3", + "resolved": "https://registry.npmjs.org/underscore.string/-/underscore.string-3.2.3.tgz", + "integrity": "sha1-gGmSYzZl1eX8tNsfs6hi62jp5to=", + "dev": true + }, + "unpipe": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", + "integrity": "sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw=", + "dev": true + }, "user-home": { "version": "2.0.0", "resolved": "http://maven.markit.partners/artifactory/api/npm/npm_mod/user-home/-/user-home-2.0.0.tgz", @@ -1781,6 +2523,31 @@ "spdx-expression-parse": "1.0.4" } }, + "websocket-driver": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/websocket-driver/-/websocket-driver-0.7.0.tgz", + "integrity": "sha1-DK+dLXVdk67gSdS90NP+LMoqJOs=", + "dev": true, + "requires": { + "http-parser-js": "0.4.9", + "websocket-extensions": "0.1.3" + } + }, + "websocket-extensions": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/websocket-extensions/-/websocket-extensions-0.1.3.tgz", + "integrity": "sha512-nqHUnMXmBzT0w570r2JpJxfiSD1IzoI+HGVdd3aZ0yNi3ngvQ4jv1dtHt5VGxfI2yj5yqImPhOK4vmIh2xMbGg==", + "dev": true + }, + "which": { + "version": "1.2.14", + "resolved": "https://registry.npmjs.org/which/-/which-1.2.14.tgz", + "integrity": "sha1-mofEN48D6CfOyvGs31bHNsAcFOU=", + "dev": true, + "requires": { + "isexe": "2.0.0" + } + }, "wordwrap": { "version": "1.0.0", "resolved": "http://maven.markit.partners/artifactory/api/npm/npm_mod/wordwrap/-/wordwrap-1.0.0.tgz", diff --git a/test/test.js b/test/test.js index dd1b7f7..a82850f 100644 --- a/test/test.js +++ b/test/test.js @@ -1,7 +1,7 @@ 'use strict'; -var assert = require('assert'); -var moment = require('../moment-msdate'); +const assert = require('assert'); +const moment = require('../moment-msdate'); describe('moment-msdate', () => { console.log('********************************************************'); From 3c17187b477b386187acb4e624256e0dedfd5d0a Mon Sep 17 00:00:00 2001 From: Matt Lackey Date: Tue, 21 Nov 2017 16:53:45 -0700 Subject: [PATCH 22/23] gets timezone offset to be contextual --- moment-msdate.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/moment-msdate.js b/moment-msdate.js index 55ca5d3..d57552b 100644 --- a/moment-msdate.js +++ b/moment-msdate.js @@ -57,7 +57,7 @@ const fromOADateOffsetToUtcByTimezone = function(oaDate, timezone) { if (!moment.tz.zone(timezone)) { throw new Error('timezone provided is not available in moment-timezone.js', 'moment-msdate.js', 59); } const ticks = oaDateToTicks(oaDate); - const offset = moment.tz(timezone).utcOffset() * MINUTE_MILLISECONDS; + const offset = moment(ticks).tz(timezone).utcOffset() * MINUTE_MILLISECONDS; return moment.tz(ticks - offset, timezone).utc(); }; From abce8fdf1f440c49d8c241f7bc8ffb2373a63cd4 Mon Sep 17 00:00:00 2001 From: Matt Lackey Date: Tue, 21 Nov 2017 17:10:49 -0700 Subject: [PATCH 23/23] adds test for times near DST - test left in but commented to be revisited --- test/test.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/test.js b/test/test.js index a82850f..91c025b 100644 --- a/test/test.js +++ b/test/test.js @@ -98,6 +98,15 @@ describe('moment-msdate', () => { assert.equal(moment.fromOADate(42298.6868055556, 'America/Los_Angeles').toISOString(), '2015-10-21T23:29:00.000Z'); }); + it('should handle times near DST change', () => { + assert.equal(moment.fromOADate(43044, 'America/Denver').toISOString(), '2017-11-05T06:00:00.000Z'); + assert.equal(moment.fromOADate(43044.25, 'America/Denver').toISOString(), '2017-11-05T12:00:00.000Z'); + assert.equal(moment.fromOADate(43044.15, 'America/Denver').toISOString(), '2017-11-05T09:36:00.000Z'); + assert.equal(moment.fromOADate(43044.18, 'America/Denver').toISOString(), '2017-11-05T10:19:12.000Z'); + // Fails - it seems our offset is too close to the DST change + // assert.equal(moment.fromOADate(43044.105, 'America/Denver').toISOString(), '2017-11-05T07:31:12.000Z'); + }); + it('should have a timezone of utc', () => { const myMoment = moment.fromOADate(42298.6868055556, 'America/New_York'); assert.ok(myMoment.isUtc());