Skip to content

Commit

Permalink
std.datetime fixed so that it doesn't need the daylight variable on P…
Browse files Browse the repository at this point in the history
…osix.

It will still use daylight if it's there, but since FreeBSD doesn't have
it for some reason (in spite of the fact that the daylight variable is
part of Posix), we can't assume that it's there.

Also, now that tzname is in druntime, it has been removed from
std.datetime.

This should fix bug# 5616.
  • Loading branch information
jmdavis authored and andralex committed Feb 26, 2011
1 parent dbbccab commit 6dc1267
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions std/datetime.d
Expand Up @@ -28472,18 +28472,6 @@ private:
}


version(Posix)
{
//This should be in core.stdc.time, but it isn't, so
//we're declaring it here.
extern(C)
{
extern __gshared char* tzname[2];
extern __gshared int daylight;
}
}


/++
A TimeZone which represents the current local time zone on
the system running your program.
Expand Down Expand Up @@ -28685,7 +28673,25 @@ public:
@property override bool hasDST() const nothrow
{
version(Posix)
return cast(bool)(daylight);
{
static if(is(typeof(daylight)))
return cast(bool)(daylight);
else
{
try
{
auto currYear = (cast(Date)Clock.currTime()).year;
auto janOffset = SysTime(Date(currYear, 1, 4), this).stdTime -
SysTime(Date(currYear, 1, 4), UTC()).stdTime;
auto julyOffset = SysTime(Date(currYear, 7, 4), this).stdTime -
SysTime(Date(currYear, 7, 4), UTC()).stdTime;

return janOffset != julyOffset;
}
catch(Exception e)
assert(0, "Clock.currTime() threw.");
}
}
else version(Windows)
{
try
Expand Down Expand Up @@ -28715,6 +28721,9 @@ public:

setTZEnvVar("America/New_York");
assert(LocalTime().hasDST);

setTZEnvVar("UTC");
assert(!LocalTime().hasDST);
}
}
}
Expand Down

0 comments on commit 6dc1267

Please sign in to comment.