LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I subtract timestamps to give me a DBL time in seconds?


@AristosQueue (NI) wrote:

@billko wrote:
What prompted you to post to an 18 year old topic?  😄  I mean, this is good info, but...?

Someone was using coercion bullets in their diagram and cited this as their reasoning. It's still the number one hit on Google for info on the topic. 🙂

 


At any rate I did file that in my "important to know" folder.  Thanks!

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 11 of 27
(977 Views)

@AristosQueue (NI) wrote:

@LesHammer wrote:
True - in fact that would get rid of those conversion dots on the subtract widget of my program. 🙂

No. Do not add coercion bullets. The coercion that the Subtract node is doing is not a coercion to double. It's an under-the-hood conversion that shouldn't, in my opinion, be reflected on the block diagram. If you coerce to double first, you will get the wrong answer. Coercing to double gets you a timestamp that is almost right, but not quite. You will be off by fractions of a second. It's small, but some users care about very small amounts.

 

These two outputs are NOT the same.

AristosQueue_0-1650327921231.png

AristosQueue_1-1650327950942.png

 

 

 


Worse, I am not sure that I agree that the Coercion dots should be hidden.  Isn't the Coercion "To UTC," part of the internal storage mechanism for the timestamp?  Without the Coercion dot how would we know if we were subtracting a value in System time format from one in UTC?

 

Casting to UTC should remove the coercion dots.  No LabVIEW on my phone to test that.

If AQ had inlined a snippet everyone outside CDT could have observed the system time offset in those constants.

Actually, this could be a great zombie discussion and we can learn things!


"Should be" isn't "Is" -Jay
0 Kudos
Message 12 of 27
(930 Views)

Related, how would we generate a VIA test for "Block Diagram Timestamp constant uses System Time?" A very nice warning to have if your code is going to travel since those constants are notorious for jetlag.


"Should be" isn't "Is" -Jay
0 Kudos
Message 13 of 27
(923 Views)

@JÞB wrote:


Worse, I am not sure that I agree that the Coercion dots should be hidden.  Isn't the Coercion "To UTC," part of the internal storage mechanism for the timestamp?  Without the Coercion dot how would we know if we were subtracting a value in System time format from one in UTC?

 

Casting to UTC should remove the coercion dots.  No LabVIEW on my phone to test that.

If AQ had inlined a snippet everyone outside CDT could have observed the system time offset in those constants.

Actually, this could be a great zombie discussion and we can learn things!


It's slightly different than you put it here. The Timestamp value itself is ALWAYS in seconds since January 1, 1904 GMT. For pretty much all practical purposes this is equal to UTC, although that didn't exist back then😀

 

What changes is the formatting of how that data is displayed. If the constant or control has the flag to display in local time, which is the default, it will change the value that is displayed, but the value behind the Timestamp remains the same.

 

Consider this the same as when you have a numerical control and you change its display mode from decimal to hexadecimal. Nothing on the actual numeric bits that represent the numbers stored in the control really changes, just the formatting of how the data is displayed is changed. So the UTC or local time is not part of the data in the wire/control, but an attribute of the control/constant that tells it how to display that data.

 

Consequently when you put time constants into your program you should consider how they are meant to be used. And here things get hairy as the intuitive approach actually will fail you quite often.

 

You could argue that that is wrong and it should be the opposite. However no matter how you implement it, there are always situations where it feels actually wrong. I think that the current approach is a pretty valid one and is consistent with most computer programming. The Unix timestamp is also an integer value with 1 second resolution and with epoch January 1, 1970 UTC. And the Windows FILETIME is a Quad (64-bit Integer) with 100ns intervals since January 1, 1600 UTC. Microsoft likely chose this epoch to avoid the problems with the discontinuity that occured with the change from the Julian to the Gregorian calendar in 1582, respectively even later in some countries.

 

The binary timestamp stored in a file will look different on a system in a different timezone when displayed in default local time format but actually does mean the exact date and time the timestamp was stored in that file when looking at it from a universal viewpoint. An observer who is not on the earth surface doesn't really care about the local timezone on earth a sun flare was recorded but the absolute "star" time. 😁

Rolf Kalbermatter
My Blog
Message 14 of 27
(905 Views)

@ rolf I am aware that the value never changes but, since there is no means to show display format, I would prefer the existing coercion dots remain for code readability and maintenance.   Or, simply, changing the existing behavior would be wrong unless we have a means to show display format similar to the widgets available on strings / Integer constants or Glyphs similar to the error ring.  (Watch that Idea Exchange for that!)

 

Are you really suggesting that performing math on mixed radix display constants would be as easy to maintain without the "Show radix" option available?  How about when the string littoral "\s" is compared to " "?


"Should be" isn't "Is" -Jay
0 Kudos
Message 15 of 27
(894 Views)

I think you still mix up things here. The coercion dot is meant to indicate that something in the numeric representation inside the wire is changing (I'm considering the pass over from a terminal to a wire and back also part of this for the ease of this discussion). The information if a timestamp is displayed in UTC or local time is however an attribute of the control itself and has nothing to do with the actual data stored in it and even less with any storage size change or whatsoever.

 

As such you bring up a good Idea Exchange point: "Add a glyph to the Timestamp control, constant and every other element that can display a timestamp that indicates that the timestamp displays in local time or UTC! In principle the same idea that lets also show in a string control if the string is displayed in normal, /, password, or hex mode."

 

Because it is really the same thing. It's about how the control displays its actual data.

Rolf Kalbermatter
My Blog
0 Kudos
Message 16 of 27
(888 Views)

Spoiler
 
@rolfk wrote:

 

As such you bring up a good Idea Exchange point: "Add a glyph to the Timestamp control, constant and every other element that can display a timestamp that indicates that the timestamp displays in local time or UTC! In principle the same idea that lets also show in a string control if the string is displayed in normal, /, password, or hex mode."

 

Because it is really the same thing. It's about how the control displays its actual data.


See here for the Idea Exchange Idea

Plenty of room for Kudos!

 

Who knows, maybe I'll actually get a blurb in the upgrade notes for this one! (I've lost count of the number implemented unclosed Ideas I have submitted)

 

Incidentally, for completeness System Time Format is merely the Default Default display format.  It can be deselected from the checkbox on the Options Evironment page.


"Should be" isn't "Is" -Jay
0 Kudos
Message 17 of 27
(874 Views)

@JÞB wrote:
ercion "To UTC," part of the internal storage mechanism for the timestamp?  Without the Coercion dot how would we know if we were subtracting a value in System time format from one in UTC?

That isn't the coercion that's happening. There isn't any coercion of the data that is occurring. It's simply that the result of the subtraction is not the same as the input types, so LV calls that a coercion and is thus drawing the coercion dots. The timestamps are subtracted as timestamps under the hood. The coercion dots definitely should not be there.

0 Kudos
Message 18 of 27
(866 Views)

@AristosQueue (NI) wrote:

@JÞB wrote:
ercion "To UTC," part of the internal storage mechanism for the timestamp?  Without the Coercion dot how would we know if we were subtracting a value in System time format from one in UTC?

That isn't the coercion that's happening. There isn't any coercion of the data that is occurring. It's simply that the result of the subtraction is not the same as the input types, so LV calls that a coercion and is thus drawing the coercion dots. The timestamps are subtracted as timestamps under the hood. The coercion dots definitely should not be there.


Then, why isn't the Coercion dot on the output?  Yes, they can be there instead of on the input!  

 

It sounds like you are arguing that the Timestamp datatype was poorly implemented.  EDIT [less well implemented than possible , poorly is quite overstated but the coersion dots placements could be improved] I might reiterate that I believe a TIA format specifier will also be needed (2mSec/day/century accumulates by e and currently stands over 37 seconds since 1904)

 

I would agree the misleading  coercion dots could be removed provided that there was another indication of display format available.  I assume your kudos on the IE are forthcoming. 

 

EDIT [ The IE exchange might be a better venue for further comment]


"Should be" isn't "Is" -Jay
0 Kudos
Message 19 of 27
(852 Views)

I do not know any other way to say this: there is no coercion of data on this node at all. None. This is irrelevant to what happens on the front panel display. Irrelevant. Not even remotely related. I'm not sure why you're connecting them. The timestamp data is the identical bits regardless of how it is displayed. The wires care about the bits. That's all there is. And they are cleanly computed into a double. There's no more coercion here than happens if you subtract two unsigned integers and get a signed integer. No coercion.

0 Kudos
Message 20 of 27
(840 Views)