0.0
No commit activity in last 3 years
No release in over 3 years
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.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies
 Project Readme

mysql_yearweek

A gem for getting the exact same yearweek as returned by the MySQL function.

Overview

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.

Installation

$ gem install mysql_yearweek

Example Usage

> require mysql_yearweek
=> true
> MySQLYearweek.yearweek(Date.new(2013, 07, 25))
=> "201330"
> MySQLYearweek.yearweek(Date.new(2013, 07, 25), 2)
=> "201329"

Limitations

This only works with 1584-01-01 and later. Before that be Julian calendar dragons.

MySQL Yearweek Modes

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

Copyright (c) 2013 Dean Morin. See LICENSE for details.