Page 1 of 1
Date and Time in RFC 3339 format
Posted: Wed Jul 10, 2019 6:35 pm
by TorstenHolmer
Is there a way to transform the livecode date and time information into the Internet format RFC 3339?
I am working with this type of data and want to know if I have to write an own function for it or if it is planned to have it as another date-time format in Livecode?
Kind regards,
Torsten
Re: Date and Time in RFC 3339 format
Posted: Wed Jul 10, 2019 7:06 pm
by Klaus
Could you give us an example, so we do not need to read the whole RFC 3339?

Re: Date and Time in RFC 3339 format
Posted: Wed Jul 10, 2019 10:23 pm
by SparkOut
I doubt it is on the roadmap to have RFC 3339 format dates in LiveCode very soon, or at least if it is and implemented before fixing the pre 1970 date bug on Windows then I will be surprised, as well as
very upset.
https://quality.livecode.com/show_bug.cgi?id=4941
(As this report is dated 2007, you can understand my scepticism.)
Re: Date and Time in RFC 3339 format
Posted: Wed Jul 10, 2019 10:50 pm
by TorstenHolmer
A typical example is this one:
2019-07-10T18:27:07.744Z
It is the standard format for many internet service timestamps.
YYYY-MM-DDTHH:MM:SS.fff (Z = UTC = Universal Time Coordinated)
It shouldn't be too complicated to implement into the engine. Until then, I will have to write my own translator for it...
Re: Date and Time in RFC 3339 format
Posted: Wed Jul 10, 2019 11:16 pm
by Klaus
Aha, thank you.
Maybe you could add a comment to the above mentioned report, Torsten?
Re: Date and Time in RFC 3339 format
Posted: Thu Jul 11, 2019 9:16 am
by [-hh]
TorstenHolmer wrote:Is there a way to transform the livecode date and time information into the Internet format RFC 3339?
You could use (the components of) the internet date.
[The optional fractional seconds can be derived from the millisecs.]
p.s. There is also
https://github.com/derbrill/libdate
Re: Date and Time in RFC 3339 format
Posted: Thu Jul 11, 2019 1:56 pm
by dunbarx
Without even understanding the format of this date, surely a handler that dissects each component, using our favorite property, the itemDelimiter, can be easily written and stored as a library function.
Craig
Re: Date and Time in RFC 3339 format
Posted: Fri Jul 12, 2019 4:36 pm
by FourthWorld
True, Craig, but being able to use the format with the convert, sort, and other commands would be pretty nice.
Mark Waddingham once outlined a proposal to support a wide range of date formats with minimal modifications to the code base. That was many years ago. Don't know what became of that, but it sure sounded useful in our world where every other week a new RFC comes out with a new date format because I guess the nature time keeps changing so all of the vast range of existing formats are somehow no longer adequate.

Re: Date and Time in RFC 3339 format
Posted: Wed Jul 17, 2019 11:45 am
by TorstenHolmer
Ok, I've developed a solution and want to share it here:
Code: Select all
function ConvertInternetTimeToSeconds tInternetTime
-- IN: 2019-07-11T15:15:22.801Z
-- OUT: 1562858122
set itemdelimiter to "T"
put item 1 of tInternetTime into tDate
put item 2 of tInternetTime into tTime
set itemdelimiter to "-"
put item 1 of tDate into tYear
put item 2 of tDate into tMonth
put item 3 of tDate into tDay
set itemdelimiter to ":"
put item 1 of tTime into tHour
put item 2 of tTime into tMinute
put item 3 of tTime into tSecond
set itemdelimiter to "."
put item 1 of tSecond into tSecond
put tYear & comma & tMonth & comma & tDay & comma & tHour & comma & tMinute & comma & tSecond & comma & "1" into tTimeInSeconds
set itemdelimiter to comma
add 2 to item 4 of tTimeInSeconds -- local adaption to UTC: my timezone is 2 hours behind ZULU time
convert tTimeInSeconds from dateItems to seconds
return tTimeInSeconds
end ConvertInternetTimeToSeconds
Re: Date and Time in RFC 3339 format
Posted: Wed Jul 17, 2019 5:35 pm
by [-hh]
For the first part of your function you could also use a one-liner:
Code: Select all
function ConvertInternetTimeToDateItems tInternetTime
return item 1 to 6 of replaceText(tInternetTime,"[-T:.]",",")
end ConvertInternetTimeTodateItems
Re: Date and Time in RFC 3339 format
Posted: Thu Jul 18, 2019 5:21 pm
by TorstenHolmer
Great idea!
Thanks Hermann
