Skip to content

deanmorin/mysql_yearweek

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

ModeFirst day of weekRangeWeek 1 is the first week …
0Sunday0-53with a Sunday in this year
1Monday0-53with more than 3 days this year
2Sunday1-53with a Sunday in this year
3Monday1-53with more than 3 days this year
4Sunday0-53with more than 3 days this year
5Monday0-53with a Monday in this year
6Sunday1-53with more than 3 days this year
7Monday1-53with a Monday in this year

Copyright

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

About

Ruby gem for getting yearweek values equivalent to the MySQL function

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages