spacetime-week-start 0.1.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/README.md +109 -0
- package/_version.js +1 -0
- package/builds/spacetime-week-start.js +6447 -0
- package/builds/spacetime-week-start.min.js +1 -0
- package/builds/spacetime-week-start.mjs +6439 -0
- package/package.json +45 -0
- package/rollup.config.js +53 -0
- package/scratch.js +6 -0
- package/src/data/countries.js +267 -0
- package/src/index.js +8 -0
- package/src/input/weekStart.js +121 -0
- package/test/basic.test.js +56 -0
- package/types/types.d.ts +202 -0
- package/weekStart-demo.js +47 -0
- package/zonefile/iana.js +2501 -0
package/README.md
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<div>
|
|
3
|
+
<h2>spacetime-week-start</h2>
|
|
4
|
+
</div>
|
|
5
|
+
<div>
|
|
6
|
+
calculate the start of a week
|
|
7
|
+
</div>
|
|
8
|
+
<a href="https://npmjs.org/package/spacetime-week-start">
|
|
9
|
+
<img src="https://img.shields.io/npm/v/spacetime-week-start.svg?style=flat-square" />
|
|
10
|
+
</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" />
|
|
13
|
+
</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
|
+
</div>
|
|
19
|
+
<hr/>
|
|
20
|
+
</div>
|
|
21
|
+
|
|
22
|
+
The start of a week varies officially in different countries.
|
|
23
|
+
|
|
24
|
+
This is a library to help understand week-starts/ends, by country or timezone.
|
|
25
|
+
|
|
26
|
+
It does some opinionated guesswork to determine the most appropriate week-start, when a timezone is given.
|
|
27
|
+
|
|
28
|
+
It returns an english name of the day used in javascript.
|
|
29
|
+
|
|
30
|
+
It is built for use in/with the [spacetime](https://github.com/spencermountain/spacetime) library
|
|
31
|
+
|
|
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
|
+
```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
|
|
47
|
+
|
|
48
|
+
`npm i spacetime-week-start`
|
|
49
|
+
|
|
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' }
|
|
68
|
+
|
|
69
|
+
console.log('#9: ', weekStart('canAda'));
|
|
70
|
+
//tz: f.e. america/montreal
|
|
71
|
+
// { day: 'sunday', country: 'canada' }
|
|
72
|
+
|
|
73
|
+
console.log('#10: ', weekStart('lize'));
|
|
74
|
+
// tz: america/belize
|
|
75
|
+
// { day: 'monday', country: 'belize' }
|
|
76
|
+
|
|
77
|
+
console.log('#11: ', weekStart('el salvador'));
|
|
78
|
+
// tz: america/el_salvador
|
|
79
|
+
// { day: 'monday', country: 'el salvador' }
|
|
80
|
+
|
|
81
|
+
console.log('#12: ', weekStart('zulu'));
|
|
82
|
+
// tz: etc/zulu
|
|
83
|
+
// { day: 'monday', location: 'zulu' }
|
|
84
|
+
|
|
85
|
+
console.log('#13: ', weekStart('gmt'));
|
|
86
|
+
// tz: f.e. etc/gmt
|
|
87
|
+
// { day: 'monday', location: 'gmt' }
|
|
88
|
+
|
|
89
|
+
console.log('#14: ', weekStart('antarctica'));
|
|
90
|
+
// tz: f.e. antarctica/south_pole
|
|
91
|
+
// { day: 'monday', location: 'antarctica' }
|
|
92
|
+
|
|
93
|
+
console.log('#15: ', weekStart('arctic'));
|
|
94
|
+
// tz: f.e. arctic/longyearbyen
|
|
95
|
+
// { day: 'monday', location: 'arctic' }
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Used various sources to determine most accurate guess:
|
|
99
|
+
|
|
100
|
+
- [First Day of the Week in Different Countries](http://chartsbin.com/view/41671)
|
|
101
|
+
- [CLDR - Unicode Common Locale Data Repository](http://cldr.unicode.org/)
|
|
102
|
+
- [CLDR - day and week data file](http://unicode.org/repos/cldr/trunk/common/supplemental/supplementalData.xml)
|
|
103
|
+
- [Wikipedia - Workweek and weekend](https://en.wikipedia.org/wiki/Workweek_and_weekend)
|
|
104
|
+
- [Time & Date](https://www.timeanddate.com/worldclock/)
|
|
105
|
+
- [Time zone converter](http://www.timezoneconverter.com/index.php)
|
|
106
|
+
|
|
107
|
+
work-in-progress
|
|
108
|
+
|
|
109
|
+
MIT
|
package/_version.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default '0.0.1'
|