views:

157

answers:

3

I have a few places in the code where I need to use the TimeZone. I can get the timezone name using DateTime::TimeZone. Is it reasonable to put the timezone name in a constant? Or should it be in a variable?

+5  A: 

If the value can change, use a variable, of it is guaranteed to stay the same, use a constant.

For a timezone, the chance it will change is not big, but it is also not 0. The user can change the timezone and it would be nice if the program behaves accordingly.

Gamecat
Thanks for the answers.
Tom Feiner
Not to mention the Summer/Winter time changes
dsm
+3  A: 

I vote for variable. You could end up with different users in different timezones working with your application, even if you doubt that could ever happen. It happened to me a couple of years ago.

Tom
+2  A: 

Look at where the timezone is coming from. Is it the timezone of a city? Make it constant. Is it the timezone of the user? Make it variable - we users travel all the time, and we reset the timezone on our laptops so that Outlook scheduling will work correctly at the new location.

fenomas