spacetime-week-start 0.4.0 → 0.5.1

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/rollup.config.js DELETED
@@ -1,26 +0,0 @@
1
- import fs from 'fs'
2
- import terser from '@rollup/plugin-terser'
3
- const pkg = JSON.parse(fs.readFileSync('./package.json').toString())
4
-
5
- console.log('\n 📦 - running rollup..\n')
6
-
7
- const name = 'spacetime-week-start'
8
- const banner = `/* spencermountain/${name} ${pkg.version} MIT */`
9
-
10
- export default [
11
- {
12
- input: 'src/index.js',
13
- output: [{ banner: banner, file: `builds/${name}.mjs`, format: 'esm' }],
14
- plugins: [terser()]
15
- },
16
- {
17
- input: 'src/index.js',
18
- output: [{ banner: banner, file: `builds/${name}.cjs`, format: 'umd', sourcemap: false, name: 'weekStart' }],
19
- plugins: [terser()]
20
- },
21
- {
22
- input: 'src/index.js',
23
- output: [{ banner: banner, file: `builds/${name}.min.js`, format: 'umd', name: 'weekStart' }],
24
- plugins: [terser()]
25
- }
26
- ]
package/scratch.js DELETED
@@ -1,7 +0,0 @@
1
- import spacetime from '../../src/index.js'
2
- import weekStartPlugin from './src/index.js'
3
-
4
- spacetime.extend(weekStartPlugin)
5
- const d = spacetime.now('Europe/Berlin')
6
- console.log(d.weekStart()) // { day: 'monday', country: 'germany' }
7
- console.log(d.weekStart('iran')) // { day: 'saturday', country: 'iran' }
@@ -1,267 +0,0 @@
1
- const loc = {
2
- c009: 'antarctica',
3
- c011: 'arctic',
4
- c081: 'gmt',
5
- c231: 'universal',
6
- c233: 'utc',
7
- c245: 'zulu'
8
- }
9
-
10
- const firstDay = {
11
- monday: {
12
- c002: 'aland islands',
13
- c003: 'albania',
14
- c006: 'andorra',
15
- c007: 'angola',
16
- c008: 'anguilla',
17
- c013: 'armenia',
18
- c014: 'aruba',
19
- c016: 'austria',
20
- c017: 'azerbaijan',
21
- c020: 'barbados',
22
- c021: 'belarus',
23
- c022: 'belgium',
24
- c024: 'benin',
25
- c025: 'bermuda',
26
- c028: 'bonaire',
27
- c029: 'bosnia and herzegovina',
28
- c032: 'british indian ocean territory',
29
- c033: 'brunei',
30
- c034: 'bulgaria',
31
- c035: 'burkina faso',
32
- c036: 'burundi',
33
- c038: 'cameroon',
34
- c040: 'cape verde',
35
- c041: 'cayman islands',
36
- c042: 'central african republic',
37
- c043: 'chad',
38
- c046: 'christmas island',
39
- c047: 'cocos (keeling) islands',
40
- c049: 'comoros',
41
- c050: 'cook islands',
42
- c052: 'croatia',
43
- c053: 'cuba',
44
- c054: 'curacao',
45
- c055: 'cyprus',
46
- c056: 'czech republic',
47
- c057: 'democratic republic of the congo',
48
- c058: 'denmark',
49
- c064: 'equatorial guinea',
50
- c065: 'eritrea',
51
- c066: 'estonia',
52
- c068: 'falkland islands',
53
- c069: 'faroe islands',
54
- c070: 'fiji',
55
- c071: 'finland',
56
- c072: 'france',
57
- c073: 'french guiana',
58
- c074: 'french polynesia',
59
- c075: 'french southern and antarctic lands',
60
- c076: 'gabon',
61
- c077: 'georgia',
62
- c078: 'germany',
63
- c079: 'ghana',
64
- c080: 'gibraltar',
65
- c082: 'greece',
66
- c083: 'greenland',
67
- c084: 'grenada',
68
- c085: 'guadeloupe',
69
- c088: 'guinea',
70
- c089: 'guinea-bissau',
71
- c090: 'guyana',
72
- c091: 'haiti',
73
- c094: 'hungary',
74
- c095: 'iceland',
75
- c097: 'indonesia',
76
- c100: 'ireland',
77
- c102: 'italy',
78
- c103: 'ivory coast',
79
- c107: 'kazakhstan',
80
- c109: 'kiribati',
81
- c111: 'kyrgyzstan',
82
- c113: 'latvia',
83
- c114: 'lebanon',
84
- c115: 'lesotho',
85
- c116: 'liberia',
86
- c118: 'liechtenstein',
87
- c119: 'lithuania',
88
- c120: 'luxembourg',
89
- c123: 'madagascar',
90
- c124: 'malawi',
91
- c127: 'mali',
92
- c130: 'martinique',
93
- c131: 'mauritania',
94
- c132: 'mauritius',
95
- c133: 'mayotte',
96
- c135: 'micronesia',
97
- c137: 'moldova',
98
- c138: 'monaco',
99
- c139: 'mongolia',
100
- c140: 'montenegro',
101
- c141: 'montserrat',
102
- c142: 'morocco',
103
- c145: 'namibia',
104
- c146: 'nauru',
105
- c148: 'netherlands',
106
- c149: 'new caledonia',
107
- c150: 'new zealand',
108
- c152: 'niger',
109
- c153: 'nigeria',
110
- c154: 'niue',
111
- c155: 'norfolk island',
112
- c157: 'northern ireland',
113
- c158: 'northern macedonia',
114
- c160: 'norway',
115
- c162: 'pakistan',
116
- c166: 'papua new guinea',
117
- c170: 'pitcairn islands',
118
- c171: 'poland',
119
- c175: 'republic of the congo',
120
- c176: 'reunion',
121
- c177: 'romania',
122
- c178: 'russia',
123
- c179: 'rwanda',
124
- c180: 'saint helena, ascension and tristan da cunha',
125
- c181: 'saint kitts and nevis',
126
- c182: 'saint lucia',
127
- c183: 'saint pierre and miquelon',
128
- c184: 'saint vincent and the grenadines',
129
- c186: 'san marino',
130
- c187: 'sao tome and principe',
131
- c189: 'senegal',
132
- c190: 'serbia',
133
- c191: 'seychelles',
134
- c192: 'sierra leone',
135
- c194: 'sint maarten',
136
- c195: 'slovakia',
137
- c196: 'slovenia',
138
- c197: 'solomon islands',
139
- c200: 'south georgia and the south sandwich islands',
140
- c203: 'spain',
141
- c204: 'sri lanka',
142
- c206: 'suriname',
143
- c207: 'swaziland',
144
- c208: 'sweden',
145
- c209: 'switzerland',
146
- c212: 'tajikistan',
147
- c213: 'tanzania',
148
- c216: 'the gambia',
149
- c217: 'togo',
150
- c218: 'tokelau',
151
- c219: 'tonga',
152
- c221: 'tunisia',
153
- c222: 'turkey',
154
- c223: 'turkmenistan',
155
- c224: 'turks and caicos islands',
156
- c225: 'tuvalu',
157
- c226: 'uganda',
158
- c227: 'ukraine',
159
- c229: 'united kingdom',
160
- c234: 'uzbekistan',
161
- c235: 'vanuatu',
162
- c236: 'vatican city',
163
- c238: 'vietnam',
164
- c241: 'wallis and futuna',
165
- c243: 'zambia'
166
- },
167
- saturday: {
168
- c019: 'bangladesh',
169
- c059: 'djibouti',
170
- c098: 'iran',
171
- c164: 'palestine',
172
- c198: 'somalia'
173
- },
174
- sunday: {
175
- c001: 'afghanistan',
176
- c004: 'algeria',
177
- c005: 'american samoa',
178
- c010: 'antigua and barbuda',
179
- c012: 'argentina',
180
- c015: 'australia',
181
- c018: 'bahrain',
182
- c023: 'belize',
183
- c026: 'bhutan',
184
- c030: 'botswana',
185
- c031: 'brazil',
186
- c037: 'cambodia',
187
- c039: 'canada',
188
- c044: 'chile',
189
- c045: 'china',
190
- c048: 'colombia',
191
- c051: 'costa rica',
192
- c060: 'dominica',
193
- c061: 'ecuador',
194
- c062: 'egypt',
195
- c063: 'el salvador',
196
- c067: 'ethiopia',
197
- c086: 'guam',
198
- c092: 'honduras',
199
- c093: 'hong kong',
200
- c096: 'india',
201
- c099: 'iraq',
202
- c101: 'israel',
203
- c104: 'jamaica',
204
- c105: 'japan',
205
- c106: 'jordan',
206
- c108: 'kenya',
207
- c110: 'kuwait',
208
- c112: 'laos',
209
- c121: 'macao',
210
- c122: 'macau',
211
- c125: 'malaysia',
212
- c126: 'maldives',
213
- c128: 'malta',
214
- c129: 'marshall islands',
215
- c134: 'mexico',
216
- c136: 'midway atoll',
217
- c143: 'mozambique',
218
- c144: 'myanmar',
219
- c147: 'nepal',
220
- c151: 'nicaragua',
221
- c156: 'north korea',
222
- c159: 'northern mariana islands',
223
- c161: 'oman',
224
- c163: 'palau',
225
- c165: 'panama',
226
- c167: 'paraguay',
227
- c168: 'peru',
228
- c169: 'philippines',
229
- c172: 'portugal',
230
- c173: 'puerto rico',
231
- c174: 'qatar',
232
- c185: 'samoa',
233
- c188: 'saudi arabia',
234
- c193: 'singapore',
235
- c199: 'south africa',
236
- c201: 'south korea',
237
- c202: 'south sudan',
238
- c205: 'sudan',
239
- c210: 'syria',
240
- c211: 'taiwan',
241
- c214: 'thailand',
242
- c215: 'the bahamas',
243
- c220: 'trinidad and tobago',
244
- c228: 'united arab emirates',
245
- c230: 'united states of america',
246
- c232: 'uruguay',
247
- c237: 'venezuela',
248
- c239: 'virgin islands',
249
- c240: 'wake island',
250
- c242: 'yemen',
251
- c244: 'zimbabwe'
252
- }
253
- }
254
-
255
- export default {
256
- countries: () => {
257
- const arr = []
258
- Object.keys(firstDay).forEach(day => {
259
- Object.keys(firstDay[day]).forEach(country => {
260
- arr.push(firstDay[day][country])
261
- })
262
- })
263
- return arr.sort()
264
- },
265
- firstDay: () => firstDay,
266
- locations: () => loc
267
- };
@@ -1,66 +0,0 @@
1
- import c from '../data/countries.js'
2
- import iana from '../../zonefile/iana.js'
3
- const firstDay = c.firstDay()
4
- const loc = c.locations()
5
-
6
- function getCountry(country) {
7
- for (const day in firstDay) {
8
- if (firstDay.hasOwnProperty(day)) {
9
- for (const key in firstDay[day]) {
10
- if (firstDay[day].hasOwnProperty(key)) {
11
- if ((key === country) || (firstDay[day][key].indexOf(country) !== -1)) {
12
- return { day: day, country: firstDay[day][key] }
13
- }
14
- }
15
- }
16
- }
17
- }
18
- for (const item in loc) {
19
- if (loc.hasOwnProperty(item) && loc[item].indexOf(country) !== -1) {
20
- return { day: 'monday', location: country }
21
- }
22
- }
23
- return {}
24
- }
25
-
26
- // find a week-start for an iana timezone name, like 'europe/berlin'
27
- function getCurrent(tz) {
28
- if (!tz || typeof tz !== 'string') {
29
- return null
30
- }
31
- tz = tz.toLowerCase()
32
- const zone = iana[tz]
33
- if (!zone) {
34
- return null
35
- }
36
- if (zone.loc) {
37
- return getCountry(zone.loc)
38
- }
39
- if (zone.ctry) {
40
- return getCountry(zone.ctry)
41
- }
42
- // otherwise, guess from the timezone name itself
43
- let found = getCountry(tz.substr(0, tz.indexOf('/')))
44
- if (found.day) {
45
- return found
46
- }
47
- found = getCountry(tz.substr(tz.indexOf('/') + 1).replace('_', ' '))
48
- if (found.day) {
49
- return found
50
- }
51
- return null
52
- }
53
-
54
- function getWeekStart(country, tz) {
55
- // try a country-name lookup first
56
- if (country && typeof country === 'string') {
57
- const found = getCountry(country.toLowerCase().trim())
58
- if (found.day) {
59
- return found
60
- }
61
- }
62
- // otherwise, use the given timezone
63
- return getCurrent(tz)
64
- }
65
-
66
- export { getWeekStart }
@@ -1,58 +0,0 @@
1
- import test from 'tape'
2
- import spacetime from '../../../src/index.js'
3
- import weekStartPlugin from '../src/index.js'
4
-
5
- spacetime.extend(weekStartPlugin)
6
-
7
- test('uses the timezone of the spacetime object', t => {
8
- t.deepEqual(spacetime.now('Europe/Berlin').weekStart(), { day: 'monday', country: 'germany' })
9
- t.deepEqual(spacetime.now('America/Toronto').weekStart(), { day: 'sunday', country: 'canada' })
10
- t.deepEqual(spacetime.now('Asia/Tehran').weekStart(), { day: 'saturday', country: 'iran' })
11
- t.end()
12
- })
13
-
14
- test('general timezones return a location', t => {
15
- t.deepEqual(spacetime.now('Etc/Zulu').weekStart(), { day: 'monday', location: 'zulu' })
16
- t.end()
17
- })
18
-
19
- test('falsy or unknown input falls back to the timezone', t => {
20
- const s = spacetime.now('America/Toronto')
21
- t.deepEqual(s.weekStart(null), { day: 'sunday', country: 'canada' })
22
- t.deepEqual(s.weekStart(''), { day: 'sunday', country: 'canada' })
23
- t.deepEqual(s.weekStart(12), { day: 'sunday', country: 'canada' })
24
- t.deepEqual(s.weekStart('xyzxyz'), { day: 'sunday', country: 'canada' })
25
- t.end()
26
- })
27
-
28
- test('a country name wins over the timezone', t => {
29
- const s = spacetime.now('Europe/Berlin')
30
- t.equal(s.weekStart('canada').day, 'sunday')
31
- t.equal(s.weekStart('canada').country, 'canada')
32
- t.equal(s.weekStart('iran').day, 'saturday')
33
- t.end()
34
- })
35
-
36
- test('partial country names match', t => {
37
- const s = spacetime.now('America/Toronto')
38
- t.equal(s.weekStart('united arab emirates').day, 'sunday')
39
- t.equal(s.weekStart('emirates').country, 'united arab emirates')
40
- t.end()
41
- })
42
-
43
- test('country name can be in lower case, upper case or camel case', t => {
44
- const s = spacetime.now('America/Toronto')
45
- t.equal(s.weekStart('cana').day, 'sunday')
46
- t.equal(s.weekStart('nada').country, 'grenada')
47
- t.notEqual(s.weekStart('nada').country, 'canada')
48
- // finds first occourance of string 'nada' in JSON
49
- t.equal(s.weekStart('CANADA').day, 'sunday')
50
- t.equal(s.weekStart('Canada').country, 'canada')
51
- // it's located in array under key "monday" for
52
- // grenada and after that appears located in
53
- // canada under key "sunday"
54
- t.equal(s.weekStart('CaNa').day, 'sunday')
55
- t.equal(s.weekStart('nAdA').country, 'grenada')
56
- t.notEqual(s.weekStart('nAdA').country, 'canada')
57
- t.end()
58
- })