0.2.0 • Published 2 years ago

spacetime-week-of-month v0.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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

0.2.0

2 years ago

0.1.0

2 years ago