spacetime-week-start 0.3.0 → 0.4.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 CHANGED
@@ -8,9 +8,6 @@
8
8
  <a href="https://npmjs.org/package/spacetime-week-start">
9
9
  <img src="https://img.shields.io/npm/v/spacetime-week-start.svg?style=flat-square" />
10
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
11
  <div>
15
12
  <sup>
16
13
  By <a href="https://github.com/MartinSpd">Martin Spodniak</a> and <a href="https://github.com/spencermountain">Spencer Kelly</a>
@@ -21,80 +18,53 @@
21
18
 
22
19
  The start of a week varies officially in different countries.
23
20
 
24
- This is a library to help understand week-starts/ends, by country or timezone.
21
+ This is a plugin for the [spacetime](https://github.com/spencermountain/spacetime) library, to help understand week-starts/ends, by country or timezone.
25
22
 
26
23
  It does some opinionated guesswork to determine the most appropriate week-start, when a timezone is given.
27
24
 
28
25
  It returns an english name of the day used in javascript.
29
26
 
30
- It is built for use in/with the [spacetime](https://github.com/spencermountain/spacetime) library
27
+ `npm i spacetime-week-start`
31
28
 
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
29
  ```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
30
+ import spacetime from 'spacetime'
31
+ import weekStart from 'spacetime-week-start'
32
+ spacetime.extend(weekStart)
47
33
 
48
- `npm i spacetime-week-start`
34
+ let s = spacetime.now('Europe/Berlin')
49
35
 
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' }
36
+ // with no argument, it uses the timezone of the spacetime object
37
+ s.weekStart()
38
+ // { day: 'monday', country: 'germany' }
68
39
 
69
- console.log('#9: ', weekStart('canAda'));
70
- //tz: f.e. america/montreal
40
+ // or, look up a country by name
41
+ s.weekStart('canada')
71
42
  // { day: 'sunday', country: 'canada' }
72
43
 
73
- console.log('#10: ', weekStart('lize'));
74
- // tz: america/belize
75
- // { day: 'monday', country: 'belize' }
44
+ s.weekStart('iran')
45
+ // { day: 'saturday', country: 'iran' }
46
+ ```
76
47
 
77
- console.log('#11: ', weekStart('el salvador'));
78
- // tz: america/el_salvador
79
- // { day: 'monday', country: 'el salvador' }
48
+ The `weekStart` method accepts one optional argument - the name of a country:
80
49
 
81
- console.log('#12: ', weekStart('zulu'));
82
- // tz: etc/zulu
83
- // { day: 'monday', location: 'zulu' }
50
+ - 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*)
51
+ - the country name can be in any case (lower, upper, camel case)
52
+ - if the country lookup is successful, it returns a simple object:
84
53
 
85
- console.log('#13: ', weekStart('gmt'));
86
- // tz: f.e. etc/gmt
87
- // { day: 'monday', location: 'gmt' }
54
+ ```js
55
+ s.weekStart('united states')
56
+ // { day: 'sunday', country: 'united states of america' }
57
+ ```
88
58
 
89
- console.log('#14: ', weekStart('antarctica'));
90
- // tz: f.e. antarctica/south_pole
91
- // { day: 'monday', location: 'antarctica' }
59
+ - some timezones have general names, such as `gmt`, `utc` or `zulu`. These return:
92
60
 
93
- console.log('#15: ', weekStart('arctic'));
94
- // tz: f.e. arctic/longyearbyen
95
- // { day: 'monday', location: 'arctic' }
61
+ ```js
62
+ spacetime.now('Etc/Zulu').weekStart()
63
+ // { day: 'monday', location: 'zulu' }
96
64
  ```
97
65
 
66
+ - 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
67
+
98
68
  ### Used various sources to determine most accurate guess:
99
69
 
100
70
  - [First Day of the Week in Different Countries](http://chartsbin.com/view/41671)
@@ -104,6 +74,4 @@ console.log('#15: ', weekStart('arctic'));
104
74
  - [Time & Date](https://www.timeanddate.com/worldclock/)
105
75
  - [Time zone converter](http://www.timezoneconverter.com/index.php)
106
76
 
107
- work-in-progress
108
-
109
77
  MIT