I searched for this before asking but couldn't find anything that helps. I have a server that uses UTC, the clients can set the time of an event that the server executes daily (this is a simplification). For example someone in France wants an event to happen at 23:00 local time (22:00 UTC). I convert this to UTC and store it; the server executes happily every day at 22:00 UTC. Then come summer, now the offset is +2h with France, the server still executes at 22:00 UTC but for the user this is the wrong time as 22:00 UTC in France is now 00:00 local time.
I store in UTC because everyone says to store in UTC and to convert to the local time when outputting to the user, fine, but this doesn't work as expected for the user. I think I should store something like 23:00 French time and the server should take that and say "ok, this is 22:00 UTC today" or ok, this is 21:00 UTC today because of DST" (I am using Java with JodaTime BTW), but this contradicts what everyone says about how I should be storing it in UTC in the DB...so...what can/should I do?
If I store the local time and date with offset and when I read it (on the server which is using UTC) I do:
DateTime dbLocalHistoricDateTime = fromDB(); // suppose this 23:00 in France on the 01.01.2015 (UTC+1), 22:00 UTC on that date DateTimeZone localZone = dbLocalHistoricDateTime.getZone(); DateTime currentLocalDateTime = DateTime.now().withZone(localZone); DateTime localToday = dbLocalHistoricDateTime.withDate(currentLocalDateTime.getYear(), currentLocalDateTime.getMonthOfYear(), currentLocalDateTime.getDayOfMonth()); DateTime utcToday = localToday.withZone(DateTimeZone.UTC);
then utcToday contains the correct UTC time for today (21:00 UTC being 23:00 in France on the 27.04.2015, the server then can execute this event on that UTC time.