Page 1 of 1
Working with ISO 8601 Date format
Posted: Mon Oct 28, 2024 11:06 pm
by andyh1234
Hi,
Is there an easy way yo work with the ISO 8601 date format.
The date is written as
2024-10-27T01:30:00Z or
2024-10-27T01:30:00+01:00
Where the date and time are separated by a letter T.
I am currently parsing the date into a comma separated string as used by the dateItems command, but am struggling with the UTC part, it is either Z for zulu (do nothing) or + or - a value for daylight savings time. I convert my string into the internet date format but it is adding an hour onto it before I even try to parse the UTC part at the end.
I would just like to convert it into seconds so I can work with it, and am getting the right time.
Re: Working with ISO 8601 Date format
Posted: Tue Oct 29, 2024 5:46 pm
by jacque
The trailing number isn't daylight savings, it's the time zone. In the central US where I am, we're currently at - 5. When we go back to standard time we'll be at - 6. So if you want to translate my current time to universal time, add the last number to the hours in the date calculation.
Re: Working with ISO 8601 Date format
Posted: Tue Oct 29, 2024 6:42 pm
by dunbarx
What Jacque said.
Know that the "Z" is "Zulu", or Universal Time Coordinated (UTC) It is what used to be called GMT, Greenwich Mean Time. It would essentially be "+0"
Craig
Re: Working with ISO 8601 Date format
Posted: Wed Oct 30, 2024 11:34 am
by richmond62
-
Rude, Crude, and Competent.
Code: Select all
on mouseUp
ask "Enter a date in ISO 8601 format"
put it into FULLD
set the itemDelimiter to "T"
put item 1 of FULLD into FIRSTD
put item 2 of FULLD into SECONDD
set the itemdelimiter to "-"
put item 1 of FIRSTD into YEARX
put item 2 of FIRSTD into MONTHX
put item 3 of FIRSTD into DAYX
put "US" && MONTHX & "/" & DAYX & "/" & YEARX into fld "USD"
put "GB" && DAYX & "/" & MONTHX & "/" & YEARX into fld "GBD"
if SECONDD contains "Z" then
set the itemDelimiter to "Z"
else
set the itemDelimiter to "+"
end if
put "LOCAL:" && item 1 of SECONDD into fld "LT"
if item 2 of SECONDD is not empty then
put item 2 of SECONDD into ZONE
put item 1 of SECONDD into HOMEX
set the itemDelimiter to ":"
put item 1 of ZONE into HOURY
put item 2 of ZONE into MINY
put item 1 of HOMEX into HOURX
put item 2 of HOMEX into MINX
put (HOURX + HOURY) into HOURZ
put (MINX + MINY) into MINZ
put "UNIVERSAL:" && HOURZ & ":" & MINZ into fld "UT"
end if
end mouseUp
Re: Working with ISO 8601 Date format
Posted: Wed Oct 30, 2024 1:22 pm
by andyh1234
Thanks everyone
Re: Working with ISO 8601 Date format
Posted: Wed Oct 30, 2024 1:26 pm
by stam
Except ISO 8601 is not a simple format. Many different string formats are possible under this.
Date formats allowed:
Code: Select all
YYYY-MM-DD or YYYYMMDD
YYYY-MM (but not YYYYMM)
You can have ordinal dates (eg the 266th day of the year 2024)
Time is optional extra. Again lots of forms but most will be hh:mm:ss - however the "T" separator is optional if "unambiguous" context.
So valid expressions would be both "2024-10-30T11:30:00" and "20241030 11:30:00"
Then there is an optional time offset denoted by +, - or Z
Code: Select all
<time>Z // zulu time
<time>±hh:mm
<time>±hhmm
<time>±hh
Personally I would be looking at creating a small library to convert ISO 8601 to dateItems, which is LiveCode's date/time variable format. From there you can get US/UK dates, long/short/internet dates, or any part of this.
Re: Working with ISO 8601 Date format
Posted: Wed Oct 30, 2024 1:50 pm
by richmond62
That is a 'real pain'.
I did indicate my stack was 'rude and crude', and for something more complex you will need something, err, more complex than my 10 minutes' worth.
