spacetime-week-start 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2026 Spencer Kelly
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
package/README.md CHANGED
@@ -1,100 +1,79 @@
1
1
  <div align="center">
2
- <div>
3
- <h2>spacetime-week-start</h2>
2
+ <div><b>spacetime-week-start</b></div>
3
+ <div>identify the appropriate start of a week</div>
4
+ <div><code>npm install spacetime-week-start</code></div>
5
+ <div align="center">
6
+ <sub>
7
+ by
8
+ <a href="https://github.com/spencermountain">Spencer Kelly</a>
9
+ </sub>
4
10
  </div>
11
+ <img height="25px" src="https://user-images.githubusercontent.com/399657/68221824-09809d80-ffb8-11e9-9ef0-6ed3574b0ce8.png"/>
12
+ </div>
13
+ <!--2nd row-->
14
+ <div align="center">
5
15
  <div>
6
- calculate the start of a week
7
- </div>
8
- <a href="https://npmjs.org/package/spacetime-week-start">
16
+ <a href="https://npmjs.org/package/spacetime-week-start">
9
17
  <img src="https://img.shields.io/npm/v/spacetime-week-start.svg?style=flat-square" />
10
18
  </a>
11
- <a href="https://unpkg.com/spacetime/builds/spacetime-week-start.min.js">
12
- <img src="https://badge-size.herokuapp.com/spencermountain/spacetime-week-start/master/builds/spacetime-week-start.min.js" />
19
+ <a href="https://bundlephobia.com/result?p=spacetime-week-start">
20
+ <img src="https://badgen.net/bundlejs/min/spacetime-week-start" />
13
21
  </a>
14
- <div>
15
- <sup>
16
- By <a href="https://github.com/MartinSpd">Martin Spodniak</a> and <a href="https://github.com/spencermountain">Spencer Kelly</a>
17
- </sup>
18
22
  </div>
19
- <hr/>
20
23
  </div>
21
24
 
25
+ <!-- spacer -->
26
+ <img height="20px" src="https://user-images.githubusercontent.com/399657/68221862-17ceb980-ffb8-11e9-87d4-7b30b6488f16.png"/>
27
+
22
28
  The start of a week varies officially in different countries.
23
29
 
24
- This is a library to help understand week-starts/ends, by country or timezone.
30
+ This is a plugin for the [spacetime](https://github.com/spencermountain/spacetime) library, to help understand week-starts/ends, by country or timezone.
25
31
 
26
32
  It does some opinionated guesswork to determine the most appropriate week-start, when a timezone is given.
27
33
 
28
34
  It returns an english name of the day used in javascript.
29
35
 
30
- It is built for use in/with the [spacetime](https://github.com/spencermountain/spacetime) library
36
+ ### Usage
31
37
 
32
- Main function `weekStart` determines when week start in the current time zone or given coutry:
33
- - it accepts one optional argument - string name of the country
34
- - 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*)
35
- - if searching for country name is successful it returns a simple JSON object for better clarification what is in output, looking f.e.:
36
- ```js
37
- { day: 'sunday', country: 'united states of america' }
38
- ```
39
- - function also accepts text in any case (lower, upper, camel case)
40
- - just to make it easy for you write lower cased country name
41
- - there are some time zones with general names, such as `gmt`, `utc` or `zulu`. These returns `JSON` such as:
42
38
  ```js
43
- { day: 'monday', location: 'zulu' }
44
- ```
45
- - 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
46
- - it uses `spacetime` library to determine current time zone only and rest is distinct for searching first day of week
39
+ import spacetime from 'spacetime'
40
+ import weekStart from 'spacetime-week-start'
41
+ spacetime.extend(weekStart)
47
42
 
48
- `npm i spacetime-week-start`
43
+ let s = spacetime.now('Europe/Berlin')
49
44
 
50
- ```js
51
- const s = require('spacetime-week-start')
52
-
53
- console.log('#1: ', s.weekStart());
54
- console.log('#2: ', s.weekStart(12));
55
- console.log('#3: ', s.weekStart(null));
56
- console.log('#4: ', s.weekStart(''));
57
- console.log('#5: ', s.weekStart(undefined));
58
- console.log('#6: ', s.weekStart('abc'));
59
- // all returns results for current tz, f.e. { day: 'sunday', country: 'canada' }
60
-
61
- console.log('#7: ', weekStart('slovakia'));
62
- // tz: europe/bratislava
63
- // { day: 'monday', country: 'slovakia' }
64
-
65
- console.log('#8: ', weekStart('iran'));
66
- //tz: asia/tehran
67
- // { day: 'saturday', country: 'iran' }
45
+ // with no argument, it uses the timezone of the spacetime object
46
+ s.weekStart()
47
+ // { day: 'monday', country: 'germany' }
68
48
 
69
- console.log('#9: ', weekStart('canAda'));
70
- //tz: f.e. america/montreal
49
+ // or, look up a country by name
50
+ s.weekStart('canada')
71
51
  // { day: 'sunday', country: 'canada' }
72
52
 
73
- console.log('#10: ', weekStart('lize'));
74
- // tz: america/belize
75
- // { day: 'monday', country: 'belize' }
53
+ s.weekStart('iran')
54
+ // { day: 'saturday', country: 'iran' }
55
+ ```
76
56
 
77
- console.log('#11: ', weekStart('el salvador'));
78
- // tz: america/el_salvador
79
- // { day: 'monday', country: 'el salvador' }
57
+ The `weekStart` method accepts one optional argument - the name of a country:
80
58
 
81
- console.log('#12: ', weekStart('zulu'));
82
- // tz: etc/zulu
83
- // { day: 'monday', location: 'zulu' }
59
+ - 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_)
60
+ - the country name can be in any case (lower, upper, camel case)
61
+ - if the country lookup is successful, it returns a simple object:
84
62
 
85
- console.log('#13: ', weekStart('gmt'));
86
- // tz: f.e. etc/gmt
87
- // { day: 'monday', location: 'gmt' }
63
+ ```js
64
+ s.weekStart('united states')
65
+ // { day: 'sunday', country: 'united states of america' }
66
+ ```
88
67
 
89
- console.log('#14: ', weekStart('antarctica'));
90
- // tz: f.e. antarctica/south_pole
91
- // { day: 'monday', location: 'antarctica' }
68
+ - some timezones have general names, such as `gmt`, `utc` or `zulu`. These return:
92
69
 
93
- console.log('#15: ', weekStart('arctic'));
94
- // tz: f.e. arctic/longyearbyen
95
- // { day: 'monday', location: 'arctic' }
70
+ ```js
71
+ spacetime.now('Etc/Zulu').weekStart()
72
+ // { day: 'monday', location: 'zulu' }
96
73
  ```
97
74
 
75
+ - 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
76
+
98
77
  ### Used various sources to determine most accurate guess:
99
78
 
100
79
  - [First Day of the Week in Different Countries](http://chartsbin.com/view/41671)
@@ -104,6 +83,4 @@ console.log('#15: ', weekStart('arctic'));
104
83
  - [Time & Date](https://www.timeanddate.com/worldclock/)
105
84
  - [Time zone converter](http://www.timezoneconverter.com/index.php)
106
85
 
107
- work-in-progress
108
-
109
86
  MIT