Class: Perpetuity::Postgres::TimestampValue
- Inherits:
-
Object
- Object
- Perpetuity::Postgres::TimestampValue
- Defined in:
- lib/perpetuity/postgres/timestamp_value.rb
Instance Attribute Summary collapse
-
#time ⇒ Object
readonly
Returns the value of attribute time.
Class Method Summary collapse
Instance Method Summary collapse
- #day ⇒ Object
- #hour ⇒ Object
-
#initialize(time) ⇒ TimestampValue
constructor
A new instance of TimestampValue.
- #minute ⇒ Object
- #month ⇒ Object
- #offset ⇒ Object
- #second ⇒ Object
- #to_s ⇒ Object
- #to_time ⇒ Object
- #value ⇒ Object
- #year ⇒ Object
Constructor Details
#initialize(time) ⇒ TimestampValue
Returns a new instance of TimestampValue.
7 8 9 |
# File 'lib/perpetuity/postgres/timestamp_value.rb', line 7 def initialize time @time = time end |
Instance Attribute Details
#time ⇒ Object (readonly)
Returns the value of attribute time.
6 7 8 |
# File 'lib/perpetuity/postgres/timestamp_value.rb', line 6 def time @time end |
Class Method Details
.from_sql(sql_value) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/perpetuity/postgres/timestamp_value.rb', line 11 def self.from_sql sql_value date, time = sql_value.split(/ /) year, month, day = date.split(/-/) hour, minute, seconds_with_offset = time.split(/:/) second = seconds_with_offset[/\d+\.\d+/].to_f offset = seconds_with_offset[/(\+|\-)\d+/] + ':00' new Time.new(year, month, day, hour, minute, second, offset) end |
Instance Method Details
#day ⇒ Object
37 38 39 |
# File 'lib/perpetuity/postgres/timestamp_value.rb', line 37 def day zero_pad(time.day) end |
#hour ⇒ Object
41 42 43 |
# File 'lib/perpetuity/postgres/timestamp_value.rb', line 41 def hour zero_pad(time.hour) end |
#minute ⇒ Object
45 46 47 |
# File 'lib/perpetuity/postgres/timestamp_value.rb', line 45 def minute zero_pad(time.min) end |
#month ⇒ Object
33 34 35 |
# File 'lib/perpetuity/postgres/timestamp_value.rb', line 33 def month zero_pad(time.month) end |
#offset ⇒ Object
53 54 55 |
# File 'lib/perpetuity/postgres/timestamp_value.rb', line 53 def offset time.strftime('%z') end |
#second ⇒ Object
49 50 51 |
# File 'lib/perpetuity/postgres/timestamp_value.rb', line 49 def second '%02d.%06d' % [time.sec, time.usec] end |
#to_s ⇒ Object
57 58 59 60 |
# File 'lib/perpetuity/postgres/timestamp_value.rb', line 57 def to_s string = TextValue.new("#{year}-#{month}-#{day} #{hour}:#{minute}:#{second}#{offset}").to_s "#{string}::timestamptz" end |
#to_time ⇒ Object
21 22 23 |
# File 'lib/perpetuity/postgres/timestamp_value.rb', line 21 def to_time time end |
#value ⇒ Object
25 26 27 |
# File 'lib/perpetuity/postgres/timestamp_value.rb', line 25 def value time end |
#year ⇒ Object
29 30 31 |
# File 'lib/perpetuity/postgres/timestamp_value.rb', line 29 def year time.year end |