-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #170 from RobD-tech/fix/result-type-unix-timestamp…
…-TECHSUP-9272 fix: add switch case for unix timestamp format TECHSUP-9272
- Loading branch information
Showing
4 changed files
with
466 additions
and
1 deletion.
There are no files selected for viewing
241 changes: 241 additions & 0 deletions
241
__tests__/date-time-offset/1.2/date-time-offset.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,241 @@ | ||
import { addMinutes } from 'date-fns'; | ||
import dateTimeOffset from '../../../functions/date-time-offset/1.2'; | ||
|
||
describe('Date Time Offset', () => { | ||
test('return date time for 1 second added to a new javascript date for UTC+1 zone', async () => { | ||
const testData = { | ||
businessDays: false, | ||
currentDate: true, | ||
customStartDate: null, | ||
offsetType: 'ss', | ||
offset: '1', | ||
resultType: 'DT', | ||
timeZoneOffset: '60', | ||
}; | ||
const { result } = await dateTimeOffset(testData); | ||
|
||
const dateDiff = | ||
new Date(result) - | ||
addMinutes(new Date(), parseInt(testData.timeZoneOffset, 10)); | ||
expect(dateDiff).toBeLessThan(1000); | ||
expect(dateDiff).toBeGreaterThan(0); | ||
}); | ||
|
||
test('return date time for 1 second added to a new javascript date for UTC-6 zone', async () => { | ||
const testData = { | ||
businessDays: false, | ||
currentDate: true, | ||
customStartDate: null, | ||
offsetType: 'ss', | ||
offset: '1', | ||
resultType: 'DT', | ||
timeZoneOffset: '-360', | ||
}; | ||
const checkDate = addMinutes( | ||
new Date(), | ||
parseInt(testData.timeZoneOffset, 10), | ||
); | ||
const { result } = await dateTimeOffset(testData); | ||
const dateDiff = new Date(result) - checkDate; | ||
expect(dateDiff).toBeLessThan(1000); | ||
expect(dateDiff).toBeGreaterThan(0); | ||
}); | ||
|
||
test('return time for 1 second added to 2022-01-01 00:00:00 for UTC+1 zone', async () => { | ||
const testData = { | ||
businessDays: false, | ||
currentDate: false, | ||
customStartDate: '2022-01-01 00:00:00', | ||
offsetType: 'ss', | ||
offset: '1', | ||
resultType: 'T', | ||
timeZoneOffset: '60', | ||
}; | ||
|
||
const { result } = await dateTimeOffset(testData); | ||
expect(result).toMatch('00:00:01'); | ||
}); | ||
|
||
test('return date time for 1 second added to 2022-01-01 00:00:00 for UTC+1 zone', async () => { | ||
const testData = { | ||
businessDays: false, | ||
currentDate: false, | ||
customStartDate: '2022-01-01 00:00:00', | ||
offsetType: 'ss', | ||
offset: '1', | ||
resultType: 'DT', | ||
timeZoneOffset: '60', | ||
}; | ||
const { result } = await dateTimeOffset(testData); | ||
expect(result).toMatch('2022-01-01 00:00:01'); | ||
}); | ||
|
||
test('return time for 2 minutes added to 2022-01-01 00:00:00 for UTC+1 zone', async () => { | ||
const testData = { | ||
businessDays: false, | ||
currentDate: false, | ||
customStartDate: '2022-01-01 00:00:00', | ||
offsetType: 'mm', | ||
offset: '2', | ||
resultType: 'T', | ||
timeZoneOffset: '60', | ||
}; | ||
const { result } = await dateTimeOffset(testData); | ||
expect(result).toMatch('00:02:00'); | ||
}); | ||
|
||
test('return time for 1 hour added to 2022-01-01 00:00:00 for UTC+1 zone', async () => { | ||
const testData = { | ||
businessDays: false, | ||
currentDate: false, | ||
customStartDate: '2022-01-01 00:00:00', | ||
offsetType: 'hh', | ||
offset: '1', | ||
resultType: 'T', | ||
timeZoneOffset: '60', | ||
}; | ||
const { result } = await dateTimeOffset(testData); | ||
expect(result).toMatch('01:00:00'); | ||
}); | ||
|
||
test('return date for 1 day added to 2022-01-01 00:00:00 for UTC+1 zone', async () => { | ||
const testData = { | ||
businessDays: false, | ||
currentDate: false, | ||
customStartDate: '2022-01-01 00:00:00', | ||
offsetType: 'DD', | ||
offset: '1', | ||
resultType: 'DT', | ||
timeZoneOffset: '60', | ||
}; | ||
const { result } = await dateTimeOffset(testData); | ||
expect(result).toMatch('2022-01-02 00:00:00'); | ||
}); | ||
|
||
test('return date for 1 business day added to 2022-01-01 00:00:00 for UTC+1 zone', async () => { | ||
const testData = { | ||
businessDays: true, | ||
currentDate: false, | ||
customStartDate: '2022-01-01 00:00:00', | ||
offsetType: 'DD', | ||
offset: '1', | ||
resultType: 'DT', | ||
timeZoneOffset: '60', | ||
}; | ||
const { result } = await dateTimeOffset(testData); | ||
expect(result).toMatch('2022-01-03 00:00:00'); | ||
}); | ||
|
||
test('return date for 1 week added to 2022-01-01 01:00:00 for UTC+1 zone', async () => { | ||
const testData = { | ||
businessDays: false, | ||
currentDate: false, | ||
customStartDate: '2022-01-01 01:00:00', | ||
offsetType: 'WW', | ||
offset: '1', | ||
resultType: 'D', | ||
timeZoneOffset: '60', | ||
}; | ||
const { result } = await dateTimeOffset(testData); | ||
expect(result).toMatch('2022-01-08'); | ||
}); | ||
|
||
test('return date time for 1 month added to 2022-01-01 00:00:00 for UTC+1 zone', async () => { | ||
const testData = { | ||
businessDays: false, | ||
currentDate: false, | ||
customStartDate: '2022-01-01 00:00:00', | ||
offsetType: 'MM', | ||
offset: '1', | ||
resultType: 'DT', | ||
timeZoneOffset: '60', | ||
}; | ||
const { result } = await dateTimeOffset(testData); | ||
expect(result).toMatch('2022-02-01 00:00:00'); | ||
}); | ||
|
||
test('return date time for 1 year added to 2022-01-01 00:00:00 for UTC+1 zone', async () => { | ||
const testData = { | ||
businessDays: false, | ||
currentDate: false, | ||
customStartDate: '2022-01-01 00:00:00', | ||
offsetType: 'YYYY', | ||
offset: '1', | ||
resultType: 'DT', | ||
timeZoneOffset: '60', | ||
}; | ||
const { result } = await dateTimeOffset(testData); | ||
expect(result).toMatch('2023-01-01 00:00:00'); | ||
}); | ||
|
||
test('return unix timestamp for 1 second added to 2022-01-01 00:00:00 for UTC+1 zone', async () => { | ||
const testData = { | ||
businessDays: false, | ||
currentDate: false, | ||
customStartDate: '2022-01-01T00:00:00Z', | ||
offsetType: 'ss', | ||
offset: '1', | ||
resultType: 'UT', | ||
timeZoneOffset: '60', | ||
}; | ||
|
||
const { result } = await dateTimeOffset(testData); | ||
expect(result).toBe(1640995201); | ||
}); | ||
|
||
test('return invalid offset type', async () => { | ||
const testData = { | ||
businessDays: false, | ||
currentDate: false, | ||
customStartDate: '2022-01-01 00:00:00', | ||
offsetType: 'INCORRECT', | ||
offset: '1', | ||
resultType: 'DT', | ||
timeZoneOffset: '60', | ||
}; | ||
const { result } = await dateTimeOffset(testData); | ||
expect(result).toMatch('Incorrect offset type'); | ||
}); | ||
|
||
test('return invalid result type', async () => { | ||
const testData = { | ||
businessDays: false, | ||
currentDate: false, | ||
customStartDate: '2022-01-01 00:00:00', | ||
offsetType: 'MM', | ||
offset: '1', | ||
resultType: 'INCORRECT', | ||
timeZoneOffset: '60', | ||
}; | ||
const { result } = await dateTimeOffset(testData); | ||
expect(result).toMatch('Incorrect formatting type'); | ||
}); | ||
|
||
test('return invalid date, based on custom incorrect date', async () => { | ||
const testData = { | ||
businessDays: false, | ||
currentDate: false, | ||
customStartDate: '2023-31-31 00:00:00', | ||
offsetType: 'MM', | ||
offset: '1', | ||
resultType: 'D', | ||
timeZoneOffset: '60', | ||
}; | ||
const { result } = await dateTimeOffset(testData); | ||
expect(result).toMatch('Invalid Date'); | ||
}); | ||
|
||
test('return invalid date, based on NO data', async () => { | ||
const testData = { | ||
businessDays: false, | ||
currentDate: null, | ||
customStartDate: null, | ||
offsetType: null, | ||
offset: null, | ||
resultType: null, | ||
timeZoneOffset: null, | ||
}; | ||
const { result } = await dateTimeOffset(testData); | ||
expect(result).toMatch('Invalid Date'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"dependencies": ["date-fns"], | ||
"functions": ["dateTimeOffset 1.1"], | ||
"functions": ["dateTimeOffset 1.2"], | ||
"includes": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
{ | ||
"description": "Calculate a date, time or date with time based on a provided date in text (YYYY-MM-DD hh:mm:ss) or the current date", | ||
"label": "Date/Time Offset", | ||
"category": "Misc", | ||
"icon": { | ||
"name": "DateTimeIcon", | ||
"color": "Yellow" | ||
}, | ||
"options": [ | ||
{ | ||
"name": "customStartDate", | ||
"label": "Specify your date in YYYY-MM-DD hh:mm:ss notation", | ||
"meta": { | ||
"type": "Text" | ||
} | ||
}, | ||
{ | ||
"name": "currentDate", | ||
"label": "OR use the current date/time ", | ||
"meta": { | ||
"type": "Boolean" | ||
} | ||
}, | ||
{ | ||
"name": "businessDays", | ||
"label": "Business days only", | ||
"meta": { | ||
"type": "Boolean" | ||
}, | ||
"info": "If checked, the calculation will skip weekends (Saturday and Sunday) and will only count working days (Monday to Friday). This option only works in combination with offset type \"Days\"." | ||
}, | ||
{ | ||
"name": "offsetType", | ||
"label": "Offset Type", | ||
"meta": { | ||
"type": "Select", | ||
"validations": { | ||
"required": true | ||
}, | ||
"values": [ | ||
{ "label": "Seconds", "value": "ss" }, | ||
{ "label": "Minutes", "value": "mm" }, | ||
{ "label": "Hours", "value": "hh" }, | ||
{ "label": "Days", "value": "DD" }, | ||
{ "label": "Weeks", "value": "WW" }, | ||
{ "label": "Months", "value": "MM" }, | ||
{ "label": "Years", "value": "YYYY" } | ||
] | ||
} | ||
}, | ||
{ | ||
"name": "offset", | ||
"label": "offset", | ||
"meta": { | ||
"type": "Number", | ||
"validations": { | ||
"required": true | ||
} | ||
} | ||
}, | ||
{ | ||
"name": "resultType", | ||
"label": "Result type", | ||
"meta": { | ||
"type": "Select", | ||
"validations": { | ||
"required": true | ||
}, | ||
"values": [ | ||
{ "label": "Date", "value": "D" }, | ||
{ "label": "Date Time", "value": "DT" }, | ||
{ "label": "Time", "value": "T" }, | ||
{ "label": "Unix Timestamp (epoch)", "value": "UT" } | ||
] | ||
} | ||
}, | ||
{ | ||
"name": "timeZoneOffset", | ||
"label": "UTC timezone offset for your zone (i.e. NL3 = UTC+1, USA2 = UTC-6)", | ||
"meta": { | ||
"type": "Select", | ||
"validations": { | ||
"required": true | ||
}, | ||
"values": [ | ||
{ "label": "UTC-8", "value": "-480" }, | ||
{ "label": "UTC-7", "value": "-420" }, | ||
{ "label": "UTC-6", "value": "-360" }, | ||
{ "label": "UTC-5", "value": "-300" }, | ||
{ "label": "UTC-4", "value": "-240" }, | ||
{ "label": "UTC-3", "value": "-180" }, | ||
{ "label": "UTC-2", "value": "-120" }, | ||
{ "label": "UTC-1", "value": "-60" }, | ||
{ "label": "UTC", "value": "0" }, | ||
{ "label": "UTC+1", "value": "60" }, | ||
{ "label": "UTC+2", "value": "120" }, | ||
{ "label": "UTC+3", "value": "180" }, | ||
{ "label": "UTC+4", "value": "240" }, | ||
{ "label": "UTC+5", "value": "300" }, | ||
{ "label": "UTC+6", "value": "360" }, | ||
{ "label": "UTC+7", "value": "420" }, | ||
{ "label": "UTC+8", "value": "480" } | ||
] | ||
} | ||
}, | ||
{ | ||
"name": "result", | ||
"label": "Result", | ||
"meta": { | ||
"type": "Output", | ||
"validations": { | ||
"required": true | ||
}, | ||
"output": { | ||
"anyOf": [ | ||
{ | ||
"type": "Text" | ||
}, | ||
{ | ||
"type": "Number" | ||
} | ||
] | ||
} | ||
} | ||
} | ||
], | ||
"yields": "NONE" | ||
} |
Oops, something went wrong.