I need to send out emails based on a timestamp. But the timestamp must be what the user expects it to be.
The timestamp is set by the user submitting an object.
E.g
Al from L.A in the U.S saves an object with a timestamp of ‘3/30/2015 10:00:00AM’.
Lars from Berlin in Germany saves an object with the timestamp of ‘4/15/2015 11:00:00PM’.
The system that looks at these objects and later sends out emails is based in a GMT+1 timezone.
My thought, to keep it super simple, is to add or subtract the difference in the timezone hours, based on where the object is from (timezone).
So in Al’s example the system would subtract 9 hours (GMT+1 difference) but in Lars’ example the system would keep the date, since Germany is also GMT+1.
Wouldn’t that be an ok soultion ?
6
The web server is saving the data, not the user, so it doesn’t matter what the user’s time is. The object should be saved with a timestamp in GMT (universal) time format. Save the user’s GMT timezone offset, Then add that offset to the timestamp (which is in UTC) to present to the user, his own local time.
For example, since I’m in CA, my UTCTimeZoneOffset would be -8. Add -8 to 21:00UTC and for me, it’s 13:00PST.
1
Not so much. Maybe.
The problem is that if Al from LA marks something with 1/1/2015 10AM and 7/1/2015 10AM, those will be different offsets from GMT.
“What the user expects it to be” can get really dicey given our overly complex way of measuring times. Where at all possible, work using UTC (which may or may not be different from GMT depending on your precision needs) and translate to local time as close to display to the user as possible.
3