Sha256: 8adb18c3da9a7f177cc6f715ad27a66d5f37df8ecf8b322506f619248786df84
Contents?: true
Size: 762 Bytes
Versions: 1
Compression:
Stored size: 762 Bytes
Contents
module CassandraObject class 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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
gotime-cassandra_object-2.1.0 | lib/cassandra_object/types/time_type.rb |