lib/groupdate/series_builder.rb in groupdate-5.1.0 vs lib/groupdate/series_builder.rb in groupdate-5.2.0

- old
+ new

@@ -9,11 +9,10 @@ @time_zone = time_zone @week_start = week_start @day_start = day_start @n_seconds = n_seconds @options = options - @round_time = {} @week_start_key = Groupdate::Magic::DAYS[@week_start] if @week_start end def generate(data, default_value:, series_default: true, multiple_groups: false, group_index: nil) series = generate_series(data, multiple_groups, group_index) @@ -140,15 +139,20 @@ end def time_range @time_range ||= begin time_range = options[:range] - if time_range.is_a?(Range) && time_range.first.is_a?(Date) - # convert range of dates to range of times - last = time_range.last.in_time_zone(time_zone) - last += 1.day unless time_range.exclude_end? - time_range = Range.new(time_range.first.in_time_zone(time_zone), last, true) + # 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) + end + if time_range.end + last = time_zone.parse(time_range.last.to_s) + last += 1.day unless time_range.exclude_end? + end + time_range = Range.new(start, last, true) elsif !time_range && options[:last] if period == :quarter step = 3.months elsif period == :custom step = n_seconds @@ -198,25 +202,37 @@ when :month_of_year 1..12 else time_range = self.time_range time_range = - if time_range.is_a?(Range) + if time_range.is_a?(Range) && time_range.begin && time_range.end time_range else # use first and last values sorted_keys = if multiple_groups data.keys.map { |k| k[group_index] }.sort else data.keys.sort end - tr = sorted_keys.first..sorted_keys.last - if options[:current] == false && sorted_keys.any? && round_time(now) >= tr.last - tr = tr.first...round_time(now) + if time_range.is_a?(Range) + if sorted_keys.any? + if time_range.begin + time_range.begin..sorted_keys.last + else + Range.new(sorted_keys.first, time_range.end, time_range.exclude_end?) + end + else + nil..nil + end + else + tr = sorted_keys.first..sorted_keys.last + if options[:current] == false && sorted_keys.any? && round_time(now) >= tr.last + tr = tr.first...round_time(now) + end + tr end - tr end if time_range.begin series = [round_time(time_range.begin)]