class Perpetuity::Postgres::TimestampValue
Attributes
time[R]
Public Class Methods
from_sql(sql_value)
click to toggle source
# File lib/perpetuity/postgres/timestamp_value.rb, line 11 def self.from_sql sql_value match = sql_value =~ /(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})\.?(\d*)?([-+]\d{2})?/ return new(nil) unless match offset = $8 ? "#$8:00" : '+00:00' new Time.new($1.to_i, $2.to_i, $3.to_i, $4.to_i, $5.to_i, "#$6.#$7".to_f, offset) end
new(time)
click to toggle source
# File lib/perpetuity/postgres/timestamp_value.rb, line 7 def initialize time @time = time end
Public Instance Methods
day()
click to toggle source
# File lib/perpetuity/postgres/timestamp_value.rb, line 35 def day zero_pad(time.day) end
hour()
click to toggle source
# File lib/perpetuity/postgres/timestamp_value.rb, line 39 def hour zero_pad(time.hour) end
minute()
click to toggle source
# File lib/perpetuity/postgres/timestamp_value.rb, line 43 def minute zero_pad(time.min) end
month()
click to toggle source
# File lib/perpetuity/postgres/timestamp_value.rb, line 31 def month zero_pad(time.month) end
offset()
click to toggle source
# File lib/perpetuity/postgres/timestamp_value.rb, line 51 def offset time.strftime('%z') end
second()
click to toggle source
# File lib/perpetuity/postgres/timestamp_value.rb, line 47 def second '%02d.%06d' % [time.sec, time.usec] end
to_s()
click to toggle source
# File lib/perpetuity/postgres/timestamp_value.rb, line 55 def to_s string = TextValue.new("#{year}-#{month}-#{day} #{hour}:#{minute}:#{second}#{offset}").to_s "#{string}::timestamptz" end
to_time()
click to toggle source
# File lib/perpetuity/postgres/timestamp_value.rb, line 19 def to_time time end
value()
click to toggle source
# File lib/perpetuity/postgres/timestamp_value.rb, line 23 def value time end
year()
click to toggle source
# File lib/perpetuity/postgres/timestamp_value.rb, line 27 def year time.year end
Private Instance Methods
zero_pad(n)
click to toggle source
# File lib/perpetuity/postgres/timestamp_value.rb, line 61 def zero_pad n '%02d' % n end