Noel
Noel

Reputation: 5369

Time is hard - working in UTC and another timezone

i have an application that receives an event every hour(via quartz). So this could happen 24 times per day.

There are 3 exclusion times within that day that I do not want to take any action when I receive an event(must still receive the event via quartz, so solution is not to update quartz cron expressions)

I need to configure the times for these 3 times in the timezone of the customer. In this case it will be CEST where summer(UTC+2) and winter(UTC+1) time are observed. The times are 00:00, 08:00, 16:00 where I will have a buffer of 5 minutes either side of these times.

So taking the 08:00 as an example and I receive an event any time between 07:55 to 08:05 I will perform no action.

My application will be working in UTC time, however the exclusion times need to be configure in CEST and in the future other timezones.

Initial thinking is to take the current date and work out exclusion times in UTC for that date but I believe there would be issues with this approach

Any ideas?

Upvotes: 1

Views: 141

Answers (1)

Matt Johnson-Pint
Matt Johnson-Pint

Reputation: 241535

Careful, assuming you are talking about a "local day", the event might be received 23 or 25 times per day, on days containing daylight saving time transitions. Not every local day has 24 hours.

Also realize that there are several time zones that have DST transitions right at midnight. For example, in Brazil the clocks will move from 2015-10-17 23:59:59 to 2015-10-18 01:00:00, skipping over the midnight hour entirely. Midnight does not exist on this day, so you'll have to decide whether to let the event be received at 1:00, or not at all.

Then on 2016-02-20 23:59:59, the clocks will tick back to 2016-02-20 23:00:00. Though midnight only exists once, your "window" that extends to 23:55 will repeat twice. You'll have to decide whether you want the event to be able to be received in either slot, or in the first, or in the second.

The idea of working out the UTC time of an occurrence in advance has merit, but the key is that the recurrence rule is kept in terms of local time and time zone, and you don't discard that information. You very well may need to recalculate the UTC time for a specific occurrence. This can happen when governments decide to change their time zone's DST rules or base offsets. In general, any time you apply a time zone update, you should consider all future UTC times suspect and recalculate them.

You can be notified of time zone changes by subscribing to the tz announcements mailing list, then monitoring your own platform for corresponding updates.

See also: Daylight saving time and time zone best practices

And my answer to How to store repeating dates keeping in mind Daylight Savings Time.

Upvotes: 1

Related Questions