Git Product home page Git Product logo

weeknumber's Introduction

weeknumber

NPM version build status

week number systems for Gregorian year according to ISO-8601 or starting on sundays, saturdays

API

dayOfYear

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)

weekNumber

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

weekNumberSun

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

weekNumberSat

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

weekNumberYear

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

weekNumberYearSun

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

weekNumberYearSat

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

weeksPerYear

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

weeksPerYearSun

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

weeksPerYearSat

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

Installation

Requires nodejs.

$ npm install weeknumber

Tests

npm test

License

Unlicense https://unlicense.org/

weeknumber's People

Contributors

commenthol avatar smhg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

lssjbrolli

weeknumber's Issues

incorrect day of year at midnight during DST

Thanks for your work on this module!

When not testing in UTC (e.g. TZ=Europe/Brussels npm test), then this happens:

dayOfYear(new Date(2018, 2, 25)) === dayOfYear(new Date(2018, 2, 26))

Day of year detection is one hour off because of DST.

Is this something you want to support?
I think Node runs in UTC by default, but for browsers dayOfYear is quite useless.

If you don't want to support it, maybe it's an idea to add TZ=UTC to the npm test script?

Return year and week

Looking at the readme, this example cought my attention:

weekNumberSun(new Date(2016, 0, 2, 12)) // Sat
//> 52
weekNumberSun(new Date(2016, 0, 3, 12)) // Sun
//> 1

In the first case, it's actually week 52 of the year 2015. Would you like a patch to return the year along with the week? And while we're here, maybe even return the day (monday=1)

Looking at the ISO 8601 page it lists these examples:

  • Monday 29 December 2008 is written "2009-W01-1"
  • Sunday 3 January 2010 is written "2009-W53-7"

Maybe another method to return this format? Thoughts?

typescript

VSCode did not pick up the types after npm install - changing packages.json to

"types": "./types/index.d.ts",

worked for me.

Add weeksPerYear(year)

Hi,

I'd love to see a function to get the number of ISO weeks of any year.
Maybe this helps. :)

Kind regards

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.