A gem for getting the exact same yearweek as returned by the MySQL function.
MySQL's yearweek
function has eight different modes for determining the yearweek. This will get the same yearweek for each mode, with 4
being the default mode.
This gem was tested against MySQL 5.6.12.
$ gem install mysql_yearweek
> require mysql_yearweek
=> true
> MySQLYearweek.yearweek(Date.new(2013, 07, 25))
=> "201330"
> MySQLYearweek.yearweek(Date.new(2013, 07, 25), 2)
=> "201329"
This only works with 1584-01-01
and later. Before that be Julian calendar dragons.
The following table from the official MySQL docs describes how each mode is expected to behave.
Mode | First day of week | Range | Week 1 is the first week … |
---|---|---|---|
0 | Sunday | 0-53 | with a Sunday in this year |
1 | Monday | 0-53 | with more than 3 days this year |
2 | Sunday | 1-53 | with a Sunday in this year |
3 | Monday | 1-53 | with more than 3 days this year |
4 | Sunday | 0-53 | with more than 3 days this year |
5 | Monday | 0-53 | with a Monday in this year |
6 | Sunday | 1-53 | with more than 3 days this year |
7 | Monday | 1-53 | with a Monday in this year |
Copyright (c) 2013 Dean Morin. See LICENSE for details.