views:

525

answers:

9

I'm developing an international software that act as a simple project management software and I'm facing a problem. This problem is about date/hour and time zone.
When a message is sent from one time zone to another time zone I can store the UTC (GMT) time in my database and then have it displayed differently according to the user's time zone. But this can't be done when I only work with date.
If I say a task is due to the 21st of March. Should I consider that this date can be 20 or 22 in some other countries ? What are your advices on this problem ?

+1  A: 

You won't be able to achieve what you are trying to do without storing the exact time. You simply don't have enough information.

David Segonds
+2  A: 

When you don't have a time, assume that the time is the end of business in the main locale for the application, then translate that time as you would any other time. An alternative would be assuming end of the business day in local time and adjust that to UTC. Everyone using the application would need to understand whatever default time assumption you make when the time is not specified. Coordinating to the main office may be best in a large enterprise whereas coordinating to local time may be best in highly decentralized environments where the local context is equally important.

tvanfosson
The end of the day in UTC would be counterintuitive to the person setting the due date (unless of course, they're already living in ZULU time).
officemonkey
@officemonkey -- that's why it wasn't my first suggestion. I suppose it may be better to choose the end of the business day in local time and adjust that for everyone else. That probably makes the most sense for the person entering the task. I'll adjust the answer.
tvanfosson
+1  A: 

The easiest solution would be just to display as the same date for everyone. The deadline would then effectively be midnight in the latest timezone.

Otherwise, decide what the default time of the deadline should be in the timezone the task was created in, e.g. 21st March 17:00 EST or 22nd March 00:00 EST and display that in the local timezone. The timezone difference will then push it into the previous day or next day accordingly for the viewer.

AdamRalph
+3  A: 

Let's say a user in New York sets a due date for a project as "anytime on Monday 26 January". That means "anytime from 0600 Monday 26 January to 0600 Tuesday 27 January" in Brussels and "anytime from 2000 Sunday 25 January to 2000 Monday 26 January" in L.A.

So completing the task at 2100 on Monday 26 is fine in Brussels and N.Y., but too late in L.A.

One possible work around is never just work with the date. If the time is not specified, either set it for 0000 hrs or 2400 hrs on the date specified in the timezone of the user.

The users may have to deal with strange due dates/times, but speaking as someone who used to work internationally, it kinda goes with the territory.

officemonkey
A: 

If you have a single instance of a DB, I would store all dates in the datetime timestamp of your DB server. If you are timestamping rows, consider GetDate() in T-SQL or as default value of the timestamped date column. Then you have your single reference point for all times. Consider UTC format there.

Then, all clients accessing the date do their own conversion into "local time" , which can be interpreted by things like : user preferences, date time stamp on client computer, etc.

Without knowing more, it hard to say exactly what the resolution is.

Ash Machine
A: 

SQL 2008 allows for a Date datatype that does not have any time value associated with it. That allows someone to say I need this done by this Date, but I don't care if it is +/- several hours. If the date selected is 1/1/2009 but it happens on 1/2/2009 at 2AM their time, they probably don't care.

When the user needs something done by a specific date and time, like close of business on 1/1/2009 then you need to store it in a DateTime as UTC and convert it to local time client-side.

This will take much of the complexity out of indicating when something is completed, it'll either be completed near a specific day or by a specific time.

DavGarcia
A: 

If you aren't storing the minutes and seconds you have to assume that the date being entered is the desired date and not to any adjustments for GMT. Just put it in the database as is. The people on the west coast will have to assume that the due date is the same regardless of where you are in the world. If you want to adjust for time zones, you'll have to collect more information, like hour, minutes, and seconds.

jjriv
A: 

Your solution depends on your application and requirements.

I'd first store UTC + offset in your data structures, so it's easy to display for any timezone.

Most likely if a task or meeting is due at 12pm on 21/March in London then it will occur at 2130 on 21/March in Adelaide (+0930), but that is an application requirement not any sinister timezone related standard.

If you want the ultimate in flexibility, add a flag that can make the even due simultaneously in every timezone or at the same time no matter where you are (staggered) and show the event accordingly.

Adam Hawes
A: 

You might want to store the date in a from that is timezone aware. This will help you in your calculations. SQL Server 2008 for instance supports a datetimeoffset that does precisely this. Alternatively if you're using SQL 2005 with a bit of effort you can write your own SQL CLR data type to support this.

Conrad