Class: GoobyDtTm
Constant Summary
collapse
- @@months =
Hash.new('')
GoobyBaseObject::KILOMETERS_PER_MILE, GoobyBaseObject::METERS_PER_FOOT, GoobyBaseObject::MILES_PER_KILOMETER, GoobyBaseObject::SECONDS_PER_HOUR, GoobyBaseObject::UOM_KILOMETERS, GoobyBaseObject::UOM_MILES, GoobyBaseObject::UOM_YARDS, GoobyBaseObject::YARDS_PER_KILOMETER, GoobyBaseObject::YARDS_PER_MILE
Instance Attribute Summary collapse
Instance Method Summary
collapse
boolean_config_value, config_value, get_config, set_config
Methods included from GoobyIO
#read_file_as_lines, #write_file, #write_lines
#classname, included
#array_param, #boolean_param, #command_line_arg, #float_param, #integer_param, #string_param
Constructor Details
#initialize(raw) ⇒ GoobyDtTm
The arg is a String like ‘2006-01-15T13:41:40Z’.
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/gooby_dttm.rb', line 42
def initialize(raw)
@valid = false
if raw
a = raw.tr('TZ\-\:', ' ').strip.split
if a.size > 5
@time = Time.utc(a[0].to_i, lookup_month(a[1]), a[2].to_i, a[3].to_i, a[4].to_i, a[5].to_i)
@valid = true if @time
end
end
end
|
Instance Attribute Details
#time ⇒ Object
Returns the value of attribute time.
20
21
22
|
# File 'lib/gooby_dttm.rb', line 20
def time
@time
end
|
#valid ⇒ Object
Returns the value of attribute valid.
20
21
22
|
# File 'lib/gooby_dttm.rb', line 20
def valid
@valid
end
|
Instance Method Details
#hh_mm_ss ⇒ Object
69
70
71
|
# File 'lib/gooby_dttm.rb', line 69
def hh_mm_ss
time.strftime("%H:%M:%S")
end
|
#hhmmss_diff(another_dttm) ⇒ Object
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/gooby_dttm.rb', line 81
def hhmmss_diff(another_dttm)
if another_dttm
secs = seconds_diff(another_dttm).abs
hh = (secs / SECONDS_PER_HOUR).to_i
rem = secs - (hh * SECONDS_PER_HOUR)
mm = (rem / 60).to_i
ss = rem - (mm * 60).to_i
ss = 59 if ss > 59
"#{hh}:#{zero_pad(mm)}:#{zero_pad(ss.to_i)}"
else
'00:00:00'
end
end
|
#invalid_time ⇒ Object
57
58
59
|
# File 'lib/gooby_dttm.rb', line 57
def invalid_time
return -99999999
end
|
#lookup_month(m) ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/gooby_dttm.rb', line 22
def lookup_month(m)
if @@months.size == 0
@@months = Hash.new('')
@@months['01'] = 'jan'
@@months['02'] = 'feb'
@@months['03'] = 'mar'
@@months['04'] = 'apr'
@@months['05'] = 'may'
@@months['06'] = 'jun'
@@months['07'] = 'jul'
@@months['08'] = 'aug'
@@months['09'] = 'sep'
@@months['10'] = 'oct'
@@months['11'] = 'nov'
@@months['12'] = 'dec'
end
@@months[m]
end
|
#seconds_diff(another_dttm) ⇒ Object
73
74
75
76
77
78
79
|
# File 'lib/gooby_dttm.rb', line 73
def seconds_diff(another_dttm)
if another_dttm
to_i - another_dttm.to_i
else
invalid_time
end
end
|
#to_i ⇒ Object
53
54
55
|
# File 'lib/gooby_dttm.rb', line 53
def to_i
(@time) ? @time.to_i : invalid_time
end
|
#to_s ⇒ Object
95
96
97
|
# File 'lib/gooby_dttm.rb', line 95
def to_s
"#{yyyy_mm_dd} #{hh_mm_ss} #{to_i}"
end
|
#yyyy_mm_dd ⇒ Object
61
62
63
|
# File 'lib/gooby_dttm.rb', line 61
def yyyy_mm_dd
time.strftime("%Y-%m-%d")
end
|
#yyyy_mm_dd_hh_mm_ss(delim = ' ') ⇒ Object
65
66
67
|
# File 'lib/gooby_dttm.rb', line 65
def yyyy_mm_dd_hh_mm_ss(delim=' ')
time.strftime("#{yyyy_mm_dd}#{delim}#{hh_mm_ss}")
end
|