Actions
Bug #19253
closed`Time` objects can't be efficiently and precisely serialized without Marshal
Description
Context¶
In our application we try to avoid to use Marshal
for serializing cache payloads because we want to be strict on what types we allow to be cached. (Full context in this post).
As such we need to be able to break Time
objects into a list of primitive types supported by our serialization format (msgpack).
Problem¶
Maybe I'm missing something, but I as far as I can tell Time
instance can't be recreated in the exact same state.
>> t = Time.now
=> 2022-12-23 09:44:05.693688 +0100
>> Time.at(t.sec, t.nsec, :nanosecond)
=> 1970-01-01 01:00:05.693688 +0100
>> t == Time.at(t.sec, t.nsec, :nanosecond)
=> false
>> t == Time.at(t.sec, t.subsec)
=> false
Additionally, Time
objects created with Time.now
have a String
as Time#zone
, and as far as I can tell that can't be reproduced either:
>> t = Time.now
=> 2022-12-23 09:46:22.452771 +0100
>> t.zone
=> "CET"
>> Time.at(t.sec, t.subsec, in: t.utc_offset).zone
=> nil
>> Time.at(t.sec, t.subsec, in: t.zone)
<internal:timev>:274:in `at': "+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: CET (ArgumentError)
>> Time.at(t.sec, t.subsec, in: TZInfo::Timezone.get(t.zone)).zone
=> #<TZInfo::DataTimezone: CET>
Actions
Like0
Like0Like0Like0Like0