Sha256: 9b579e8916410de3c7c077cd158177a8547a3ed1e2eaf6cbf18ac1e8a01cff6a

Contents?: true

Size: 702 Bytes

Versions: 11

Compression:

Stored size: 702 Bytes

Contents

module CassandraObject
  module Types
    class TimeType
      # lifted from the implementation of Time.xmlschema and simplified
      REGEX = /\A\s*
                (-?\d+)-(\d\d)-(\d\d)
                T
                (\d\d):(\d\d):(\d\d)
                (\.\d*)?
                (Z|[+-]\d\d:\d\d)?
                \s*\z/ix

      def encode(time)
        raise ArgumentError.new("#{self} requires a Time") unless time.kind_of?(Time)
        time.xmlschema(6)
      end

      def decode(str)
        return nil if str.empty?
        raise ArgumentError.new("Cannot convert #{str} into a Time") unless str.kind_of?(String) && str.match(REGEX)
        Time.xmlschema(str)
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
gotime-cassandra_object-2.5.0 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-2.4.2 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-2.4.1 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-2.4.0 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-2.3.6 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-2.3.5 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-2.3.4 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-2.3.3 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-2.3.2 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-2.3.1 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-2.3.0 lib/cassandra_object/types/time_type.rb