spacetime-week-of-month

0.2.0 • Public • Published
calculate the week number of a month
spacetime-week-of-month
by Spencer Kelly

Broadly, we think of a month as having 4 weeks, but when people say 'the 1st week of the month', it can be an ambiguous thing.

The 1st week of May is defined as the first week with a Thursday in it.

This means that first 3 days of October are in the 5th week of September: image

and the last 3 days of June, will be the 1st week of July. image

This is a spacetime plugin to calculate this, for a given day.

// Oct 2020 starts on a thursday
let s = spacetime('saturday oct 10th 2020')
s.weekOfMonth()
// 2

s = s.weekOfMonth(1)
// Mon Sep 28th

the week numbers start at 1.

like .week() which is based on the year, .weekOfMonth() works as a getter+setter, based on the input param:

Note: the getter/setter can produce different results:

let s = spacetime('saturday oct 10th 2020')
s = s.weekOfMonth(1)
// Mon Sep 28th
s.weekOfMonth()
// 5

Sep 28th is considered the 5th week of September.

work-in-progress.

See also

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i spacetime-week-of-month

Weekly Downloads

1

Version

0.2.0

License

MIT

Unpacked Size

11.2 kB

Total Files

8

Last publish

Collaborators

  • spencermountain