Skip to content

Commit

Permalink
Remove std.datetime.DTRebindable
Browse files Browse the repository at this point in the history
  • Loading branch information
9rnsr committed Aug 24, 2011
1 parent cf62cd2 commit 5395df0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 89 deletions.
104 changes: 16 additions & 88 deletions std/datetime.d
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ import std.stdio;
import std.string;
import std.system;
import std.traits;
import std.typecons;

version(Windows)
{
Expand Down Expand Up @@ -604,7 +605,7 @@ public:
immutable adjustedTime = dateDiff + todDiff + fracHNSecs;
immutable standardTime = _timezone.tzToUTC(adjustedTime);

this(standardTime, _timezone.get);
this(standardTime, _timezone);
}
catch(Exception e)
{
Expand Down Expand Up @@ -657,7 +658,7 @@ public:
immutable adjustedTime = (date - Date(1, 1, 1)).total!"hnsecs";
immutable standardTime = _timezone.tzToUTC(adjustedTime);

this(standardTime, _timezone.get);
this(standardTime, _timezone);
}
catch(Exception e)
assert(0, "Date's constructor through when it shouldn't have.");
Expand Down Expand Up @@ -725,7 +726,7 @@ public:
ref SysTime opAssign(const ref SysTime rhs) pure nothrow
{
_stdTime = rhs._stdTime;
_timezone = rhs._timezone.get;
_timezone = rhs._timezone;

return this;
}
Expand All @@ -737,7 +738,7 @@ public:
ref SysTime opAssign(SysTime rhs) pure nothrow
{
_stdTime = rhs._stdTime;
_timezone = rhs._timezone.get;
_timezone = rhs._timezone;

return this;
}
Expand Down Expand Up @@ -2092,7 +2093,7 @@ assert(SysTime(DateTime(-7, 4, 5, 7, 45, 2)).day == 5);
+/
@property immutable(TimeZone) timezone() const pure nothrow
{
return _timezone.get;
return _timezone;
}


Expand Down Expand Up @@ -5893,7 +5894,7 @@ assert(st4 == SysTime(DateTime(2010, 1, 1, 0, 0, 0),
(is(Unqual!D == Duration) ||
is(Unqual!D == TickDuration)))
{
SysTime retval = SysTime(this._stdTime, this._timezone.get);
SysTime retval = SysTime(this._stdTime, this._timezone);

static if(is(Unqual!D == Duration))
immutable hnsecs = duration.total!"hnsecs";
Expand Down Expand Up @@ -7306,7 +7307,7 @@ assert(SysTime(DateTime(2000, 6, 4, 12, 22, 9),

immutable newDaysHNSecs = convert!("days", "hnsecs")(newDays);

auto retval = SysTime(this._stdTime, this._timezone.get);
auto retval = SysTime(this._stdTime, this._timezone);
retval.adjTime = newDaysHNSecs + theTimeHNSecs;

return retval;
Expand Down Expand Up @@ -7706,7 +7707,7 @@ assert(!SysTime(DateTime(-2010, 1, 1, 2, 2, 2)).isAD);
SysTime opCast(T)() const pure nothrow
if(is(Unqual!T == SysTime))
{
return SysTime(_stdTime, _timezone.get);
return SysTime(_stdTime, _timezone);
}


Expand Down Expand Up @@ -8260,7 +8261,7 @@ assert(SysTime.fromISOString("20100704T070612+8:00") ==
{
auto dateTime = DateTime.fromISOString(dateTimeStr);
auto fracSec = fracSecFromISOString(fracSecStr);
DTRebindable!(immutable TimeZone) parsedZone;
Rebindable!(immutable TimeZone) parsedZone;

if(zoneStr.empty)
parsedZone = LocalTime();
Expand All @@ -8269,7 +8270,7 @@ assert(SysTime.fromISOString("20100704T070612+8:00") ==
else
parsedZone = SimpleTimeZone.fromISOString(zoneStr);

auto retval = SysTime(dateTime, fracSec, parsedZone.get);
auto retval = SysTime(dateTime, fracSec, parsedZone);

if(tz !is null)
retval.timezone = tz;
Expand Down Expand Up @@ -8458,7 +8459,7 @@ assert(SysTime.fromISOExtString("2010-07-04T07:06:12+8:00") ==
{
auto dateTime = DateTime.fromISOExtString(dateTimeStr);
auto fracSec = fracSecFromISOString(fracSecStr);
DTRebindable!(immutable TimeZone) parsedZone;
Rebindable!(immutable TimeZone) parsedZone;

if(zoneStr.empty)
parsedZone = LocalTime();
Expand All @@ -8467,7 +8468,7 @@ assert(SysTime.fromISOExtString("2010-07-04T07:06:12+8:00") ==
else
parsedZone = SimpleTimeZone.fromISOString(zoneStr);

auto retval = SysTime(dateTime, fracSec, parsedZone.get);
auto retval = SysTime(dateTime, fracSec, parsedZone);

if(tz !is null)
retval.timezone = tz;
Expand Down Expand Up @@ -8670,7 +8671,7 @@ assert(SysTime.fromSimpleString("2010-Jul-04 07:06:12+8:00") ==
{
auto dateTime = DateTime.fromSimpleString(dateTimeStr);
auto fracSec = fracSecFromISOString(fracSecStr);
DTRebindable!(immutable TimeZone) parsedZone;
Rebindable!(immutable TimeZone) parsedZone;

if(zoneStr.empty)
parsedZone = LocalTime();
Expand All @@ -8679,7 +8680,7 @@ assert(SysTime.fromSimpleString("2010-Jul-04 07:06:12+8:00") ==
else
parsedZone = SimpleTimeZone.fromISOString(zoneStr);

auto retval = SysTime(dateTime, fracSec, parsedZone.get);
auto retval = SysTime(dateTime, fracSec, parsedZone);

if(tz !is null)
retval.timezone = tz;
Expand Down Expand Up @@ -8860,7 +8861,7 @@ private:


long _stdTime;
DTRebindable!(immutable TimeZone) _timezone;
Rebindable!(immutable TimeZone) _timezone;
}


Expand Down Expand Up @@ -33178,79 +33179,6 @@ string numToString(long value) pure nothrow
}


/+
A temporary replacement for Rebindable!() until bug http://d.puremagic.com/issues/show_bug.cgi?id=4977
is fixed.
+/
template DTRebindable(T) if (is(T == class) || is(T == interface) || isArray!(T))
{
static if(!is(T X == const(U), U) && !is(T X == immutable(U), U))
{
alias T DTRebindable;
}
else static if(isArray!(T))
{
alias const(ElementType!(T))[] DTRebindable;
}
else
{
struct DTRebindable
{
private union
{
T original;
U stripped;
}

void opAssign(T another) pure nothrow
{
stripped = cast(U) another;
}

void opAssign(DTRebindable another) pure nothrow
{
stripped = another.stripped;
}

static if(is(T == const U))
{
// safely assign immutable to const
void opAssign(DTRebindable!(immutable U) another) pure nothrow
{
stripped = another.stripped;
}
}

this(T initializer) pure nothrow
{
opAssign(initializer);
}

@property ref T get() pure nothrow
{
return original;
}

@property ref T get() const pure nothrow
{
return original;
}

alias get this;

T opDot() pure nothrow
{
return original;
}

T opDot() const pure nothrow
{
return original;
}
}
}
}

version(unittest)
{
//Variables to help in testing.
Expand Down
2 changes: 1 addition & 1 deletion std/traits.d
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/
module std.traits;
import std.typetuple;
import std.typecons : Rebindable;
import std.typecons;
import core.vararg;

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::://
Expand Down

0 comments on commit 5395df0

Please sign in to comment.