Sha256: 7a296fc10373785cccb1fd6495e6e25d5067d8310d6891cee0cf979b35daeb93

Contents?: true

Size: 668 Bytes

Versions: 20

Compression:

Stored size: 668 Bytes

Contents

module CassandraObject
  module Types
    class TimeType < BaseType
      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.utc.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(TimeType::REGEX)
        Time.xmlschema(str).in_time_zone
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
gotime-cassandra_object-2.11.7 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-2.11.6 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-2.11.5 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-2.11.4 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-2.11.3 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-2.11.2 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-2.11.1 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-2.11.0 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-2.10.11 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-2.10.10 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-2.10.9 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-2.10.8 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-2.10.7 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-2.10.6 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-2.10.5 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-2.10.4 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-2.10.3 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-2.10.2 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-2.10.1 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-2.10.0 lib/cassandra_object/types/time_type.rb