| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const Datelib = require("../datelib"); | ||
| test('it formats time in hours', () => { | ||
| const date = new Date().toISOString(); | ||
| expect(Datelib.formatTime(date).length).toEqual(5); | ||
| }); | ||
| test('it converts from utc to bst and back', () => { | ||
| const date = new Date().toISOString(); | ||
| const utc = Datelib.toUtc(date); | ||
| const bst = Datelib.fromUtc(utc); | ||
| const newUtc = Datelib.toUtc(bst); | ||
| expect(utc).toEqual(newUtc); | ||
| }); | ||
| //# sourceMappingURL=datelib.spec.js.map |
| {"version":3,"file":"datelib.spec.js","sourceRoot":"","sources":["../../test/datelib.spec.ts"],"names":[],"mappings":";;AAAA,sCAAqC;AAErC,IAAI,CAAC,0BAA0B,EAAE;IAC7B,MAAM,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAA;IAErC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;AAEtD,CAAC,CAAC,CAAA;AAGF,IAAI,CAAC,sCAAsC,EAAE;IACzC,MAAM,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAA;IAErC,MAAM,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAE/B,MAAM,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;IAEhC,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAGjC,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;AAC/B,CAAC,CAAC,CAAA"} |
+5
-7
@@ -9,3 +9,3 @@ import * as moment from 'moment' | ||
| // Createing a moment from a date object because we know that the format | ||
| // Creating a moment from a date object because we know that the format | ||
| // of our date is an iso 8601 string. This is much faster than having | ||
@@ -36,8 +36,6 @@ // moment parse the string itself | ||
| export const toUtc = (val: string) => { | ||
| return moment.utc(new Date(val)).format() | ||
| } | ||
| export const toUtc = (val: string) => | ||
| moment.utc(new Date(val)).format() | ||
| // as far as I can tell this method is inferior to the one above | ||
| // export const withUtcOffset = (val: string) => | ||
| // moment(val).add(utcOffset() * -1, 'minutes').format() | ||
| export const fromUtc = (val: string) => | ||
| moment(new Date(val)).local().format() |
+2
-9
@@ -7,5 +7,2 @@ "use strict"; | ||
| exports.utcOffset = () => moment.parseZone(new Date()).utcOffset(); | ||
| // Createing a moment from a date object because we know that the format | ||
| // of our date is an iso 8601 string. This is much faster than having | ||
| // moment parse the string itself | ||
| const toMoment = (val) => moment(new Date(val)); | ||
@@ -19,8 +16,4 @@ exports.format = (val, fmt) => toMoment(val).format(fmt); | ||
| exports.diffNow = (val) => toMoment(val).diff(moment(new Date())); | ||
| exports.toUtc = (val) => { | ||
| return moment.utc(new Date(val)).format(); | ||
| }; | ||
| // as far as I can tell this method is inferior to the one above | ||
| // export const withUtcOffset = (val: string) => | ||
| // moment(val).add(utcOffset() * -1, 'minutes').format() | ||
| exports.toUtc = (val) => moment.utc(new Date(val)).format(); | ||
| exports.fromUtc = (val) => moment(new Date(val)).local().format(); | ||
| //# sourceMappingURL=datelib.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"datelib.js","sourceRoot":"","sources":["../datelib.ts"],"names":[],"mappings":";;AAAA,iCAAgC;AAEnB,QAAA,kBAAkB,GAAW,SAAS,CAAA;AACtC,QAAA,kBAAkB,GAAW,OAAO,CAAA;AAEpC,QAAA,SAAS,GAAG,MACrB,MAAM,CAAC,SAAS,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,SAAS,EAAE,CAAA;AAE5C,wEAAwE;AACxE,qEAAqE;AACrE,iCAAiC;AACjC,MAAM,QAAQ,GAAG,CAAC,GAAW,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,CAAA;AAE1C,QAAA,MAAM,GAAG,CAAC,GAAW,E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": "ts-datelib", | ||
| "version": "1.0.0", | ||
| "version": "1.0.1", | ||
| "description": "Typescript date formatting", | ||
@@ -5,0 +5,0 @@ "main": "dist/datelib.js", |
+15
-2
| import * as Datelib from '../datelib' | ||
| test('it formats time in hours', () => { | ||
| const date = new Date().toISOString() | ||
| const date = new Date().toISOString() | ||
| console.log('date is', date) | ||
| expect(Datelib.formatTime(date).length).toEqual(5) | ||
| }) | ||
| test('it converts from utc to bst and back', () => { | ||
| const date = new Date().toISOString() | ||
| const utc = Datelib.toUtc(date) | ||
| //console.log('utc is', utc) | ||
| const bst = Datelib.fromUtc(utc) | ||
| //console.log('bst is', bst) | ||
| const newUtc = Datelib.toUtc(bst) | ||
| //console.log('newUtc is', newUtc) | ||
| expect(utc).toEqual(newUtc) | ||
| }) |
7303
18.19%12
20%78
21.88%