Hey! What do people in general consider the best ...
# suitescript
n
Hey! What do people in general consider the best way of handling timezone issues in Suitescripts? I mean handling the issue of the server always using server time and you needing it in a specific timezone. Do you guys find the N/format API to be good enough with the .parse method? Or do you use third party libraries? I don't wanna use Moment as it's not gonna be updated anymore, looked a bit at Luxon but it handles timezones through IANA timezones which it seems in the NS environment we can't use. Just using offset from UTC or whatever the server is in doesn't feel very safe with DST in our region..
c
It depends a little on what I'm trying to do. I'm happy to stick with moment.js for date manipulation etc but if you're just looking to parse/present dates, etc then N/format is OK, coupled with its timezone options and grabbing the user's timezone preference.
Any specific use case you're looking at?
n
@Chris Abbott Cool, thanks for the input! My use case right now is I get a timestamp in (i.e. 2020-09-22T140316.0000000Z) and I need it formated in a specific way, but to do that I need it to be a JS Date object, but when I do "new Date('2020-09-22T140316.0000000Z') it's server time (PDT?), I need to get it in CET time. and it seems I can do what I need with N/format and Luxon but not sure if it's the optimal approach, maybe it is? So would you usually grab the users TZ prefs and use that in your calculation?
c
With new Date('2020-09-22T140316.0000000Z') the underlying time should be correct. It might look different if you log it but the underlying object should be right.
How are you outputting it?
n
Never mind my bad.. it's correct, it's in UTC and when I format it with the timezone EUROPE_AMSTERDAM it's correct 🙂
But in what scenarios would you use the users TZ prefs? Asking out of curiosity
c
The most common scenario is parsing/setting data from/in the UI.
Only really comes into play with a Date/Time field though.
n
Ah ok cool, thanks for the help!
y
I will suggest to use moment time zone! This way is easier to work with it 😄!
👍 1
n
@Yeison thanks 🙂 I am right now but since they've stoped the development of moment I don't wanna use it in new projects if I don't absolutely have to.. 😕