Commit e82aadcd0974b6647da63ce744d8a01b77e19307
1 parent
4a842ecd
Exists in
master
and in
12 other branches
Added current option
Showing
4 changed files
with
18 additions
and
0 deletions
Show diff stats
CHANGELOG.md
README.md
... | ... | @@ -115,6 +115,12 @@ To get the most recent time periods, use: |
115 | 115 | User.group_by_week(:created_at, last: 8).count # last 8 weeks |
116 | 116 | ``` |
117 | 117 | |
118 | +To exclude the current period, use: [master] | |
119 | + | |
120 | +```ruby | |
121 | +User.group_by_week(:created_at, last: 8, current: false).count | |
122 | +``` | |
123 | + | |
118 | 124 | ### Order |
119 | 125 | |
120 | 126 | You can order in descending order with: | ... | ... |
lib/groupdate/magic.rb
test/test_helper.rb
... | ... | @@ -698,6 +698,16 @@ module TestGroupdate |
698 | 698 | assert_equal expected, User.group_by_year(:created_at, last: 3).count |
699 | 699 | end |
700 | 700 | |
701 | + def test_current | |
702 | + create_user "2012-05-01 00:00:00 UTC" | |
703 | + create_user "2014-05-01 00:00:00 UTC" | |
704 | + expected = { | |
705 | + utc.parse("2013-01-01 00:00:00 UTC") => 0, | |
706 | + utc.parse("2014-01-01 00:00:00 UTC") => 1 | |
707 | + } | |
708 | + assert_equal expected, User.group_by_year(:created_at, last: 2, current: false).count | |
709 | + end | |
710 | + | |
701 | 711 | def test_format_day |
702 | 712 | create_user "2014-03-01 00:00:00 UTC" |
703 | 713 | assert_format :day, "March 1, 2014", "%B %-e, %Y" | ... | ... |