Class: Lutaml::Model::Type::TimeWithoutDate
- Defined in:
- lib/lutaml/model/type/time_without_date.rb
Constant Summary
Constants inherited from Value
Instance Attribute Summary
Attributes inherited from Value
Class Method Summary collapse
-
.cast(value, _options = {}) ⇒ Object
TODO: we probably want to do something like this because using Time.parse will set the date to today.
-
.default_xsd_type ⇒ String
XSD type for TimeWithoutDate.
- .serialize(value) ⇒ Object
Methods inherited from Value
format_type_serializer_for, from_format, #initialize, #initialized?, register_format_to_from_methods, register_format_type_serializer, #to_s
Methods included from Xml::Type::Configurable
Methods included from UninitializedClassGuard
Constructor Details
This class inherits a constructor from Lutaml::Model::Type::Value
Class Method Details
.cast(value, _options = {}) ⇒ Object
TODO: we probably want to do something like this because using Time.parse will set the date to today.
time = ::Time.parse(value.to_s) ::Time.new(1, 1, 1, time.hour, time.min, time.sec)
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/lutaml/model/type/time_without_date.rb', line 15 def self.cast(value, = {}) return super if Utils.uninitialized?(value) return nil if value.nil? case value when ::Time then value else # Check if input has invalid hour format (24:00:00 or higher) if value.to_s =~ /^(\d+):/ hour = ::Regexp.last_match(1).to_i return nil if hour >= 24 end ::Time.parse(value.to_s) end rescue ArgumentError nil end |
.default_xsd_type ⇒ String
XSD type for TimeWithoutDate
44 45 46 |
# File 'lib/lutaml/model/type/time_without_date.rb', line 44 def self.default_xsd_type "xs:time" end |
.serialize(value) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/lutaml/model/type/time_without_date.rb', line 34 def self.serialize(value) return nil if value.nil? value = cast(value) value.strftime("%H:%M:%S") # Format as HH:MM:SS end |