Class: CassandraModel::DatetimeType

Inherits:
Object
  • Object
show all
Defined in:
lib/cassandra-model/types.rb

Class Method Summary collapse

Class Method Details

.dump(v) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/cassandra-model/types.rb', line 53

def self.dump(v)
  ret = nil
  if !v.blank?
    case v
      when String
        if v.size == 8
          ret = Cassandra::Long.new(v)
        else
          ret = Cassandra::Long.new(::Time.strptime(v, '%FT%T%z').utc.to_i)
        end
      when Cassandra::Long
        ret =v
      when Time
        ret = Cassandra::Long.new(v.utc.to_i)
      when DateTime
        ret = Cassandra::Long.new(v.to_time.utc.to_i)
    end
  end
  ret
end

.load(v) ⇒ Object



74
75
76
# File 'lib/cassandra-model/types.rb', line 74

def self.load(v)
  !v.blank? && ::Time.at(v.to_i)
end