spacetime-week-start

0.2.0 • Public • Published

spacetime-week-start

calculate the start of a week

The start of a week varies officially in different countries.

This is a 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.

It is built for use in/with the spacetime library

Main function weekStart determines when week start in the current time zone or given coutry:

  • it accepts one optional argument - string name of the country
  • you don't have to supply full name of a country - it's enough write part of name (f.e. instead of united states of america just united states or unique part of name, like f.e. ted sta)
  • if searching for country name is successful it returns a simple JSON object for better clarification what is in output, looking f.e.:
{ day: 'sunday', country: 'united states of america' }
  • function also accepts text in any case (lower, upper, camel case)
  • just to make it easy for you write lower cased country name
  • there are some time zones with general names, such as gmt, utc or zulu. These returns JSON such as:
{ day: 'monday', location: 'zulu' }
  • if you write as argument different type as string, null, undefined or supply no argument at all it returns first day of weeek for current time zone
  • it uses spacetime library to determine current time zone only and rest is distinct for searching first day of week

npm i spacetime-week-start

const s = require('spacetime-week-start')

console.log('#1: ', s.weekStart());
console.log('#2: ', s.weekStart(12));
console.log('#3: ', s.weekStart(null));
console.log('#4: ', s.weekStart(''));
console.log('#5: ', s.weekStart(undefined));
console.log('#6: ', s.weekStart('abc'));
// all returns results for current tz, f.e. { day: 'sunday', country: 'canada' }

console.log('#7: ', weekStart('slovakia'));
// tz: europe/bratislava
// { day: 'monday', country: 'slovakia' }

console.log('#8: ', weekStart('iran'));
//tz: asia/tehran
// { day: 'saturday', country: 'iran' }

console.log('#9: ', weekStart('canAda'));
//tz: f.e. america/montreal
// { day: 'sunday', country: 'canada' }

console.log('#10: ', weekStart('lize'));
// tz: america/belize
// { day: 'monday', country: 'belize' }

console.log('#11: ', weekStart('el salvador'));
// tz: america/el_salvador
// { day: 'monday', country: 'el salvador' }

console.log('#12: ', weekStart('zulu'));
// tz: etc/zulu
// { day: 'monday', location: 'zulu' }

console.log('#13: ', weekStart('gmt'));
// tz: f.e. etc/gmt
// { day: 'monday', location: 'gmt' }

console.log('#14: ', weekStart('antarctica'));
// tz: f.e. antarctica/south_pole
// { day: 'monday', location: 'antarctica' }

console.log('#15: ', weekStart('arctic'));
// tz: f.e. arctic/longyearbyen
// { day: 'monday', location: 'arctic' }

Used various sources to determine most accurate guess:

work-in-progress

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i spacetime-week-start

Weekly Downloads

0

Version

0.2.0

License

none

Unpacked Size

439 kB

Total Files

15

Last publish

Collaborators

  • spencermountain