Comparing version
@@ -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() |
@@ -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 |
{ | ||
"name": "ts-datelib", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Typescript date formatting", | ||
@@ -5,0 +5,0 @@ "main": "dist/datelib.js", |
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) | ||
}) |
Sorry, the diff of this file is not supported yet
7303
18.19%12
20%78
21.88%