Skip to content

Commit

Permalink
Return ISODateString instead of date
Browse files Browse the repository at this point in the history
Change-type: major
Signed-off-by: fisehara <[email protected]>
  • Loading branch information
fisehara committed Feb 26, 2024
1 parent 5478179 commit 9b447bc
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
7 changes: 5 additions & 2 deletions src/types/date-time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
return data.toISOString();
}
return new Date(data).toISOString();
};

export const nativeFactTypes = {
Expand Down
7 changes: 5 additions & 2 deletions src/types/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
return data.toISOString();
}
return new Date(data).toISOString();
};

export const nativeFactTypes = {
Expand Down
6 changes: 3 additions & 3 deletions test/Date Time.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down
6 changes: 3 additions & 3 deletions test/Date.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down

0 comments on commit 9b447bc

Please sign in to comment.