in reply to Re^2: Timezone Conversion
in thread Timezone Conversion
Time zone conversion. Fun stuff. Looks easy until you get into it.
It's not the math that kills you; it's the human complexity element. There's a reason the Time Zone Database is so large.
If the timezone is given to you as EDT then you're stuck doing your best to avoid or translate ambiguity with what you're given.
I seem to recall the two keys to doing graceful time conversions are knowing what rules are followed in the creation of the timestamp format you are receiving, and knowing what timezone the target should be.
I did a time conversion routine at one point where I insisted I should be able to perform the translation in a single computation (and, frankly, I still argue that I should have been able to), but kept wrapping myself around the axle in handling the odd cases. Probably just wasn't my best head-in-the-algorithm day, but the troubles it kept causing me highlighted what I probably should have done from the start
I finally surrendered and made it a two-step process; convert source time to UTC, then convert UTC to target timezone.
Not only did I get it right without hassle, but the code was astoundingly easier to read and maintain for the poor sucker who had to work on it the next time they changed the DST rules.
I begrudgingly accepted the increased computation cost of two conversions for code that was easier to read and maintain.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: Timezone Conversion
by MidLifeXis (Monsignor) on Oct 28, 2015 at 13:43 UTC | |
by marinersk (Priest) on Nov 16, 2015 at 22:01 UTC | |
by oiskuu (Hermit) on Nov 16, 2015 at 23:16 UTC | |
Re^4: Timezone Conversion
by stevieb (Canon) on Oct 27, 2015 at 23:18 UTC |