Sha256: 14e61e554746604a4c121e637e820049ac85613fd82282cc41a2cd0faf655372

Contents?: true

Size: 565 Bytes

Versions: 1

Compression:

Stored size: 565 Bytes

Contents

module CassandraObject
  class Types
    module DateType
      FORMAT = '%Y-%m-%d'
      REGEX = /\A\d{4}-\d{2}-\d{2}\Z/
      def encode(date)
        raise ArgumentError.new("#{self} requires a Date") unless date.kind_of?(Date)
        date.strftime(FORMAT)
      end
      module_function :encode

      def decode(str)
        return nil if str.empty?
        raise ArgumentError.new("Cannot convert #{str} into a Date") unless str.kind_of?(String) && str.match(REGEX)
        Date.strptime(str, FORMAT)
      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/date_type.rb