Sha256: 7090d11bedb05b3470d089af743aeba5ac6977880ba0852fd01910d5a67bb36d

Contents?: true

Size: 575 Bytes

Versions: 4

Compression:

Stored size: 575 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 unless str && str.match(TimeType::REGEX)
        Time.xmlschema(str).in_time_zone
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
gotime-cassandra_object-4.9.0 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-4.8.1 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-4.8.0 lib/cassandra_object/types/time_type.rb
gotime-cassandra_object-4.7.3 lib/cassandra_object/types/time_type.rb