Nanoseconds Questions

I was just browsing the new Xojo.Core.Date, and looking at Nanoseconds. I’m considering a logging application that might want to log in increments finer than seconds.

What time is the Nanoseconds value measuring from? Is it from 1 January 1970, GMT - like TotalSeconds?

Nanoseconds is defined as an integer, wouldn’t that overflow pretty quickly with the default 32 bit integer type?

Is it actually returning a UInt64?

[quote=176334:@John McKernon]I was just browsing the new Xojo.Core.Date, and looking at Nanoseconds. I’m considering a logging application that might want to log in increments finer than seconds.

What time is the Nanoseconds value measuring from? Is it from 1 January 1970, GMT - like TotalSeconds?

Nanoseconds is defined as an integer, wouldn’t that overflow pretty quickly with the default 32 bit integer type?

Is it actually returning a UInt64?[/quote]

As far as I understand, it counts nanoseconds from the last full second, and when it reaches one billion, one second is added, and it starts over at zero nanosecond.

That said, I never needed such a small fraction of time. Maybe microseconds sometimes to measure execution time. For smaller than a second, I often use Ticks.

Ah, that makes sense, though it would be best if the documentation made that clearer.

Thanks!

i use ticks to measure execution time too…

I don’t think this is true. Will look for sources.

It is the remaining fraction of the time in nanoseconds. It’s a fraction of a second.

The LR describes Nanoseconds as “The nanoseconds of the time.”. To me it means for instance Seven hours, 28 minutes, 10 seconds and 12589 nanoseconds. That said, that should not be so difficult to verify with a program.

I placed a multiple Timer1 1000 Ms on a window, and added a dada Xojo.Core.Date property to it.

Button :

[code]Sub Action()
static compte as integer

dada = xojo.core.date.now
system.debuglog str(dada.Nanosecond)
compte = compte+1

if compte = 10 then me.enabled = false

End Sub
[/code]

The result is steadily about the same value with a bit of variations, like
62600000
62200000
62300000
and so on.

At first glance, it does look very much like elapsed nanoseconds from the full secon.

Of course no way to edit when there is a mistake. Read. No need for Button. Timer Action event :

You are right. I get confused with the new framework. I must have been thinking about the Microseconds function in the old framework.

It’s alright. The new framework is somewhat unsettling at first.

Xojo.Core.Date.Nanoseconds is the nanoseconds after the second, just like Xojo.Core.Date.Second is the seconds after the minute.

Xojo.System.Microseconds (or just Microseconds in desktop/web/console projects) measures elapsed time since the computer was started.