Skip to content

Commit

Permalink
Fix #122 -- toValue should support Nullable!DateTime
Browse files Browse the repository at this point in the history
  • Loading branch information
schveiguy committed Nov 9, 2018
1 parent 96df408 commit f713fab
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/dpq2/conv/from_d_types.d
Expand Up @@ -23,7 +23,12 @@ Value toValue(T)(T v)
if (is(T == Nullable!R, R) && !(isArrayType!(typeof(v.get))))
{
if (v.isNull)
return Value(ValueFormat.BINARY, detectOidTypeFromNative!T);
{
static if(is(T == Nullable!DateTime))
return Value(ValueFormat.BINARY, detectOidTypeFromNative!TimeStamp);
else
return Value(ValueFormat.BINARY, detectOidTypeFromNative!T);
}
else
return toValue(v.get);
}
Expand Down Expand Up @@ -358,6 +363,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

0 comments on commit f713fab

Please sign in to comment.