Sha256: 1543ff5eaa5bb91721ec6c8a45c206a77e1933178cddac3ee5e252947730882e

Contents?: true

Size: 674 Bytes

Versions: 30

Compression:

Stored size: 674 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("#{time.inspect} is not 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

30 entries across 30 versions & 1 rubygems

Version Path
gotime-cassandra_object-4.5.1 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-4.5.0 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-4.4.5 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-4.4.4 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-4.4.3 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-4.4.0 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-4.3.2 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-4.3.1 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-4.3.0 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-4.2.2 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-4.2.0 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-4.1.0 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-4.0.2 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-4.0.1 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-4.0.0 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-3.0.5 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-3.0.4 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-3.0.3 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-3.0.2 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-3.0.1 lib/cassandra_object/types/time_type.rb