Sha256: 8939a746b49ffa11b70ff7b4501029f6d624f55656be55cba66af30fb02f848b

Contents?: true

Size: 713 Bytes

Versions: 28

Compression:

Stored size: 713 Bytes

Contents

module CassandraObject
  module Types
    class TimeType < BaseType
      # 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

28 entries across 28 versions & 1 rubygems

Version Path
gotime-cassandra_object-2.9.2 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-2.9.1 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-2.9.0 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-2.8.6 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-2.8.5 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-2.8.4 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-2.8.3 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-2.8.2 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-2.8.1 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-2.8.0 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-2.7.12 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-2.7.11 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-2.7.10 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-2.7.9 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-2.7.8 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-2.7.7 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-2.7.6 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-2.7.5 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-2.7.4 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-2.7.3 lib/cassandra_object/types/time_type.rb