Forum Discussion

renojim's avatar
renojim
Community Streaming Expert
16 years ago

roDateTime fromISO8601String

I'm trying to initialize an roDateTime object from an ISO8601 date/time string. From the Roku DVP Component Reference:

Void fromISO8601String(String dateString) 
• Initialize the date/time using a string in the ISO8601 format. For example “01-01-2009T01:00:00.000”

The first thing to note is that the example does not follow the ISO8601 standard, it should be "2009-01-01T01:00:00.000". But, that doesn't work either. I've tried every possibility of moving the year around, with and without fractional seconds, with and without timezone offsets, etc., but the following code always shows that the date/time object never changes:


dt = CreateObject("roDateTime")
print dt.asSeconds()
dt.fromISO8601String("2009-01-01T01:00:00.000")
print dt.asSeconds()

I can change the value using the fromSeconds() function, but not the fromISO8601String() function.

Have I just not stumbled upon the magic string to make the function happy, or is it safe to say that this isn't really implemented even though it's in the documentation?

-JT

5 Replies

  • renojim's avatar
    renojim
    Community Streaming Expert
    Ahh... that was it! And I thought I tried every combination of date and time.

    Now if I could just remember why I was looking into this in the first place...

    Thanks again,
    -JT
  • "renojim" wrote:
    Have I just not stumbled upon the magic string to make the function happy, or is it safe to say that this isn't really implemented even though it's in the documentation?

    -JT


    I spent some time a while back trying to use this function and had the same results. I never did find a string that worked with it.
  • This is indeed a bug.... The roDateTime.fromISO8601String() method is not actually accepting ISO8601 strings. We are not recognizing the "T" in the example above (or any other letters eg "Z" in the iso8601 string)

    If you try to initialize using your code above, but replacing the "T" with a "-" you will get better results.

    dt = CreateObject("roDateTime")
    print dt.asSeconds()
    dt.fromISO8601String("2009-01-01-01:00:00.000")
    print dt.asSeconds()

    We will fix this to better support ISO8601 strings in a future release. For now, only use date strings like the format above without letters in it.

    --Kevin
  • renojim's avatar
    renojim
    Community Streaming Expert
    Thanks, that did it.

    Well... I take it back. Entering the string as "2010-04-26-01:01:01.000" does change the value, but the new value is off by more than 7 million seconds. Changing the time doesn't affect the value either and in fact the time portion of the string can be left off completely.

    -JT
  • Try strings like:

    "2010-04-26 00:00:00.000"
    "2010-04-26 16:45:00.000"