Working with ISO 8601 Date format
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Working with ISO 8601 Date format
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.
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
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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Working with ISO 8601 Date format
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
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
-
- Livecode Opensource Backer
- Posts: 9748
- Joined: Fri Feb 19, 2010 10:17 am
Re: Working with ISO 8601 Date format
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
- Attachments
-
- ISO 8601 Cracker.livecode.zip
- (1.4 KiB) Downloaded 382 times
Re: Working with ISO 8601 Date format
Thanks everyone
Re: Working with ISO 8601 Date format
Except ISO 8601 is not a simple format. Many different string formats are possible under this.
Date formats allowed:
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
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.
Date formats allowed:
Code: Select all
YYYY-MM-DD or YYYYMMDD
YYYY-MM (but not YYYYMM)
Code: Select all
YYYY-DDD or YYYYDDD
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
-
- Livecode Opensource Backer
- Posts: 9748
- Joined: Fri Feb 19, 2010 10:17 am
Re: Working with ISO 8601 Date format
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.
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.