Convert historical time to GMT

一世执手 提交于 2019-12-06 08:14:11

The obvious reliable solution would be to use UTC (which has no daylight savings) for the time stamp you're sending over. Using any time system that has inherent ambiguity (there is one hour of overlap each year where you can get the same time stamps on a different time) will make it impossible to have a fool-proof method, since information is lost.

If you have no control over the time format that the remote machine is sending, you can only try to extrapolate from the information that you do have, for instance, if the end time is lower than the start time, add one hour. This again introduces ambiguity if the job took longer than one hour, but at least time won't move backwards.

Time change appears twice a year - why should you bother? Anyway, can't you change the time format to include the time change event? Or check if job is done during time change by comparing to some fixed time and date at which time change appears?

Get the local time in UTC at the start and end of the remote job. Get the remote job time and covert to UTC at the start and end of the job. Convert the collection "historic" times to GMT/UTC as stated in your original post. Keep this data together in a struct or class and give additional start end times a clear name like LocalDLSValidation etc We must now checkfor following scenarios:

  1. Start and end time delta between Local and Remote is within allowed threshold(50mins?)

This the gold case. No modification is required to our collection of historical times

 2. Local start/end time and remote time delta is outside threshold. 

This is the second simplest case. It means that we can + or - hour to our entire collection of times.

 3.Local start time and remote time delta is within threshold.  But end is outside. 

This is our worst case scenario as it means change has occurred in the middle of our job. If the job lasts less than hour then it will be easy to see which times in our collection need to be + or - one hour.

If it is greater than 1 hour....mmmmm. This is where we run into problems.

   4.  Start time between local and remote is different but end time is different

According to use case in OP this should not occur.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!