Sha256: 78b9c59fd023d2b201afd5a784d135fea2eda0a9c20e13f537565a585dcf5b0a

Contents?: true

Size: 705 Bytes

Versions: 12

Compression:

Stored size: 705 Bytes

Contents

module Lutaml
  module Model
    module Type
      class Date < Value
        def self.cast(value)
          return nil if value.nil?

          case value
          when ::DateTime, ::Time
            value.to_date
          when ::Date
            value
          else
            ::Date.parse(value.to_s)
          end
        rescue ArgumentError
          nil
        end

        # xs:date format
        def self.serialize(value)
          return nil if value.nil?

          value&.iso8601
        end

        # This is to handle where Ruby's YAML safe_load does not handle
        # the Date/Time classes
        def to_yaml
          value&.iso8601.to_s
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
lutaml-model-0.5.4 lib/lutaml/model/type/date.rb
lutaml-model-0.5.3 lib/lutaml/model/type/date.rb
lutaml-model-0.5.2 lib/lutaml/model/type/date.rb
lutaml-model-0.5.1 lib/lutaml/model/type/date.rb
lutaml-model-0.5.0 lib/lutaml/model/type/date.rb
lutaml-model-0.4.0 lib/lutaml/model/type/date.rb
lutaml-model-0.3.30 lib/lutaml/model/type/date.rb
lutaml-model-0.3.29 lib/lutaml/model/type/date.rb
lutaml-model-0.3.28 lib/lutaml/model/type/date.rb
lutaml-model-0.3.27 lib/lutaml/model/type/date.rb
lutaml-model-0.3.26 lib/lutaml/model/type/date.rb
lutaml-model-0.3.25 lib/lutaml/model/type/date.rb