I have issues with time zones, I think...
# suitescript
m
I have issues with time zones, I think...
I have a record that comes from the NWS weather API. The lat and long of this weather can be anywhere in the US and the timezone is shown on the response as a string. i.e. "America/New_York". How do ensure that the time shown on my record is same string time listed without conversion?
So if a weather event were to happen at 5 AM in New York (keeping with my example) I want the record to show 5 AM but when saving the time I believe it's being converted to 5 AM PST (server time) or possibly 5 AM MST (client time) depending on if I'm running the code as a test or not.
b
In general, convert the date time you get from the api to a Date
And use the Date to set fields
Netsuite will set the field using the timezone from the current user
✔️ 1
m
yeah I guess that's the part I'm worried about, is how it's eventually displayed. I'm leaning toward setting the value as a string instead of a date
it comes in looking something like "2019-11-12T060000-05:00" So I want my record to show that the timezone is "America/New_York" and then "11-12-2019 6:00 AM" in a readable format.
b
My advice is to use moment timezone here
Netsuite doesn't have a built in mechanism to turn "2019-11-12T060000-05:00" into a Date
And it will suck to convert that string into netsuite's date time string format if you have to handle multiple time zones
m
I do have to handle at least all US timezones (including HI and AK)
so far I've been using a Zigman style parseISO function function parseISOString(s){ var b = s.split(/\D+/); return new Date(Date.UTC(b[0], --b[1], b[2], b[3], b[4], b[5], b[6])); } along with the native nlapi function var str_date_example = nlapiDateToString(parseISOString(forecast_period.exampleTime), 'datetimetz');
the problem is I'm not sure that's working how I thought it was working when I set it up
b
That looks to only work for date time strings in utc