Sha256: b633a8006366e1c8ab10f618e440c3009d67ee4033b116cc0e166b4f105cc471

Contents?: true

Size: 478 Bytes

Versions: 7

Compression:

Stored size: 478 Bytes

Contents

module CassandraObject
  module Types
    class DateType < BaseType
      FORMAT = '%Y-%m-%d'
      REGEX = /\A\d{4}-\d{2}-\d{2}\Z/

      def encode(value)
        raise ArgumentError.new("#{value.inspect} is not a Date") unless value.kind_of?(Date)
        value.strftime(FORMAT)
      end

      def decode(str)
        return nil if str.empty?
        Date.parse(str)
      end

      def wrap(record, name, value)
        value.to_date if value
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
gotime-cassandra_object-4.12.2 lib/cassandra_object/types/date_type.rb
gotime-cassandra_object-4.12.1 lib/cassandra_object/types/date_type.rb
gotime-cassandra_object-4.12.0 lib/cassandra_object/types/date_type.rb
gotime-cassandra_object-4.11.6 lib/cassandra_object/types/date_type.rb
gotime-cassandra_object-4.11.5 lib/cassandra_object/types/date_type.rb
gotime-cassandra_object-4.11.4 lib/cassandra_object/types/date_type.rb
gotime-cassandra_object-4.11.3 lib/cassandra_object/types/date_type.rb