Author Topic: Composer: fromISOString / toISOString  (Read 2679 times)

Offline cavagnaro

  • Administrator
  • Hero Member
  • *****
  • Posts: 7623
  • Karma: 56330
Composer: fromISOString / toISOString
« on: November 21, 2020, 10:02:36 AM »
Hi guys
Any of you have a sample on how to use these functions and which format do they support?
I am having problems trying to use them with the format 20201120T204713 for example-


Thanks

Offline gen_rtfm

  • Full Member
  • ***
  • Posts: 114
  • Karma: 4
Re: Composer: fromISOString / toISOString
« Reply #1 on: November 21, 2020, 04:40:38 PM »
Hi,

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString

describes the iso 8601 format, looking at that it seems the interpreter expects ':' separating hour, minute, second and '.' separating second and millisecond, and a 'z' as last character.

Based on that I think you have to preprocess your datetime-string if you want to use those functions.

Br

Skickat från min Mi MIX 3 5G via Tapatalk


Offline cavagnaro

  • Administrator
  • Hero Member
  • *****
  • Posts: 7623
  • Karma: 56330
Re: Composer: fromISOString / toISOString
« Reply #2 on: November 22, 2020, 08:17:49 AM »
Hi was able to make it work


String format from customer has to be strictly YYYY-MM-DDTHH:MM:SS.sssZ


Customer was just sending  YYYY-MM-DDTHH:MM:SS


Added ".sssZ"


and then did a     var datef = Date.fromISOString(f);


Now it is a valid Date object


Thanks

Offline cavagnaro

  • Administrator
  • Hero Member
  • *****
  • Posts: 7623
  • Karma: 56330
Re: Composer: fromISOString / toISOString
« Reply #3 on: November 23, 2020, 11:23:27 PM »
Ok an issue with this is that it return the date in GMT zone and the TZ in another field...
So...just another complication.
Will do as a JSP file better...just to consider if someone decides to use this...

Offline gen_rtfm

  • Full Member
  • ***
  • Posts: 114
  • Karma: 4
Re: Composer: fromISOString / toISOString
« Reply #4 on: November 24, 2020, 03:37:42 AM »
If you always deal with a timezone with a fixed offset from gmt you should be able to change .000Z to .000+02:00 (to offset utc by two hours).

I haven't tried it in composer but if the js-function conforms to iso standard it should be able to handle that format.

You say that timezone is in a different field, maybe you can have an object to select "suffix" based on the contents in that field prior to adding that to the given datestring to produce a valid datetime?

Jsp is of course another way to achieve the same thing.

Skickat från min Mi MIX 3 5G via Tapatalk


Offline cavagnaro

  • Administrator
  • Hero Member
  • *****
  • Posts: 7623
  • Karma: 56330
Re: Composer: fromISOString / toISOString
« Reply #5 on: November 24, 2020, 05:52:26 AM »
I see, will try it anyways to have it documented
Thanks!