Skip to content

Commit

Permalink
Merge pull request #124 from denizzzka/fix_122_attempt_two
Browse files Browse the repository at this point in the history
Another fix for #122
  • Loading branch information
denizzzka authored Nov 10, 2018
2 parents 96df408 + 18515d2 commit 848d438
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
19 changes: 18 additions & 1 deletion src/dpq2/conv/from_d_types.d
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,10 @@ if (is(Unqual!T == TimeStamp) || is(Unqual!T == TimeStampUTC))
);
}

// Wikipedia's magic
private auto modJulianDayForIntYear(const int year, const ubyte month, const short day) pure
{
// Wikipedia magic:

const a = (14 - month) / 12;
const y = year + 4800 - a;
const m = month + a * 12 - 3;
Expand Down Expand Up @@ -358,6 +359,22 @@ unittest
assert(v.as!DateTime == d);
}

unittest
{
// Nullable!DateTime
import std.typecons : nullable;
auto d = nullable(DateTime(2018, 2, 20, 1, 2, 3));
auto v = toValue(d);

assert(v.oidType == OidType.TimeStamp);
assert(v.as!(Nullable!DateTime) == d);

d.nullify();
v = toValue(d);
assert(v.oidType == OidType.TimeStamp);
assert(v.as!(Nullable!DateTime).isNull);
}

unittest
{
// TimeOfDay: '14:29:17'
Expand Down
3 changes: 2 additions & 1 deletion src/dpq2/oids.d
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ OidType detectOidTypeFromNative(T)()

private OidType detectOidTypeNotCareAboutNullable(T)()
{
import std.datetime.date : StdDate = Date, TimeOfDay;
import std.datetime.date : StdDate = Date, TimeOfDay, DateTime;
import std.datetime.systime : SysTime;
import std.traits : Unqual;
import std.uuid : StdUUID = UUID;
Expand All @@ -188,6 +188,7 @@ private OidType detectOidTypeNotCareAboutNullable(T)()
static if(is(UT == double)){ return Float8; } else
static if(is(UT == StdDate)){ return Date; } else
static if(is(UT == TimeOfDay)){ return Time; } else
static if(is(UT == DateTime)){ return TimeStamp; } else
static if(is(UT == SysTime)){ return TimeStampWithZone; } else
static if(is(UT == dpq2.conv.time.TimeStamp)){ return TimeStamp; } else
static if(is(UT == dpq2.conv.time.TimeStampUTC)){ return TimeStampWithZone; } else
Expand Down

0 comments on commit 848d438

Please sign in to comment.