LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

UTC +-0.001 seconds

This is a little bit of two things, one I want to figure out what is going on with this little snippet for curiosity sake and also, see if anyone has any better ways of dealing with this then the Goldbergian way I currently am.

 

I have a server that only returns timestamps in the specified text format and UTC time so I need a way of converting that to local time for ease of reading, so after faffing about for a bit I found the below, although it has an interesting problem, it loses 0.001 seconds on certain values.

.256 = .255

.257 = .256

.258 = .258

.259 = .259

.260 = .259

UTC to local.png

 

Not a big deal as I'll never be working to that time accuracy, but just interesting. Let me know your thoughts.

0 Kudos
Message 1 of 12
(3,882 Views)

Can you show more decimal places on your indicators?

 

My thought is that timestamps are essentially a special variation of a floating point double precision.  You probably already know by now that not all numbers can be represented exactly in binary.  You may be running into this where the act of converting is not quite giving you the same result back due to the tiny errors in the resolution of floating point numbers.

 

Beyond that, I'm not sure you need to do as much as you are doing to convert a time to appear in local time.  I just don't have the time (ha ha) at the moment to experiment with it.

0 Kudos
Message 2 of 12
(3,874 Views)

If you remove the two "to DBL" and subtract the two timestamps directly, things seem to work better. Try it.

 

0 Kudos
Message 3 of 12
(3,868 Views)

@Ravens

local time.png

I had tried using the Time version originally but it doesn't seem to work properly with DST for some reason, but I do feel like there must be a better way to do this.

 

@Altenbach

It seems better, but oh do I not like the sight of coercion dots....

Not sure which is the lesser of two evils here. And my understanding of coercion dots was that they indicated a hidden type conversion, so interestingly, its not the conversion to float itself, but simply the position of the float conversions.

0 Kudos
Message 4 of 12
(3,843 Views)

Well, coercion dots are not harmful. If a coercion occurs, it does not matter if it is implicit or explicit. 😄

 

(see also this long discussion that shows that omitting explicit coercion (and thus having coercion dots!) is sometimes preferable. Go read it! I just added a link to our discussion :D)).

 

Back to the current problem, I had the crazy idea to tell it that the original time is in UTC (by replacing the "Z" with 00:00:00 or -00:00:00 and reading it with %z, but it obviously does not seem to work. Maybe I am doing it all wrong. This is not my field of expertise. 😄

 

 

 

0 Kudos
Message 5 of 12
(3,826 Views)

Looking at your use of %z reminded me of something I saw once upon a time in the date format so I figured I might try it.

 

Replacing %< >T (Absolute time container) with %^< >T (Universal time container) results in the same reading as returns from the Seconds/Date-Time/Seconds conversion, off by an hour. So it looks like there is something about LV that doesn't quite handle the DST properly when going back and forth to UTC.

0 Kudos
Message 6 of 12
(3,806 Views)

Would it be fair to say that the obsession with coercion dots came from the CLD exam frowning upon them?

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.
0 Kudos
Message 7 of 12
(3,804 Views)

Why wouldn't this work?

 

Input string is assumed to be UTC.  It converts it to a timestamp which is assumed to be local time.  It also determines time zone, and adds that to the result, so the time in the time stamp indicator is now compensated t local time.

 

I do see one flaw with this.   The DST shift could fail if UTC time is at a time that if it was local, time changed would have occurred, but it would subtract back to a point of time where the time change had not occurred yet in your local time.  So that would be a few hours in the spring and a few hours in the fall.  But with a bit more code to look at the time zone offset after the addition, the hour could be added back in or taken out.  (I did not include this scheme in the snippet.)

 

I still think there is another way that LabVIEW would handle this better based on format strings.  I'm just not sure how yet.

 

0 Kudos
Message 8 of 12
(3,765 Views)

Here is an alternate way to convert from local time to UTC time. I've used this call to the kernel for many years without any issues (at least through Windows 7). Just "add" the UTC offset to go from UTC time to Local. I don't know if this is any better/faster, but you only need to store one numeric value rather than doing a lot of string conversions.

 

The only issue I see is the same one RavensFan mentioned: If you make the call to the kernel just before DST changes (at 2am) you will still have the old offset value until you call the kernel again after 2am. This will only happen twice a year Nov 1 and March 3 (or not at all if you live in Arizona, Hawaii, Puerto Rico...)


I forgot where I got this code, so I apologize for not giving him/her credit.

 

convert UTC_Local Time.png

 

0 Kudos
Message 9 of 12
(3,739 Views)

This is courtesy paul_cardinale:

utc offset.png

 

This calculates the offset of local time from UTC.  It is fully DST compatible.

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.
0 Kudos
Message 10 of 12
(3,716 Views)