diff --git a/src/types/date-time.ts b/src/types/date-time.ts index 0811ce8..3a6759f 100644 --- a/src/types/date-time.ts +++ b/src/types/date-time.ts @@ -10,10 +10,13 @@ export const types = { }; export const fetchProcessing = (data: any) => { - if (data == null || data instanceof Date) { + if (data == null) { return data; } - return new Date(data); + if (!(data instanceof Date)) { + data = new Date(data); + } + return data.toISOString(); }; export const nativeFactTypes = { diff --git a/src/types/date.ts b/src/types/date.ts index 60c5757..95c04f5 100644 --- a/src/types/date.ts +++ b/src/types/date.ts @@ -10,10 +10,13 @@ export const types = { }; export const fetchProcessing = (data: any) => { - if (data == null || data instanceof Date) { + if (data == null) { return data; } - return new Date(data); + if (!(data instanceof Date)) { + data = new Date(data); + } + return data.toISOString(); }; export const nativeFactTypes = { diff --git a/src/types/time.ts b/src/types/time.ts index 3b54873..1dba8fc 100644 --- a/src/types/time.ts +++ b/src/types/time.ts @@ -12,7 +12,7 @@ export const types = { export const fetchProcessing = (data: any) => { if (data != null) { // We append the date of the epoch so that we can parse this as a valid date. - return new Date('Thu, 01 Jan 1970 ' + data); + return new Date('Thu, 01 Jan 1970 ' + data).toISOString(); } return data; }; diff --git a/test/Date Time.js b/test/Date Time.js index 67d6e6f..c46ead1 100644 --- a/test/Date Time.js +++ b/test/Date Time.js @@ -3,9 +3,9 @@ import * as helpers from './helpers'; helpers.describe('Date Time', function (test) { const now = new Date(); describe('fetchProcessing', function () { - test.fetch(now, now); - test.fetch(now.toString(), now); - test.fetch(now.getTime(), now); + test.fetch(now, now.toISOString()); + test.fetch(now.toString(), new Date(now.toString()).toISOString()); + test.fetch(now.getTime(), new Date(now.getTime()).toISOString()); test.fetch(null, null); }); diff --git a/test/Date.js b/test/Date.js index ec2ae1d..638fbae 100644 --- a/test/Date.js +++ b/test/Date.js @@ -3,9 +3,9 @@ import * as helpers from './helpers'; helpers.describe('Date', function (test) { const now = new Date(); describe('fetchProcessing', function () { - test.fetch(now, now); - test.fetch(now.toString(), now); - test.fetch(now.getTime(), now); + test.fetch(now, now.toISOString()); + test.fetch(now.toString(), new Date(now.toString()).toISOString()); + test.fetch(now.getTime(), new Date(now.getTime()).toISOString()); test.fetch(null, null); }); diff --git a/test/Time.js b/test/Time.js index 7092344..623b8bf 100644 --- a/test/Time.js +++ b/test/Time.js @@ -6,7 +6,10 @@ helpers.describe('Time', function (test) { now.setMonth(0); now.setDate(1); describe('fetchProcessing', function () { - test.fetch(now.toTimeString(), now); + test.fetch( + now.toTimeString(), + new Date('Thu, 01 Jan 1970 ' + now.toTimeString()).toISOString(), + ); test.fetch(null, null); });