Skip to content

Latest commit

 

History

History

week-of-month

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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