week number systems for Gregorian year according to ISO-8601 or starting on sundays, saturdays
- API
- dayOfYear
- weekNumber - ISO 8601 week numbers
- weekNumberSun - week starting on Sundays
- weekNumberSat - week starting on Saturdays
- weekNumberYear - ISO 8601 calendar year, week, and day
- weekNumberYearSun - calendar year, week, and day starting on Sundays
- weekNumberYearSat - calendar year, week, and day starting on Saturdays
- weeksPerYear - ISO 8601 calendar weeks in a given year
- weeksPerYearSun
- weeksPerYearSat
- Installation
- Tests
- License
Get day of year in Gregorian year
Parameters
date
?: Date; optional: local date
Example
import { dayOfYear } from 'weeknumber'
dayOfYear(new Date(2017, 11, 31, 12))
//> 365
dayOfYear(new Date(2018, 0, 1, 12))
//> 1
Returns Number
, number of day in year (1 ... 366)
ISO-8601 week numbering.
New week starts on Mondays. Used by most European countries, most of Asia and Oceania.
1st week contains 4-7 days of the new year.
Parameters
date
?: Date; optional: local date
Example
import { weekNumber } from 'weeknumber'
weekNumber(new Date(2016, 0, 3, 12)) // Sun
//> 53
weekNumber(new Date(2016, 0, 4, 12)) // Mon
//> 1
Returns Number
, week number in ISO 8601 format
North American and Islamic system.
New week starts on Sundays. Used in Canada, United States, India, Japan, Taiwan, Hong Kong, Macau, Israel, South Africa, most of Latin America.
1st week contains 1-7 days of the new year
Parameters
date
?: Date; optional: local date
Example
weekNumberSun(new Date(2016, 0, 2, 12)) // Sat
//> 52
weekNumberSun(new Date(2016, 0, 3, 12)) // Sun
//> 1
Returns Number
, week number
Middle Eastern system.
New week starts on Saturdays. Used in most of the Middle East.
1st week contains 1-7 days of the new year
Parameters
date
?: Date; optional: local date
Example
weekNumberSat(new Date(2016, 0, 1, 12)) // Fri
//> 52
weekNumberSat(new Date(2016, 0, 2, 12)) // Sat
//> 1
Returns Number
, week number
ISO-8601 calendar year, week, and day
New week starts on Mondays. Used by most European countries, most of Asia and Oceania.
1st week contains 4-7 days of the new year.
Parameters
date
?: Date; optional: local date
Example
weekNumberYear(new Date(2008, 11, 29, 12)) // Monday
//> { year: 2009, week: 1, day: 1 }
weekNumberYear(new Date(2010, 0, 3, 12)) // Sunday
//> { year: 2009, week: 53, day: 7 }
Returns Object
, {year, week, day}
where day 1=Monday ... 7=Sunday
North American and Islamic system calendar year, week, and day
New week starts on Sundays. Used in Canada, United States, India, Japan, Taiwan, Hong Kong, Macau, Israel, South Africa, most of Latin America.
1st week contains 1-7 days of the new year
Parameters
date
?: Date; optional: local date
Example
weekNumberYearSun(new Date(2009, 0, 3, 12)) // Saturday
//> { year: 2008, week: 52, day: 7 }
weekNumberYearSun(new Date(2009, 0, 4, 12)) // Sunday
//> { year: 2009, week: 1, day: 1 }
Returns Object
, {year, week, day}
where day 1=Sunday ... 7=Saturday
Middle Eastern system calendar year, week, and day
New week starts on Saturdays. Used in most of the Middle East.
1st week contains 1-7 days of the new year
Parameters
date
?: Date; optional: local date
Example
weekNumberYearSat(new Date(2009, 0, 2, 12)) // Friday
//> { year: 2008, week: 52, day: 7 }
weekNumberYearSat(new Date(2009, 0, 3, 12)) // Saturday
//> { year: 2009, week: 1, day: 1 }
Returns Object
, {year, week, day}
where day 1=Saturday ... 7=Friday
ISO 8601 calendar weeks in a given year
New week starts on mondays. Used by most European countries, most of Asia and Oceania.
Parameters
year
: number;
Returns number weeks in year
North American and islamic system calendar weeks in a given year
New week starts on sundays. Used in Canada, United States, India, Japan, Taiwan, Hong Kong, Macau, Israel, South Africa, most of Latin America.
Parameters
year
: number;
Returns number weeks in year
Middle Eastern system calendar weeks in a given year
New week starts on saturdays. Used in most of the Middle East.
Parameters
year
: number;
Returns number weeks in year
Requires nodejs.
$ npm install weeknumber
npm test
Unlicense https://unlicense.org/