Your Digital Media Has Never Looked So Good

 
dunerunner
Topic Author
Posts: 10
Joined: Wed Jul 22, 2015 3:12 am

Re: Timestamp in milliseconds

Fri Aug 07, 2015 7:29 am

Thank you for all your help, but the answer I came up with looks like this:

ToMilliseconds = Function(time, timestring = "")
    If time <> invalid
      timestamp = time.AsSeconds()
      ms = time.GetMilliseconds()
      timestampString = timestamp.ToStr() + ms.ToStr()
    Else
      timestampString = timestring
    End If
    low = timestampString.Mid(timestampString.Len() - 9, 9).ToInt()
    high = timestampString.Mid(0, timestampString.Len() - 9).ToInt()
    output# = high
    output# = output# * 1000000000
    output# = output# + low
   
    return output#
  End Function


And then:
time = CreateObject("roDateTime")
  timestamp = GetGlobalAA().util.ToMilliseconds(time)
  print timestamp
 
  part1 = Int(timestamp / 1000000).toStr().Trim()
 
  coolString = part1 + "000000"
  coolTimestamp = GetGlobalAA().util.ToMilliseconds(invalid, coolString)
 
  part2 = Str(timestamp - coolTimestamp).Trim()
 
  print part1
  print part2
 
  timeStampString = part1 + part2
  print "--------------"
  print timeStampString


BTW BrightScript is the best language in the World :lol:
 
User avatar
RokuMarkn
Roku Engineering
Posts: 1581
Joined: Mon Jun 09, 2008 9:20 am

Re: Timestamp in milliseconds

Fri Aug 07, 2015 7:37 am

dunerunner wrote:

      timestampString = timestamp.ToStr() + ms.ToStr()



I don't think that will work. Depending on the value of ms, you'll be appending either 1, 2 or 3 digits to timestamp.

--Mark
 
sjb64
Posts: 108
Joined: Thu Apr 16, 2015 1:13 pm
Location: Memphis, TN

Re: Timestamp in milliseconds

Fri Aug 07, 2015 7:39 am

Belltown's suggestion should fix that:

belltown wrote:
There are too many significant digits to store in any of the Roku number types, but you can get the milliseconds value as a string:

dt = CreateObject ("roDateTime")
ms = dt.AsSeconds ().ToStr () + Right ("00" + dt.GetMilliseconds ().ToStr (), 3)
Print ms
FlixRaider channel
 
dunerunner
Topic Author
Posts: 10
Joined: Wed Jul 22, 2015 3:12 am

Re: Timestamp in milliseconds

Fri Aug 07, 2015 7:44 am

Thanks, fixed it.
 
EnTerr
** Valued Community Member **
Posts: 3834
Joined: Sun Jan 02, 2011 2:41 am

Re: Timestamp in milliseconds

Fri Aug 07, 2015 10:53 am

All this pain and suffering. Seems like a case of "if something is too hard, perhaps you are approaching it the wrong way".

How about using roDateTime.toISOString()?
You get a timestamp which (a) can be used directly for comparisons (because of the format used, string lexical order gives you proper chronological order) and (b) can be converted server-side to native timestamp, if time differences are to be calculated.
 
User avatar
TheEndless
** Valued Community Member **
Posts: 9231
Joined: Mon Oct 04, 2004 10:15 am
Location: US
Contact:

Re: Timestamp in milliseconds

Fri Aug 07, 2015 11:31 am

EnTerr wrote:
All this pain and suffering. Seems like a case of "if something is too hard, perhaps you are approaching it the wrong way".

How about using roDateTime.toISOString()?
You get a timestamp which (a) can be used directly for comparisons (because of the format used, string lexical order gives you proper chronological order) and (b) can be converted server-side to native timestamp, if time differences are to be calculated.

Neither ToISOString nor FromISO8601String supports milliseconds, so if millisecond precision is important, that wouldn't work.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
 
EnTerr
** Valued Community Member **
Posts: 3834
Joined: Sun Jan 02, 2011 2:41 am

Re: Timestamp in milliseconds

Fri Aug 07, 2015 12:35 pm

TheEndless wrote:
Neither ToISOString nor FromISO8601String supports milliseconds, so if millisecond precision is important, that wouldn't work.

Ugh! I was mislead by "2009-01-01T01:00:00.000" while skimming the doc

PS. let me compensate for that:
BrightScript Debugger> ti = createObject("roDateTime")
BrightScript Debugger> ? left(ti.ToISOString(), 19) + "." + right("000" + ti.getMilliseconds().toStr(), 3) + "Z"
2015-08-07T19:48:35.076Z
 
User avatar
TheEndless
** Valued Community Member **
Posts: 9231
Joined: Mon Oct 04, 2004 10:15 am
Location: US
Contact:

Re: Timestamp in milliseconds

Sat Aug 08, 2015 12:19 am

EnTerr wrote:
Ugh! I was mislead by "2009-01-01T01:00:00.000" while skimming the doc

If that format is indeed in the documentation, then it's misleading and they should fix it, as roDateTime.FromISO8601String() will fail to parse it, returning 1/1/1970 instead. The fact that FromISO8601String doesn't support ISO dates with milliseconds is a bug, in my opinion, and has tripped me up on a number of occasions.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
 
EnTerr
** Valued Community Member **
Posts: 3834
Joined: Sun Jan 02, 2011 2:41 am

Re: Timestamp in milliseconds

Sat Aug 08, 2015 9:06 am

they might have fixed it by now:
BrightScript Debugger> ti.FromISO8601String("2009-01-02T03:04:05.678")
BrightScript Debugger>  ? ti.toISOstring(), ti.getMilliseconds()
2009-01-02T03:04:05Z    678
 
User avatar
TheEndless
** Valued Community Member **
Posts: 9231
Joined: Mon Oct 04, 2004 10:15 am
Location: US
Contact:

Re: Timestamp in milliseconds

Sun Aug 09, 2015 9:01 pm

EnTerr wrote:
they might have fixed it by now:
BrightScript Debugger> ti.FromISO8601String("2009-01-02T03:04:05.678")
BrightScript Debugger>  ? ti.toISOstring(), ti.getMilliseconds()
2009-01-02T03:04:05Z    678

Interesting.. It doesn't work with the Z, though...
BrightScript Debugger> ti.FromISO8601String("2009-01-02T03:04:05.678Z")
BrightScript Debugger> ? ti.toISOstring(), ti.getMilliseconds()
1970-01-01T00:00:00Z           0
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
 
belltown
Posts: 1465
Joined: Thu Dec 09, 2010 1:43 pm
Contact:

Re: Timestamp in milliseconds

Sun Aug 09, 2015 9:19 pm

The documentation for FromISO8601String() is definitely confusing. It gives an example of the format supported: "YYYY-MM-DD HH:MM:SS" (note, no milliseconds), but when it goes on to give examples of the example, it includes milliseconds: "2009-01-01 01:00:00.000" or "2009-01-01T01:00:00.000". It says those are the only formats recognized. Neither the example format nor the examples of the example format include the "Z" at the end. ToISOString() supposedly does have a "Z" at the end.

Set the date/time using a string in the ISO 8601 format. For example "YYYY-MM-DD HH:MM:SS" e.g "2009-01-01 01:00:00.000" or "2009-01-01T01:00:00.000". Note that this function is unaware of the local time zone, so these time formats are effectively UTC even though the ISO 8601 spec says they should be in local time. The above formats are also the only formats recognized by this function, even though the ISO 8601 spec contains other valid formats.
https://github.com/belltown/
 
User avatar
RokuKC
Posts: 315
Joined: Wed Sep 10, 2014 10:44 am
Location: Roku HQ

Re: Timestamp in milliseconds

Mon Aug 10, 2015 10:00 am

TheEndless wrote:
Interesting.. It doesn't work with the Z, though...
BrightScript Debugger> ti.FromISO8601String("2009-01-02T03:04:05.678Z")
BrightScript Debugger> ? ti.toISOstring(), ti.getMilliseconds()
1970-01-01T00:00:00Z           0


Thanks for the bug report. Issue confirmed.

Who is online

Users browsing this forum: No registered users and 5 guests