From b81d8fc5127bd493018fd799c34258f849321b48 Mon Sep 17 00:00:00 2001 From: Andrew Stewart Date: Sun, 7 Jun 2020 15:07:33 -0400 Subject: [PATCH 1/2] Fix Time struct Fixes https://github.com/Papierkorb/cannon/issues/4 --- src/cannon/core_ext.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cannon/core_ext.cr b/src/cannon/core_ext.cr index 037f395..7d00fb8 100644 --- a/src/cannon/core_ext.cr +++ b/src/cannon/core_ext.cr @@ -219,7 +219,7 @@ struct Time include Cannon::FastAuto def self.from_cannon_io(io) - new(Cannon.decode(io, Int64)) + utc(seconds: Cannon.decode(io, Int64), nanoseconds: 0) end end From 09b5801a65cf7638f2744ebdbdcb2b57bf4af511 Mon Sep 17 00:00:00 2001 From: Andrew Stewart Date: Sun, 7 Jun 2020 17:03:39 -0400 Subject: [PATCH 2/2] Update core_ext.cr Handle Time::Span, Time::Location, and Time's location and nanoseconds fields --- src/cannon/core_ext.cr | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/cannon/core_ext.cr b/src/cannon/core_ext.cr index 7d00fb8..1e74a86 100644 --- a/src/cannon/core_ext.cr +++ b/src/cannon/core_ext.cr @@ -216,10 +216,36 @@ struct Tuple(*T) end struct Time + def self.from_cannon_io(io) + new(seconds: Cannon.decode(io, Int64), nanoseconds: Cannon.decode(io, Int32), location: Cannon.decode(io, Location)) + end + + def to_cannon_io(io) + to_unix.to_cannon_io io + nanosecond.to_cannon_io io + location.to_cannon_io io + + io + end +end + +struct Time::Span include Cannon::FastAuto def self.from_cannon_io(io) - utc(seconds: Cannon.decode(io, Int64), nanoseconds: 0) + new(seconds: Cannon.decode(io, Int64), nanoseconds: 0) + end +end + +class Time::Location + def self.from_cannon_io(io) + load(Cannon.decode(io, String)) + end + + def to_cannon_io(io) + name.to_cannon_io io + + io end end