Class: Timeframe::Iso8601::B
Overview
Internal use.
The “B” side of “A/B”
Constant Summary
Constants inherited from Side
Instance Attribute Summary
Attributes inherited from Side
Instance Method Summary collapse
-
#initialize(raw) ⇒ B
constructor
A new instance of B.
- #offset ⇒ Object
-
#resolve_time(counterpart) ⇒ Object
When shorthand is used, we need to peek at our counterpart (A) in order to steal letters Shorthand can only be used on the B side, and only in <start>/<end> format.
Methods inherited from Side
Constructor Details
#initialize(raw) ⇒ B
Returns a new instance of B.
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/timeframe/iso_8601.rb', line 63 def initialize(raw) raw = raw.upcase if raw.include?(':') and not raw.include?('T') # it's just a shorthand for time @date_part = '' @time_part = raw else @date_part, @time_part = raw.split('T') @time_part ||= '' end end |
Instance Method Details
#offset ⇒ Object
89 90 91 |
# File 'lib/timeframe/iso_8601.rb', line 89 def offset Duration.new(date_part, time_part).seconds end |
#resolve_time(counterpart) ⇒ Object
When shorthand is used, we need to peek at our counterpart (A) in order to steal letters Shorthand can only be used on the B side, and only in <start>/<end> format.
76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/timeframe/iso_8601.rb', line 76 def resolve_time(counterpart) filled_in_date_part = unless date_part.count('-') == 2 counterpart.date_part[0..(0-date_part.length-1)] + date_part else date_part end filled_in_time_part = if time_part.count(':') < 2 counterpart.time_part[0..(0-time_part.length-1)] + time_part else time_part end Time.parse [filled_in_date_part, filled_in_time_part].join('T') end |