Skip to content

Commit

Permalink
Merge pull request #91 from balena-io-modules/fisehara/return-iso_dat…
Browse files Browse the repository at this point in the history
…e_string

Return `ISODateString` instead of `date`
  • Loading branch information
flowzone-app[bot] authored Mar 4, 2024
2 parents 5478179 + 37e2d44 commit 1d054fe
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 12 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)) {
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

0 comments on commit 1d054fe

Please sign in to comment.