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 |
# 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 |
Instance Method Details
#day ⇒ Object
35 36 37 |
# File 'lib/perpetuity/postgres/timestamp_value.rb', line 35 def day zero_pad(time.day) end |
#hour ⇒ Object
39 40 41 |
# File 'lib/perpetuity/postgres/timestamp_value.rb', line 39 def hour zero_pad(time.hour) end |
#minute ⇒ Object
43 44 45 |
# File 'lib/perpetuity/postgres/timestamp_value.rb', line 43 def minute zero_pad(time.min) end |
#month ⇒ Object
31 32 33 |
# File 'lib/perpetuity/postgres/timestamp_value.rb', line 31 def month zero_pad(time.month) end |
#offset ⇒ Object
51 52 53 |
# File 'lib/perpetuity/postgres/timestamp_value.rb', line 51 def offset time.strftime('%z') end |
#second ⇒ Object
47 48 49 |
# File 'lib/perpetuity/postgres/timestamp_value.rb', line 47 def second '%02d.%06d' % [time.sec, time.usec] end |
#to_s ⇒ Object
55 56 57 58 |
# 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 ⇒ Object
19 20 21 |
# File 'lib/perpetuity/postgres/timestamp_value.rb', line 19 def to_time time end |
#value ⇒ Object
23 24 25 |
# File 'lib/perpetuity/postgres/timestamp_value.rb', line 23 def value time end |
#year ⇒ Object
27 28 29 |
# File 'lib/perpetuity/postgres/timestamp_value.rb', line 27 def year time.year end |