Is timezone info redundant provided that UTC timestamp is available?

264 views Asked by At

I have a simple mobile app that schedules future events between people at a specified location. These events may be physical or virtual, so the time specified for the event may or may not be in the same timezone as the 'location' of the event. For example, a physical meeting may be scheduled for two people in London at local time 10am on a specified date. Alternatively, a Skype call may be scheduled for two people in different timezones at 4pm (in one person's timezone) on a specified date though the 'location' of the event is simply 'office' which means two different places in different timezones.

I wonder the following design is going to work for this application:

  1. On the client, it asks user to input the local date and time and specify the timezone local to the event.

  2. On the server, it converts the local date and time with the provided timezone into UTC timestamp, and store this timestamp only.

  3. When a client retrieves these details, it receives the UTC timestamp only and converts it into local time in the same timezone as the client's current timezone. The client's current timezone is determined by the current system timezone setting, which I think is automatically adjusted based on the client's location (of course, assuming the client is connected to a mobile network).

My main motivations for this design are:

  1. UTC is an absolute and universal time standard, and you can convert to/from it from/to any timezone.

  2. Users only care about the local date and time in the timezone they are currently in.

Is this a feasible design? If not, what specific scenarios would break the application or severely affect user experience? Critiques welcome.

2

There are 2 answers

0
Jon Skeet On BEST ANSWER

For a single event, knowing the UTC instant on which it occurs is usually enough, so long as you have the right UTC instant (see later).

For repeated events, you need to know the time zone in which it repeats... not just the UTC offset, but the actual time zone. For example, if I schedule a weekly meeting at 5pm in Europe/London with colleagues in America/Los_Angeles, then for most of the year it will occur at 9am for them... but for a couple of weeks in the year it will occur at 8am and for a couple of weeks in the year it will occur at 10am, due to differences in when DST is observed.

Even for a single event, you might want to consider what happens if time zone rules change. Suppose I schedule a meeting for 4pm on March 20th 2018, in the Europe/London time zone. Currently that will occur with a UTC offset of 0... but suppose between now and the meeting, the time zone rules change to bring British Summer Time in one hour earlier. If I've written it in my diary as 4pm, I probably don't want the software to think that it's actually at 5pm because that's the UTC instant we originally predicted.

We don't know your exact application requirements, but the above situations at least provide an argument for potentially storing the local time and time zone instead of the UTC instant... but you'll also need to work out what to do if the local time ends up being skipped or being ambiguous due to DST changes. (When the clocks fall back, some local times occur twice. When the clocks skip forward, some local times are skipped. A time that was unambiguous may become invalid or ambiguous if the rules change between the original planning time and the actual event. You should probably account for this in your design.)

0
Sandman On

To keep it simple, my answers are:

  • Timezone info is redundant if you want to define a single moment. A UTC/Unix timestamp completely defines a moment.
  • Your design seems feasible but on point 2: i would convert to the UTC/Unix timestamp on the client-side and already give this timestamp in its final form to the server. Reason: the client-side already has the info necessary to convert (see this time-keeping client-server-db architecture example - it works based exactly on the principles you describe).

  • One possible problem (as described by Jon Skeet in his answer) are recurring events, but this should be reflected in the way you model time. The difference between recurring events and fixed events is that the latter completely define a moment (like a UTC/Unix timestamp) while the first are only a 'function' which can be applied to the current time to get the next trigger time of the recurring event. But this might entirely be a different problem than what you ask - in any case, somehow distinguishing between recurring events (if you need them) and fixed events in your model is a good idea.

  • One decision to make is: PULL or PUSH? Or both? Do you want the server to be able to send emails for example, when an event comes to pass? Or do you want client-side alerts only when your client-side app is running? The answers to these questions will help you come towards a design suitable for you.