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 +13 -0
- package/README.md +46 -69
- package/builds/spacetime-week-start.cjs +1 -6447
- package/builds/spacetime-week-start.min.js +1 -1
- package/builds/spacetime-week-start.mjs +1 -6439
- package/package.json +27 -22
- package/src/index.js +8 -3
- package/_version.js +0 -1
- package/rollup.config.js +0 -31
- package/scratch.js +0 -6
- package/src/data/countries.js +0 -267
- package/src/input/weekStart.js +0 -121
- package/test/basic.test.js +0 -56
- package/types/types.d.ts +0 -202
- package/weekStart-demo.js +0 -47
- package/zonefile/iana.js +0 -2501
package/types/types.d.ts
DELETED
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
import { TimeUnit, Format } from './constraints'
|
|
2
|
-
|
|
3
|
-
export interface SpacetimeMain {
|
|
4
|
-
/** move to a new timezone, but at this same moment. Accepts an IANA code or abbreviation */
|
|
5
|
-
goto: (target: string) => Spacetime
|
|
6
|
-
|
|
7
|
-
/** @returns a copy of this object, with no references to the original */
|
|
8
|
-
clone: () => Spacetime
|
|
9
|
-
|
|
10
|
-
/** @returns a bunch of meta-data about your current timezone */
|
|
11
|
-
timezone: () => TimezoneMeta
|
|
12
|
-
|
|
13
|
-
/** output nicely-formatted strings */
|
|
14
|
-
format: (format: Format) => string | object
|
|
15
|
-
|
|
16
|
-
/** output formatted string using unix formatting code (yyyy.MM.dd h:mm a) */
|
|
17
|
-
unixFmt: (format: string) => string
|
|
18
|
-
|
|
19
|
-
/** move to the first millisecond of the day, week, month, year, etc. */
|
|
20
|
-
startOf: (unit: TimeUnit) => Spacetime
|
|
21
|
-
|
|
22
|
-
/** move to the last millisecond of the day, week, month, year, etc. */
|
|
23
|
-
endOf: (unit: TimeUnit) => Spacetime
|
|
24
|
-
|
|
25
|
-
/** increment the time by a number and unit - like an hour, minute, day, or year */
|
|
26
|
-
add: (value: number, unit: TimeUnit) => Spacetime
|
|
27
|
-
|
|
28
|
-
/** decrease the time by a number and unit - like an hour, minute, day, or year */
|
|
29
|
-
subtract: (value: number, unit: TimeUnit) => Spacetime
|
|
30
|
-
|
|
31
|
-
/** go to the beginning of the next unit */
|
|
32
|
-
next: (unit: TimeUnit) => Spacetime
|
|
33
|
-
|
|
34
|
-
/** go to the beginning of the previous unit */
|
|
35
|
-
last: (unit: TimeUnit) => Spacetime
|
|
36
|
-
|
|
37
|
-
/** pass-in a spacetime object or date input and see if it takes-place after your spacetime date/time */
|
|
38
|
-
isAfter: (other: Spacetime | Date) => Spacetime
|
|
39
|
-
|
|
40
|
-
/** pass-in a spacetime object or date input and see if it takes-place before your spacetime date/time */
|
|
41
|
-
isBefore: (other: Spacetime | Date) => Spacetime
|
|
42
|
-
|
|
43
|
-
/** is this date on the exact same millisecond as another */
|
|
44
|
-
isEqual: (other: Spacetime | Date) => boolean
|
|
45
|
-
|
|
46
|
-
/** detect if two date/times are the same day, week, or year, etc */
|
|
47
|
-
isSame: (other: Spacetime | Date, unit: TimeUnit) => boolean
|
|
48
|
-
|
|
49
|
-
/** given a date and a unit, count how many of them you'd need to make the dates equal */
|
|
50
|
-
diff(value: Spacetime | ParsableDate, unit: TimeUnit): number
|
|
51
|
-
|
|
52
|
-
/** given a date, count how many of various units to make the dates equal */
|
|
53
|
-
diff(value: Spacetime | ParsableDate): Diff
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/** The return types are not actually both number and Spacetime, but this aids in casting to the proper type */
|
|
57
|
-
export interface SpacetimeGetterSetters {
|
|
58
|
-
/** set or return the current number of milliseconds (0-999) */
|
|
59
|
-
millisecond: (value?: number) => number & Spacetime
|
|
60
|
-
|
|
61
|
-
/** set or return the current number of seconds (0-59) */
|
|
62
|
-
second: (value?: number) => number & Spacetime
|
|
63
|
-
|
|
64
|
-
/** set or return the current number of minutes (0-59) */
|
|
65
|
-
minute: (value?: number) => number & Spacetime
|
|
66
|
-
|
|
67
|
-
/** set or return the current hour, in 24 time (0-23). also accepts/parses '3pm' */
|
|
68
|
-
hour: (value?: number | string) => number & Spacetime
|
|
69
|
-
|
|
70
|
-
/** set or return the day-number of the month (1- max31) */
|
|
71
|
-
date: (value?: number) => number & Spacetime
|
|
72
|
-
|
|
73
|
-
/** set or return the zero-based month-number (0-11). Also accepts 'June', or 'oct'. */
|
|
74
|
-
month: (value?: string) => number & Spacetime
|
|
75
|
-
|
|
76
|
-
/** set or return the 4-digit year as an integer */
|
|
77
|
-
year: (value?: number) => number & Spacetime
|
|
78
|
-
|
|
79
|
-
/** set or return a formatted, 12-hour time, like '11:30pm' */
|
|
80
|
-
time: (value?: string) => number & Spacetime
|
|
81
|
-
|
|
82
|
-
/** set or return the week-number of the year (1-52) */
|
|
83
|
-
week: (value?: number) => number & Spacetime
|
|
84
|
-
|
|
85
|
-
/** set or return the fiscal-quarter (1-4) */
|
|
86
|
-
quarter: (value?: number) => number & Spacetime
|
|
87
|
-
|
|
88
|
-
/** set or return the name of the season, spring/summer/fall/autumn/winter */
|
|
89
|
-
season: (value?: string) => string & Spacetime
|
|
90
|
-
|
|
91
|
-
/** set or return the hour + minute in decimal form, so '3:30am' is 3.5 */
|
|
92
|
-
hourFloat: (value?: number) => number & Spacetime
|
|
93
|
-
|
|
94
|
-
/** set or return the day of the week as an integer, starting on sunday (day-0). Also accepts names like 'wednesday', or 'thurs' */
|
|
95
|
-
day: (value?: number | string) => number & Spacetime
|
|
96
|
-
|
|
97
|
-
/** set or return whether the time is am or pm */
|
|
98
|
-
ampm: (value?: string) => string & Spacetime
|
|
99
|
-
|
|
100
|
-
/** set or return the general time-of-day, like 'afternoon' */
|
|
101
|
-
dayTime: (value?: string) => string & Spacetime
|
|
102
|
-
|
|
103
|
-
/** set or return the current month as a string, like 'april' */
|
|
104
|
-
monthName: (value?: string) => string & Spacetime
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export interface SpacetimeUtils {
|
|
108
|
-
/** change to a new date */
|
|
109
|
-
set(date: ParsableDate): Spacetime
|
|
110
|
-
|
|
111
|
-
/** does this time exist on the gregorian/javascript calendar? */
|
|
112
|
-
isValid: () => boolean
|
|
113
|
-
|
|
114
|
-
/** pretty-print the date to the console, for nicer debugging */
|
|
115
|
-
log: () => string
|
|
116
|
-
|
|
117
|
-
/** Between 0-1, how far the moment lands between the start and end of the day/week/month/year. */
|
|
118
|
-
progress: () => Progress
|
|
119
|
-
|
|
120
|
-
/** is the current year a leap year? */
|
|
121
|
-
leapYear: () => boolean
|
|
122
|
-
|
|
123
|
-
/** is daylight-savings-time activated right now, for this timezone? */
|
|
124
|
-
inDST: () => boolean
|
|
125
|
-
|
|
126
|
-
/** does this timezone ever use daylight-savings */
|
|
127
|
-
hasDST: () => boolean
|
|
128
|
-
|
|
129
|
-
/** the current, DST-aware time-difference from UTC, in hours */
|
|
130
|
-
offset: () => number
|
|
131
|
-
|
|
132
|
-
/** checks if the current time is between 10pm and 8am */
|
|
133
|
-
isAsleep: () => boolean
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
export interface Spacetime extends SpacetimeMain, SpacetimeGetterSetters, SpacetimeUtils {
|
|
137
|
-
/** @returns epoch in milliseconds */
|
|
138
|
-
epoch: number
|
|
139
|
-
|
|
140
|
-
/** @returns whether warnings are enabled */
|
|
141
|
-
silent: boolean
|
|
142
|
-
|
|
143
|
-
/** @returns the timezone tz database name, eg, 'america/denver' */
|
|
144
|
-
tz: string
|
|
145
|
-
|
|
146
|
-
/** @returns the tz database nameset */
|
|
147
|
-
timezones: TimezoneSet
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
export interface TimezoneMeta {
|
|
151
|
-
change?: { start: string; back: string }
|
|
152
|
-
current: { offset: number; isDST: boolean }
|
|
153
|
-
default_offset: number
|
|
154
|
-
display: string
|
|
155
|
-
hasDst: boolean
|
|
156
|
-
hemisphere: string
|
|
157
|
-
name: string
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
export interface Progress {
|
|
161
|
-
/** Progress of value from 0-1 */
|
|
162
|
-
day: number
|
|
163
|
-
/** Progress of value from 0-1 */
|
|
164
|
-
hour: number
|
|
165
|
-
/** Progress of value from 0-1 */
|
|
166
|
-
minute: number
|
|
167
|
-
/** Progress of value from 0-1 */
|
|
168
|
-
month: number
|
|
169
|
-
/** Progress of value from 0-1 */
|
|
170
|
-
quarter: number
|
|
171
|
-
/** Progress of value from 0-1 */
|
|
172
|
-
quarterHour: number
|
|
173
|
-
/** Progress of value from 0-1 */
|
|
174
|
-
season: number
|
|
175
|
-
/** Progress of value from 0-1 */
|
|
176
|
-
week: number
|
|
177
|
-
/** Progress of value from 0-1 */
|
|
178
|
-
year: number
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
export interface Diff {
|
|
182
|
-
days: number
|
|
183
|
-
hours: number
|
|
184
|
-
milliseconds: number
|
|
185
|
-
minutes: number
|
|
186
|
-
months: number
|
|
187
|
-
seconds: number
|
|
188
|
-
weeks: number
|
|
189
|
-
years: number
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
/** set where the key is tz database name in lowercase, eg, 'america/denver' */
|
|
193
|
-
export interface TimezoneSet {
|
|
194
|
-
[key: string]: {
|
|
195
|
-
offset: number
|
|
196
|
-
hem: string
|
|
197
|
-
dst?: string
|
|
198
|
-
ctry?: string
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
export type ParsableDate = Date | number | Array<number> | string
|
package/weekStart-demo.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import weekStart from './src/input/weekStart.js';
|
|
2
|
-
|
|
3
|
-
console.log('#1: ', weekStart());
|
|
4
|
-
console.log('#2: ', weekStart(12));
|
|
5
|
-
console.log('#3: ', weekStart(null));
|
|
6
|
-
console.log('#4: ', weekStart(''));
|
|
7
|
-
console.log('#5: ', weekStart(undefined));
|
|
8
|
-
console.log('#6: ', weekStart('abc'));
|
|
9
|
-
// all returns results for current tz, f.e.
|
|
10
|
-
// { day: 'sunday', country: 'canada' }
|
|
11
|
-
|
|
12
|
-
console.log('#7: ', weekStart('slovakia'));
|
|
13
|
-
// tz: europe/bratislava
|
|
14
|
-
// { day: 'monday', country: 'slovakia' }
|
|
15
|
-
|
|
16
|
-
console.log('#8: ', weekStart('iran'));
|
|
17
|
-
//tz: asia/tehran
|
|
18
|
-
// { day: 'saturday', country: 'iran' }
|
|
19
|
-
|
|
20
|
-
console.log('#9: ', weekStart('canAda'));
|
|
21
|
-
//tz: f.e. america/montreal
|
|
22
|
-
// { day: 'sunday', country: 'canada' }
|
|
23
|
-
|
|
24
|
-
console.log('#10: ', weekStart('lize'));
|
|
25
|
-
// tz: america/belize
|
|
26
|
-
// { day: 'monday', country: 'belize' }
|
|
27
|
-
|
|
28
|
-
console.log('#11: ', weekStart('el salvador'));
|
|
29
|
-
// tz: america/el_salvador
|
|
30
|
-
// { day: 'monday', country: 'el salvador' }
|
|
31
|
-
|
|
32
|
-
console.log('#12: ', weekStart('zulu'));
|
|
33
|
-
// tz: etc/zulu
|
|
34
|
-
// { day: 'monday', location: 'zulu' }
|
|
35
|
-
|
|
36
|
-
console.log('#13: ', weekStart('gmt'));
|
|
37
|
-
// tz: f.e. etc/gmt
|
|
38
|
-
// { day: 'monday', location: 'gmt' }
|
|
39
|
-
|
|
40
|
-
console.log('#14: ', weekStart('antarctica'));
|
|
41
|
-
// tz: f.e. antarctica/south_pole
|
|
42
|
-
// { day: 'monday', location: 'antarctica' }
|
|
43
|
-
|
|
44
|
-
console.log('#15: ', weekStart('arctic'));
|
|
45
|
-
// tz: f.e. arctic/longyearbyen
|
|
46
|
-
// { day: 'monday', location: 'arctic' }
|
|
47
|
-
|