# HG changeset patch # User sam # Date 1743608508 -25200 # Node ID cfec585882ce6a6a44fcdea13b6c844998296d9b # Parent 63364723d4608d8f04d47fe22b7a507c0b08bb39 add: support to store times with timezones (uses ref, which we usually do not serialize atm) diff -r 63364723d460 -r cfec585882ce semicongine/storage.nim --- a/semicongine/storage.nim Wed Apr 02 00:49:02 2025 +0700 +++ b/semicongine/storage.nim Wed Apr 02 22:41:48 2025 +0700 @@ -117,6 +117,9 @@ proc writeValue[T](s: Stream, value: T) +proc writeTimeValue[T](s: Stream, value: T) = + s.write(value.toTime().toUnixFloat().float64) + proc writeNumericValue[T](s: Stream, value: T) = s.write(value) @@ -139,7 +142,9 @@ writeValue(s, value) proc writeValue[T](s: Stream, value: T) = - when distinctBase(T) is SomeOrdinal or T is SomeFloat: + when distinctBase(T) is DateTime: + writeTimeValue[T](s, value) + elif distinctBase(T) is SomeOrdinal or T is SomeFloat: writeNumericValue[T](s, value) elif distinctBase(T) is seq: writeSeqValue[T](s, value) @@ -175,6 +180,11 @@ proc loadValue[T](s: Stream): T +proc loadTimeValue[T](s: Stream): T = + var t: float64 + read(s, t) + fromUnixFloat(t).utc() + proc loadNumericValue[T](s: Stream): T = read(s, result) @@ -205,7 +215,9 @@ value = loadValue[typeof(value)](s) proc loadValue[T](s: Stream): T = - when distinctBase(T) is SomeOrdinal or distinctBase(T) is SomeFloat: + when distinctBase(T) is DateTime: + loadTimeValue[T](s) + elif distinctBase(T) is SomeOrdinal or distinctBase(T) is SomeFloat: loadNumericValue[T](s) elif distinctBase(T) is seq: loadSeqValue[T](s)