Permalink
Browse files

clarify method naming per @dkastner

  • Loading branch information...
1 parent e7a76dc commit d2753177712a228c91a589a850f3b6b3c4511c43 @seamusabshere seamusabshere committed Feb 21, 2012
Showing with 11 additions and 14 deletions.
  1. +1 −1 lib/timeframe.rb
  2. +10 −13 lib/timeframe/iso_8601.rb
View
@@ -49,7 +49,7 @@ def from_iso8601(str)
a_raw, b_raw = str.split delimiter
a = Iso8601::A.new a_raw
b = Iso8601::B.new b_raw
- new a.resolve(b), b.resolve(a)
+ new a.to_time(b), b.to_time(a)
end
# Construct a new Timeframe from a hash with keys startDate and endDate
View
@@ -25,19 +25,16 @@ def parse(part, indicator)
# Internal use.
class Side
+ # We add one day because so that it can be excluded per timeframe's conventions.
EXCLUDED_LAST_DAY = 86_400
attr_reader :date_part, :time_part
- def resolve(counterpart)
+ def to_time(counterpart)
if date_part.start_with?('P')
- # We add one day because so that it can be excluded per timeframe's conventions.
- counterpart.as_time(self) + as_offset + EXCLUDED_LAST_DAY
+ counterpart.resolve_time(self) + resolve_offset + EXCLUDED_LAST_DAY
else
- as_time counterpart
+ resolve_time counterpart
end
end
- def to_duration
- Duration.new date_part, time_part
- end
end
# Internal use.
@@ -49,12 +46,12 @@ def initialize(raw)
@date_part, @time_part = raw.split('T')
@time_part ||= ''
end
- def as_time(*)
+ def resolve_time(*)
Time.parse [date_part, time_part].join('T')
end
# When A is a period, it counts as a negative offset to B.
- def as_offset
- 0.0 - to_duration.seconds
+ def resolve_offset
+ 0.0 - Duration.new(date_part, time_part).seconds
end
end
@@ -75,7 +72,7 @@ def initialize(raw)
end
# 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.
- def as_time(counterpart)
+ 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
@@ -88,8 +85,8 @@ def as_time(counterpart)
end
Time.parse [filled_in_date_part, filled_in_time_part].join('T')
end
- def as_offset
- to_duration.seconds
+ def resolve_offset
+ Duration.new(date_part, time_part).seconds
end
end
end

0 comments on commit d275317

Please sign in to comment.