Skip to content
Permalink
Browse files

Merge branch 'leonelgalan-day_start_and_week_start' into groupdate4

  • Loading branch information
ankane committed Feb 22, 2018
2 parents 976b9c1 + 1a770da commit 361905ea29d272e58795d24ce7174d156fada501
Showing with 27 additions and 3 deletions.
  1. +5 −3 lib/groupdate/magic.rb
  2. +22 −0 test/test_helper.rb
@@ -155,7 +155,7 @@ def series(count, default_value, multiple_groups = false, reverse = false, serie
when :minute_of_hour
key = sunday + key.minutes + day_start.seconds
when :day_of_week
key = sunday + key.days
key = sunday + key.days + (week_start + 1).days
when :day_of_month
key = Date.new(2014, 1, key).to_time
when :month_of_year
@@ -210,7 +210,7 @@ def round_time(time)
when :minute_of_hour
time.min
when :day_of_week
time.wday
(time.wday - 1 - week_start) % 7
when :day_of_month
time.day
when :month_of_year
@@ -407,7 +407,9 @@ def perform(relation, result)

cast_method =
case period
when :day_of_week, :hour_of_day, :day_of_month, :month_of_year, :minute_of_hour
when :day_of_week
lambda { |k| (k.to_i - 1 - week_start) % 7 }
when :hour_of_day, :day_of_month, :month_of_year, :minute_of_hour
lambda { |k| k.to_i }
else
utc = ActiveSupport::TimeZone["UTC"]
@@ -781,6 +781,24 @@ def test_day_of_week_start_of_day_with_time_zone_day_start_2am
assert_result :day_of_week, 3, "2013-01-02 10:00:00", true, day_start: 2
end

# day of week week start monday

def test_day_of_week_end_of_day_week_start_mon
assert_result :day_of_week, 1, "2013-01-01 23:59:59", false, week_start: :mon
end

def test_day_of_week_start_of_day_week_start_mon
assert_result :day_of_week, 2, "2013-01-02 00:00:00", false, week_start: :mon
end

def test_day_of_week_end_of_week_with_time_zone_week_start_mon
assert_result :day_of_week, 1, "2013-01-02 07:59:59", true, week_start: :mon
end

def test_day_of_week_start_of_week_with_time_zone_week_start_mon
assert_result :day_of_week, 2, "2013-01-02 08:00:00", true, week_start: :mon
end

# day of month

def test_day_of_month_end_of_day
@@ -1083,6 +1101,10 @@ def test_format_day_of_week_week_start
assert_format :day_of_week, "Sat", "%a", week_start: :mon
end

def test_format_day_of_week_week_start
assert_equal "Mon", call_method(:day_of_week, :created_at, week_start: :mon, format: "%a", series: true).keys.first
end

def test_format_day_of_month
create_user "2014-03-01"
assert_format :day_of_month, " 1", "%e"

0 comments on commit 361905e

Please sign in to comment.
You can’t perform that action at this time.