From 04077c527d2fbda34126f250f42a720049af7ccf Mon Sep 17 00:00:00 2001 From: Vadim Henb Date: Mon, 9 Dec 2024 14:31:42 +0300 Subject: [PATCH] [requif/issues #3] Fix specs --- lib/reqif/high_precision_date_time.rb | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/reqif/high_precision_date_time.rb b/lib/reqif/high_precision_date_time.rb index cec11b6..c935f70 100644 --- a/lib/reqif/high_precision_date_time.rb +++ b/lib/reqif/high_precision_date_time.rb @@ -2,15 +2,18 @@ module Reqif class HighPrecisionDateTime < Lutaml::Model::Type::DateTime + def self.serialize(value) + return nil if value.nil? - # The format looks like this `2012-04-07T01:51:37.112+02:00` - def self.from_xml(xml_string) - ::DateTime.parse(xml_string) + cast(value)&.iso8601(8) + end + + def to_json + value.to_time.iso8601(8) end - # The %L adds milliseconds to the time def to_xml - value.strftime("%Y-%m-%dT%H:%M:%S.%L99999%:z") + value.to_time.iso8601(8) end end end