Class: Perpetuity::Postgres::TimestampValue

Inherits:
Object
  • Object
show all
Defined in:
lib/perpetuity/postgres/timestamp_value.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#timeObject (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
# File 'lib/perpetuity/postgres/timestamp_value.rb', line 11

def self.from_sql sql_value
  Time.parse(sql_value)
end

Instance Method Details

#dayObject



31
32
33
# File 'lib/perpetuity/postgres/timestamp_value.rb', line 31

def day
  zero_pad(time.day)
end

#hourObject



35
36
37
# File 'lib/perpetuity/postgres/timestamp_value.rb', line 35

def hour
  zero_pad(time.hour)
end

#minuteObject



39
40
41
# File 'lib/perpetuity/postgres/timestamp_value.rb', line 39

def minute
  zero_pad(time.min)
end

#monthObject



27
28
29
# File 'lib/perpetuity/postgres/timestamp_value.rb', line 27

def month
  zero_pad(time.month)
end

#offsetObject



47
48
49
# File 'lib/perpetuity/postgres/timestamp_value.rb', line 47

def offset
  time.strftime('%z')
end

#secondObject



43
44
45
# File 'lib/perpetuity/postgres/timestamp_value.rb', line 43

def second
  '%02d.%06d' % [time.sec, time.usec]
end

#to_sObject



51
52
53
54
# File 'lib/perpetuity/postgres/timestamp_value.rb', line 51

def to_s
  string = TextValue.new("#{year}-#{month}-#{day} #{hour}:#{minute}:#{second}#{offset}").to_s
  "#{string}::timestamptz"
end

#to_timeObject



15
16
17
# File 'lib/perpetuity/postgres/timestamp_value.rb', line 15

def to_time
  time
end

#valueObject



19
20
21
# File 'lib/perpetuity/postgres/timestamp_value.rb', line 19

def value
  time
end

#yearObject



23
24
25
# File 'lib/perpetuity/postgres/timestamp_value.rb', line 23

def year
  time.year
end