Sha256: 24a9399913546ab876acfbe7f92e714531c3ba1c8a2c5fc26015fd8aad1384ef

Contents?: true

Size: 763 Bytes

Versions: 117

Compression:

Stored size: 763 Bytes

Contents

module CassandraObject
  module Types
    module 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
      module_function :encode

      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
      module_function :decode
    end
  end
end

Version data entries

117 entries across 117 versions & 2 rubygems

Version Path
sessionm-cassandra_object-2.3.9 lib/cassandra_object/types/time_type.rb
sessionm-cassandra_object-2.3.8 lib/cassandra_object/types/time_type.rb
sessionm-cassandra_object-2.3.6 lib/cassandra_object/types/time_type.rb
sessionm-cassandra_object-2.3.5 lib/cassandra_object/types/time_type.rb
sessionm-cassandra_object-2.3.4 lib/cassandra_object/types/time_type.rb
sessionm-cassandra_object-2.3.3 lib/cassandra_object/types/time_type.rb
sessionm-cassandra_object-2.3.2 lib/cassandra_object/types/time_type.rb
sessionm-cassandra_object-2.3.1 lib/cassandra_object/types/time_type.rb
sessionm-cassandra_object-2.3.0 lib/cassandra_object/types/time_type.rb
sessionm-cassandra_object-2.2.55 lib/cassandra_object/types/time_type.rb
sessionm-cassandra_object-2.2.54 lib/cassandra_object/types/time_type.rb
sessionm-cassandra_object-2.2.53 lib/cassandra_object/types/time_type.rb
sessionm-cassandra_object-2.2.52 lib/cassandra_object/types/time_type.rb
sessionm-cassandra_object-2.2.51 lib/cassandra_object/types/time_type.rb
sessionm-cassandra_object-2.2.50 lib/cassandra_object/types/time_type.rb
sessionm-cassandra_object-2.2.49 lib/cassandra_object/types/time_type.rb
sessionm-cassandra_object-2.2.48 lib/cassandra_object/types/time_type.rb
sessionm-cassandra_object-2.2.47 lib/cassandra_object/types/time_type.rb
sessionm-cassandra_object-2.2.46 lib/cassandra_object/types/time_type.rb
sessionm-cassandra_object-2.2.45 lib/cassandra_object/types/time_type.rb