lib/groupdate/series_builder.rb in groupdate-5.2.0 vs lib/groupdate/series_builder.rb in groupdate-5.2.1
- old
+ new
@@ -139,19 +139,38 @@
end
def time_range
@time_range ||= begin
time_range = options[:range]
- # entire range must be Date if begin or end is Date
- if time_range.is_a?(Range) && (time_range.begin.is_a?(Date) || time_range.end.is_a?(Date))
- if time_range.begin
- start = time_zone.parse(time_range.first.to_s)
+
+ if time_range.is_a?(Range)
+ # check types
+ [time_range.begin, time_range.end].each do |v|
+ case v
+ when nil, Date, Time
+ # good
+ when String
+ # TODO raise error in Groupdate 6
+ warn "[groupdate] Range bounds should be Date or Time, not #{v.class.name}. This will raise an error in Groupdate 6"
+ break
+ else
+ raise ArgumentError, "Range bounds should be Date or Time, not #{v.class.name}"
+ end
end
- if time_range.end
- last = time_zone.parse(time_range.last.to_s)
- last += 1.day unless time_range.exclude_end?
+
+ start = time_range.begin
+ start = start.in_time_zone(time_zone) if start
+
+ exclude_end = time_range.exclude_end?
+
+ finish = time_range.end
+ finish = finish.in_time_zone(time_zone) if finish
+ if time_range.end.is_a?(Date) && !exclude_end
+ finish += 1.day
+ exclude_end = true
end
- time_range = Range.new(start, last, true)
+
+ time_range = Range.new(start, finish, exclude_end)
elsif !time_range && options[:last]
if period == :quarter
step = 3.months
elsif period == :custom
step = n_seconds