Skip to main content
16-Pearl
October 2, 2020
Solved

How to handle daylight savings and timezone offset values

  • October 2, 2020
  • 2 replies
  • 4558 views

I am trying to display timestamp in local time where the asset is located (local time = asset time).  I try to do this by

1.  storing the local time in UTC time (server time) on the server (no offset)

2.  get the timezone offset using the user's IP (user is person viewing the mashup)

3.  add the timezone offset to the startDate and endDate of the query

4.  subtract the timestamp value by the timezone offset value to display the data in the grid in asset time

 

This works great except the part when there was a daylight savings adjustment in the past.

Please see image below:

 

All of these records were restored with 00:00:00 for time, but you can see that the time shifted by 1 hour when daylight savings started on March 8th, 2020 in the US.  When I use the timezone offset in step #2, I am using the current offset, which is -7.  When I apply this to the query, it is applying it to all records even though some records need offset of -8 due to daylight savings adjustment.  I can't get and apply historical timezone offset values.

 

How can I fix this?????

 

Thingworx - 2020-10-02 - Timezone offset issue.PNG

Best answer by Willie

I was able to resolve the issue based on the article below.  Timezone offset should be dealt with when adding the data to streams, etc., not afterwards like I had in my original post.

 

https://www.ptc.com/en/support/article/CS240366

 

 

2 replies

Willie16-PearlAuthor
16-Pearl
October 2, 2020

In addition, I think the server goes by US DST schedule.  DST starts/ends on different dates/times around the world.

https://www.timeanddate.com/time/dst/2020.html

 

By the way, our server is PTC cloud hosted.

 

Maybe the server should not adjust to daylight savings. 

Community Manager
October 2, 2020

Hi @Willie.

 

We recommend running ThingWorx in UTC to avoid time change issues.  Here's a link from the 9.0 Help Center regarding timezones.

 

Since your site is hosted, I recommend opening a case for the Cloud team.  I will be happy to open the case on your behalf, if you would like.

 

Regards.

 

--Sharon

Willie16-PearlAuthor
16-Pearl
October 2, 2020

@slangley 

 

I think our server is actually in UTC time.  The thingworx applicaiton adjusts the time displayed based on the user's timezone (person viewing mashup).  Depending on the date stored in the application, it will adjust the offset appropriate for that time. So from March 8th, 2020 to Novermber 5th, 2020, it uses offset of -7.  It uses offset of -8 before March 8th, 2020 to November 3, 2019.  

Willie16-PearlAuthorAnswer
16-Pearl
October 5, 2020

I was able to resolve the issue based on the article below.  Timezone offset should be dealt with when adding the data to streams, etc., not afterwards like I had in my original post.

 

https://www.ptc.com/en/support/article/CS240366