Sha256: 45be699d3e48ecf460b92afaddfc3815dd0f69dfeef4988c54ef305a5a288b59

Contents?: true

Size: 505 Bytes

Versions: 11

Compression:

Stored size: 505 Bytes

Contents

module CassandraObject
  module Types
    class 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

      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
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
gotime-cassandra_object-2.5.0 lib/cassandra_object/types/date_type.rb
gotime-cassandra_object-2.4.2 lib/cassandra_object/types/date_type.rb
gotime-cassandra_object-2.4.1 lib/cassandra_object/types/date_type.rb
gotime-cassandra_object-2.4.0 lib/cassandra_object/types/date_type.rb
gotime-cassandra_object-2.3.6 lib/cassandra_object/types/date_type.rb
gotime-cassandra_object-2.3.5 lib/cassandra_object/types/date_type.rb
gotime-cassandra_object-2.3.4 lib/cassandra_object/types/date_type.rb
gotime-cassandra_object-2.3.3 lib/cassandra_object/types/date_type.rb
gotime-cassandra_object-2.3.2 lib/cassandra_object/types/date_type.rb
gotime-cassandra_object-2.3.1 lib/cassandra_object/types/date_type.rb
gotime-cassandra_object-2.3.0 lib/cassandra_object/types/date_type.rb