Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return ISODateString instead of date #91

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)) {
data = new Date(data);
}
return 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)) {
data = new Date(data);
}
return data.toISOString();
};

export const nativeFactTypes = {
Expand Down
2 changes: 1 addition & 1 deletion src/types/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
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
5 changes: 4 additions & 1 deletion test/Time.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down
Loading