Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Re^3: convert UTC time to system time zone's time with perl default methodby Marshall (Canon) |
on Feb 24, 2017 at 21:55 UTC ( [id://1182762]=note: print w/replies, xml ) | Need Help?? |
Wow, I hadn't thought about this code for 7 years! Yes, there is some wild time weirdness out there and time zone offsets of 30 minutes for sure exist. If I remember right, there used to be a couple of places in the US that used a 30 minute offset for daylight savings time? I hadn't heard of a 15 minute time zone (or daylight time) difference before, but humans are capable of doing some amazingly stupid things! I guess that sort of confusion could be nice as an "excuse" if you are late to an appointment and the other side of the street is using local time 15 minutes ahead of you! If I were re-doing this, I would add the minutes and seconds into the code, leaving out only the fractions of seconds which cannot be represented by epoch time. Epoch is basically a 32 bit int representing number of seconds since an arbitrary date that is related to the release of Unix. So the fractions of a second cannot be represented. After 7 years, the algorithm remains sound: a) Convert the UTC date/time string into standard epoch seconds. Then, b) ask the local system what local time that epoch time means? I think the code is clear enough that I can leave that straight-forward extension to the reader...The epoch->local time standard function would handle this 30 minute stuff when given enough precision in the epoch time. So a 30 minute offset doesn't fundamentally change anything except the need for more precision. My advice to always log data in UTC remains. Local time is a presentation thing for management.
In Section
Seekers of Perl Wisdom
|
|