Ok I have a strange error. netsuite is passing me ...
# suitescript
f
Ok I have a strange error. netsuite is passing me a datetime string like this:
2020-03-27T14:42:34
which seem to be in the the users timezone. How can I convert that to an isoString? Passing it to
new Date("2020-03-27T14:42:34")
fails on the server saying its an invalid date. Using format.parse and type
DATETIME
and then call
.toIsoString()
says that I can’t call method
toIsoString
on an object
b
where are you getting that string from?
f
Netsuite API (implementing a plugin)
b
thats not one of the date/time formats netsuite uses
usually they match the current user's date/time format
what you have is almost ISO-8601, but is missing the timezone information
if the timezone is GMT, then you can use new Date("2020-03-27T144234.000Z")
f
Yeah
unfortently its not GMT
its there new Financial Institution Connection plugin
not sure why they did that
this is the error
Copy code
Cannot find function toISOString in object 2020-03-27T15:01:17."
b
are you sure 2020-03-27T150117 is a string?
what is the value of Object.prototype.toString.call on your value
f
The issue is triggered by this line:
Copy code
format.parse({ value: fromDateTime, type: format.Type.DATETIMETZ}).toISOString()
b
2020-03-27T150117 is not in any of netsuite's supported DATETIMETZ formats
f
and
typeof fromDateTime
is a string
b
a flaw of format.parse is that if the input doesnt match the type, it returns the input value
f
Ok so my problem is Netsuite gives me an unsupported date time string that is not timezoned but is given in the companies timezone
is there an easy way for me to get the current timezone and just append that timezone modifier? Or any other way how I can get that date string to a JS Date object?
b
https://momentjs.com/timezone/ is what i would grab
use User.getPreference to get the value of the 'TIMEZONE' preference
i would not describe this as easy
If you are sure you will only deal with one timezone, you could consider using new Date with the .000Z added and fix the offset
its a little too hacky for my taste
f
yeah thats pretty hacky and we deal with financial transactions so not a good idea
I just don’t understand why
new Date("2020-03-27T14:42:34")
is not working. Normal JS engines can process it…
b
Rhino is old
f
Even strings like this:
Copy code
2020-03-27T15:44:35-0700
b
ive only found the iso 8601 strings that include the zero offset and milliseconds to be useful and working
there is also the format that Date.toString uses, but ive yet to find anything that uses that
f
ok going todo it oldschool. Use a regex to parse the date and then manual populate the date and time in a date object