spacetime-week-start
v0.4.0
Published
calculate start-of-week
Readme
The start of a week varies officially in different countries.
This is a plugin for the spacetime library, to help understand week-starts/ends, by country or timezone.
It does some opinionated guesswork to determine the most appropriate week-start, when a timezone is given.
It returns an english name of the day used in javascript.
npm i spacetime-week-start
import spacetime from 'spacetime'
import weekStart from 'spacetime-week-start'
spacetime.extend(weekStart)
let s = spacetime.now('Europe/Berlin')
// with no argument, it uses the timezone of the spacetime object
s.weekStart()
// { day: 'monday', country: 'germany' }
// or, look up a country by name
s.weekStart('canada')
// { day: 'sunday', country: 'canada' }
s.weekStart('iran')
// { day: 'saturday', country: 'iran' }The weekStart method accepts one optional argument - the name of a country:
- you don't have to supply the full name of a country - part of the name is enough (f.e. instead of united states of america just united states, or a unique part of the name, like ted sta)
- the country name can be in any case (lower, upper, camel case)
- if the country lookup is successful, it returns a simple object:
s.weekStart('united states')
// { day: 'sunday', country: 'united states of america' }- some timezones have general names, such as
gmt,utcorzulu. These return:
spacetime.now('Etc/Zulu').weekStart()
// { day: 'monday', location: 'zulu' }- if you supply a non-string,
null,undefined, an unknown name, or no argument at all, it returns the first day of the week for the object's timezone
Used various sources to determine most accurate guess:
- First Day of the Week in Different Countries
- CLDR - Unicode Common Locale Data Repository
- CLDR - day and week data file
- Wikipedia - Workweek and weekend
- Time & Date
- Time zone converter
MIT
