Date and Time in RFC 3339 format

Something you want to see in a LiveCode product? Want a new forum set up for a specific topic? Talk about it here.

Moderators: Klaus, FourthWorld, heatherlaine, robinmiller, kevinmiller

Post Reply
TorstenHolmer
Posts: 21
Joined: Mon Oct 28, 2013 1:23 pm
Location: Dresden, Germany

Date and Time in RFC 3339 format

Post by TorstenHolmer » Wed Jul 10, 2019 6:35 pm

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

Klaus
Posts: 11115
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Date and Time in RFC 3339 format

Post by Klaus » Wed Jul 10, 2019 7:06 pm

Could you give us an example, so we do not need to read the whole RFC 3339? 8)

SparkOut
Posts: 2015
Joined: Sun Sep 23, 2007 4:58 pm

Re: Date and Time in RFC 3339 format

Post by SparkOut » Wed Jul 10, 2019 10:23 pm

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.)

TorstenHolmer
Posts: 21
Joined: Mon Oct 28, 2013 1:23 pm
Location: Dresden, Germany

Re: Date and Time in RFC 3339 format

Post by TorstenHolmer » Wed Jul 10, 2019 10:50 pm

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...

Klaus
Posts: 11115
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Date and Time in RFC 3339 format

Post by Klaus » Wed Jul 10, 2019 11:16 pm

Aha, thank you.
Maybe you could add a comment to the above mentioned report, Torsten?

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2094
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Date and Time in RFC 3339 format

Post by [-hh] » Thu Jul 11, 2019 9:16 am

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
shiftLock happens

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6119
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Date and Time in RFC 3339 format

Post by dunbarx » Thu Jul 11, 2019 1:56 pm

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

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6793
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Date and Time in RFC 3339 format

Post by FourthWorld » Fri Jul 12, 2019 4:36 pm

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. ;)
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

TorstenHolmer
Posts: 21
Joined: Mon Oct 28, 2013 1:23 pm
Location: Dresden, Germany

Re: Date and Time in RFC 3339 format

Post by TorstenHolmer » Wed Jul 17, 2019 11:45 am

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


[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2094
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Date and Time in RFC 3339 format

Post by [-hh] » Wed Jul 17, 2019 5:35 pm

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
shiftLock happens

TorstenHolmer
Posts: 21
Joined: Mon Oct 28, 2013 1:23 pm
Location: Dresden, Germany

Re: Date and Time in RFC 3339 format

Post by TorstenHolmer » Thu Jul 18, 2019 5:21 pm

Great idea!
Thanks Hermann :-)

Post Reply

Return to “Feature Requests”