One of the tasks I do at work every day is to pull the latest updates of the several source repositories I have checked out and view the changes. It keeps me up to date. One particular change caught my eye:
>
```
r4245 | XXXXXXX | 2014-03-12 11:36:38 -0400 (Wed, 12 Mar 2014) | 1 line
update for Daylight Savings Time
```
Really?
We have networked computers, running the latest operating systems, and we're still manually updating the time zone? (Okay, to be fair, this is code to test code, but still …)
Now granted, getting the time zone information in a portable manner is not always that easy. In C, there is no direct way to obtain the timezone, and thus, you need to do something like:
>
```
time_t now;
struct tm slocal;
struct tm sgmt;
time_t local;
time_t gmt;
double zone;
now = time(NULL);
slocal = *localtime(&now);
sgmt = *gmtime(&now);
local = mktime(&slocal);
gmt = mktime(&sgmt);
zone = difftime(local,gmt);
```
zone is the number of seconds from UT (Universal Time); divide by 3,600 to get the time zone (well, the quotient is the timezone, the remainder needs to be multiplied by 3,600 then divided by 60 to get the minutes).
And that's just to be “portable”—POSIX (read: most modern Unix systems these days) include a way to obtain the timezone more directly, just call tzset() and the global variables extern char *tzname[2] and extern long timezone are initialized.
You don't need to hardcode a timezone.
But I was curious, and I checked the log for the file in question:
>
```
r4245 | XXXXXXX | 2014-03-12 11:36:38 -0400 (Wed, 12 Mar 2014) | 1 line
update for Daylight Savings Time
------------------------------------------------------------------------
r3889 | XXXXXXX | 2013-11-04 13:21:02 -0500 (Mon, 04 Nov 2013) | 1 line
Support for XXXXXXXX. Changed the Manual UTC offset constant to reflect DST
change. Ran a couple tests and they were all passing after making the
change.
------------------------------------------------------------------------
r3245 | XXXXXXX | 2013-03-07 15:20:00 -0500 (Thu, 07 Mar 2013) | 1 line
Fixing utc offset for day-light savings shift.
------------------------------------------------------------------------
r2923 | XXXXXXX | 2012-11-05 11:30:04 -0500 (Mon, 05 Nov 2012) | 1 line
Adjust time offset value for daylight savings.
------------------------------------------------------------------------
r1827 | XXXXXXX | 2012-03-12 12:08:41 -0400 (Mon, 12 Mar 2012) | 1 line
Update for daylight savings time.
------------------------------------------------------------------------
r1154 | XXXXXXX | 2011-11-14 19:28:32 -0500 (Mon, 14 Nov 2011) | 1 line
Remove unneeded constants.
------------------------------------------------------------------------
r1091 | XXXXXXX | 2011-11-04 19:32:51 -0400 (Fri, 04 Nov 2011) | 1 line
Adjusting UTC_OFFSET for day light savings.
```
And the punchline? The comment above the timezone constant:
>
```
// UTC Offset (for now until this can be automated)
```
which was added in April of 2011.