Not able to convert timezone using dayjs in integrator.io (Celigo)
Whenever I try to use dayjs in order to convert from a particular timezone to UTC, the following errors are happening:
- I am getting `Intl is not defined` when using it as
`dayjs.tz('2021-01-01, 'America/Los_Angeles').format()` - Getting the time in UTC instead of PST when using it as
`dayjs('2021-01-01').tz('America/Los_Angeles').format()`
// output: 2021-01-01T00:00:00Z - Getting the time in UTC instead of PST when using it as
`dayjs.tz.setDefault('America/Los_Angeles');`
`dayjs.tz('2021-01-01')`
// output: Error as point 1.
`dayjs('2021-01-01')`
// output: 2021-01-01T00:00:00Z
* All the required extensions are imported as per the document
The js runtime in integrator.io(Celigo) seems to be missing ECMAScript Internationalization API (Intl) and the issue mentioned in the second point seems to be fixed in the higher version of `dayjs`: https://github.com/iamkun/dayjs/issues/1827#issuecomment-1222036877
Any thoughts on how to get this done?
0
Comments
Junction Team it's currently not possible to use the timezone conversions with dayjs because the Internationalization API isn't available within the script environment. It's on the roadmap to add in, but for now the best way to convert datetimes is to use handlebar expressions when you map your data. https://docs.celigo.com/hc/en-us/articles/360039326071-Handlebars-helper-reference#dateFormat
Hi Tyler Lamparter. Thank you for your prompt response.
We looked into the `dateFormat` handler. I see that we can convert a UTC time to any other timezone but, my use case right now is that I have a timestamp in PST (America/Los_Angeles) and I want to convert it to UTC.
Is this possible using such handlers without manually specifying the offset?
I cannot use the offset addition because of Daylight-Savings (DST) which will alter the offset of Pacific time by 1 hour. Any suggestions on how I can handle DST and also achieve this?
Junction Team couple questions while I try to figure something out here.
If your source is exporting from NetSuite, then you could have NetSuite do the conversion. On your saved search, you would have a text formula like this:
A possible solution using a handlebar expression would be the following:
The above will take the value of the pstDate object, convert it to an ISO8601 Format, then add 25200000 milliseconds, which accounts for a 7 hour offset.
Below is an example of this in action:
Best Regards,
Dan
Hi Dan Claypool. Thank you for your comment.
Currently, we are using it in a similar way, however, we don't want to add/subtract the timezone offset because it changes during daylight savings. So we were looking to see if there was a more dynamic approach to it.
Hi Tyler Lamparter thank you for the mentioned approaches.
Source System: Netsuite.
Target System: PostGreSQL DB
Format: '06/12/2023 11:22 am' (MM/DD/YYYY HH:mm a').
NOTE:
Ultimately, we would prefer the `dayjs` library to assist us in the conversion of time-zones but for now we are planning to opt for a different solution on the target side.
'Update tester set "updated_at = '2023-11-05T03:01:00.000Z'::timestamp at time zone 'America/Los_Angeles' where test_id = 5;
Junction Team that's why I was curious what your source system was. Glad to see you ended up figuring it out! We have enhancements for dayjs on the roadmap and hopefully we can get that resolved so you can do this directly in javascript.
Please sign in to leave a comment.