Shaitan00 Posted November 3, 2005 Posted November 3, 2005 Oddly enough I was sitting at home writting this application to calculate the Elapsed time worked on a project when all of a sudden the clock went back an hour (daylight savings time), and that got me to thinking.... So, the way it works, when a user presses start I write the timestamp (datetime), when they pause I calculate now-start and save that value as Elapsed, then they can restart/unpause, and finally End. Now I realized something, if they have a project running when we go over a daylight saving time period they will loose/gain an hour, this is unacceptable because I use this process to calcuate the hours worked on a project for billing customers - therefore it must be accurate. Problem is I can't seem to find a way to fix this, only idea I had was to somehow check every X minutes to see if we are before a daylight savings time, forcefully pause all jobs (thus saving the elapsed time) and then forcefully restarting them after the switch, however I find this greatly inefficient and I don't even know how to code it. Also, there is the problem about determining the daylight savings time, hardcoding it is not really an option seeing as it can change (as it will for my end of the world in a few years), is there a way to get this information programatically? Can Windows supply it somehow? Anyways, hopefully that explains my problem - and the more I think about it the bigger it sounds... Any hints/help would be greatly appreciated. thanks Quote
Administrators PlausiblyDamp Posted November 3, 2005 Administrators Posted November 3, 2005 If you want absolute time differences then use the UTC time property of the DateTime object rather than the local time which may be influenced by DST. If you need to programatically access this look under System.Globalisation, you should find classes like System.Globalization.DaylightTime and System.Globalization. which will be of use. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Shaitan00 Posted November 5, 2005 Author Posted November 5, 2005 Amazing idea - one question, how do I convert the UTC DateTime to the correct local time on the users machine? I mean, I was thinking of just storing the START and END time as UTC (in the DB) and when the user loads the program have it modify the UTC -> Local Time (somehow???) to display it in the correct TimeZone. Using UTC removes the need to handle Daylight Savings Time (right?). This would be a better method then using the System.Globalization.DayLightSavingTime right? Unless you can recommend a more efficient method. Quote
Administrators PlausiblyDamp Posted November 5, 2005 Administrators Posted November 5, 2005 The DateTime class provides methods / properties for getting details in UTC, check the intellisense and you should easily find them. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.