datevolt 1.0.0 → 1.0.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/README.md +124 -124
- package/package.json +1 -1
- package/src/index.js +38 -38
- package/src/parse.js +1 -1
- package/src/tempox.js +86 -86
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
#
|
|
1
|
+
# datevolt
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/datevolt)
|
|
4
|
+
[](LICENSE)
|
|
5
5
|
|
|
6
6
|
> **A complete, lightweight, zero-dependency JavaScript date library** with a `moment.js`-compatible chainable API.
|
|
7
7
|
|
|
@@ -17,32 +17,32 @@
|
|
|
17
17
|
## Install
|
|
18
18
|
|
|
19
19
|
```bash
|
|
20
|
-
npm install
|
|
20
|
+
npm install datevolt
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
## Quick Start
|
|
24
24
|
|
|
25
25
|
```js
|
|
26
|
-
const
|
|
26
|
+
const datevolt = require('datevolt');
|
|
27
27
|
|
|
28
28
|
// Current date/time
|
|
29
|
-
|
|
29
|
+
datevolt().format('YYYY-MM-DD HH:mm:ss');
|
|
30
30
|
|
|
31
31
|
// Parse ISO string
|
|
32
|
-
|
|
32
|
+
datevolt('2024-06-15').format('dddd, MMMM D, YYYY'); // "Saturday, June 15, 2024"
|
|
33
33
|
|
|
34
34
|
// Add / subtract
|
|
35
|
-
|
|
35
|
+
datevolt('2024-01-31').add(1, 'month').format('YYYY-MM-DD'); // "2024-02-29"
|
|
36
36
|
|
|
37
37
|
// Relative time
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
datevolt('2024-01-01').fromNow(); // "6 months ago"
|
|
39
|
+
datevolt().add(2, 'hours').toNow(); // "in 2 hours"
|
|
40
40
|
|
|
41
41
|
// Diff
|
|
42
|
-
|
|
42
|
+
datevolt('2024-06-15').diff('2024-01-01', 'days'); // 166
|
|
43
43
|
|
|
44
44
|
// Compare
|
|
45
|
-
|
|
45
|
+
datevolt('2024-06-15').isBefore('2024-12-31'); // true
|
|
46
46
|
```
|
|
47
47
|
|
|
48
48
|
---
|
|
@@ -52,29 +52,29 @@ tempox('2024-06-15').isBefore('2024-12-31'); // true
|
|
|
52
52
|
### Parsing
|
|
53
53
|
|
|
54
54
|
```js
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
55
|
+
datevolt() // now
|
|
56
|
+
datevolt('2024-06-15') // ISO date string (local midnight)
|
|
57
|
+
datevolt('2024-06-15T10:30:00') // ISO datetime
|
|
58
|
+
datevolt('2024-06-15T10:30:00Z') // UTC
|
|
59
|
+
datevolt('2024-06-15T10:30:00+05:30') // with offset
|
|
60
|
+
datevolt('15/06/2024', 'DD/MM/YYYY') // with format string
|
|
61
|
+
datevolt('15/06/2024', ['DD/MM/YYYY', 'YYYY-MM-DD']) // multiple formats
|
|
62
|
+
datevolt([2024, 5, 15]) // array [Y, M(0-based), D]
|
|
63
|
+
datevolt([2024, 5, 15, 14, 30, 0, 0]) // array with time
|
|
64
|
+
datevolt({ year:2024, month:5, day:15 }) // object
|
|
65
|
+
datevolt(1718438400000) // unix milliseconds
|
|
66
|
+
datevolt.unix(1718438400) // unix seconds
|
|
67
|
+
datevolt.utc('2024-06-15T10:30:00') // UTC mode
|
|
68
68
|
|
|
69
69
|
// Validation
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
datevolt('2024-06-15').isValid() // true
|
|
71
|
+
datevolt('not-a-date').isValid() // false
|
|
72
72
|
```
|
|
73
73
|
|
|
74
74
|
### Get + Set
|
|
75
75
|
|
|
76
76
|
```js
|
|
77
|
-
var d =
|
|
77
|
+
var d = datevolt('2024-06-15T14:30:45.123');
|
|
78
78
|
|
|
79
79
|
d.year() // 2024 d.year(2025)
|
|
80
80
|
d.month() // 5 (0-based) d.month(0)
|
|
@@ -101,51 +101,51 @@ d.set('year', 2025) // chainable
|
|
|
101
101
|
### Manipulate
|
|
102
102
|
|
|
103
103
|
```js
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
104
|
+
datevolt().add(7, 'days')
|
|
105
|
+
datevolt().add(1, 'month')
|
|
106
|
+
datevolt().add(2, 'years')
|
|
107
|
+
datevolt().add(3, 'hours')
|
|
108
|
+
datevolt().add(30, 'minutes')
|
|
109
|
+
datevolt().add(15, 'seconds')
|
|
110
|
+
datevolt().add({ days: 1, hours: 2, minutes: 30 }) // object form
|
|
111
111
|
|
|
112
|
-
|
|
113
|
-
|
|
112
|
+
datevolt().subtract(1, 'week')
|
|
113
|
+
datevolt().subtract(3, 'months')
|
|
114
114
|
|
|
115
115
|
// Chained
|
|
116
|
-
|
|
116
|
+
datevolt('2024-01-01').add(1,'year').subtract(3,'months').startOf('month')
|
|
117
117
|
|
|
118
118
|
// startOf / endOf
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
119
|
+
datevolt().startOf('year') // Jan 1, 00:00:00.000
|
|
120
|
+
datevolt().startOf('month') // 1st of month, 00:00:00.000
|
|
121
|
+
datevolt().startOf('week') // locale-aware week start
|
|
122
|
+
datevolt().startOf('day') // 00:00:00.000
|
|
123
|
+
datevolt().startOf('hour')
|
|
124
|
+
datevolt().startOf('minute')
|
|
125
|
+
datevolt().startOf('second')
|
|
126
|
+
datevolt().startOf('quarter')
|
|
127
|
+
datevolt().startOf('isoWeek')
|
|
128
|
+
|
|
129
|
+
datevolt().endOf('year') // Dec 31, 23:59:59.999
|
|
130
|
+
datevolt().endOf('month') // last day, 23:59:59.999
|
|
131
|
+
|
|
132
|
+
datevolt().clone() // immutable copy
|
|
133
133
|
```
|
|
134
134
|
|
|
135
135
|
### Format
|
|
136
136
|
|
|
137
137
|
```js
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
138
|
+
datevolt().format() // "1:30 PM" (LT)
|
|
139
|
+
datevolt().format('YYYY-MM-DD') // "2024-06-15"
|
|
140
|
+
datevolt().format('YYYY-MM-DD HH:mm:ss') // "2024-06-15 14:30:45"
|
|
141
|
+
datevolt().format('dddd, MMMM D, YYYY') // "Saturday, June 15, 2024"
|
|
142
|
+
datevolt().format('MMM Do, YYYY') // "Jun 15th, 2024"
|
|
143
|
+
datevolt().format('h:mm A') // "2:30 PM"
|
|
144
|
+
datevolt().format('[Today is] dddd') // "Today is Saturday"
|
|
145
|
+
datevolt().format('L') // "06/15/2024"
|
|
146
|
+
datevolt().format('LL') // "June 15, 2024"
|
|
147
|
+
datevolt().format('LLL') // "June 15, 2024 2:30 PM"
|
|
148
|
+
datevolt().format('LLLL') // "Saturday, June 15, 2024 2:30 PM"
|
|
149
149
|
```
|
|
150
150
|
|
|
151
151
|
| Token | Output | Description |
|
|
@@ -175,79 +175,79 @@ tempox().format('LLLL') // "Saturday, June 15, 2024 2:30 PM"
|
|
|
175
175
|
### Relative Time
|
|
176
176
|
|
|
177
177
|
```js
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
178
|
+
datevolt('2024-01-01').fromNow() // "6 months ago"
|
|
179
|
+
datevolt().add(2,'hours').fromNow() // "in 2 hours"
|
|
180
|
+
datevolt().subtract(3,'days').fromNow(true) // "3 days" (without suffix)
|
|
181
181
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
182
|
+
datevolt('2024-01-01').from('2024-06-15') // "6 months ago"
|
|
183
|
+
datevolt().add(5,'minutes').toNow() // "in 5 minutes"
|
|
184
|
+
datevolt('2024-01-01').to('2024-06-15') // "in 6 months"
|
|
185
185
|
```
|
|
186
186
|
|
|
187
187
|
### Calendar
|
|
188
188
|
|
|
189
189
|
```js
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
190
|
+
datevolt().calendar() // "Today at 2:30 PM"
|
|
191
|
+
datevolt().add(1,'day').calendar() // "Tomorrow at 2:30 PM"
|
|
192
|
+
datevolt().subtract(1,'day').calendar() // "Yesterday at 2:30 PM"
|
|
193
|
+
datevolt().add(3,'days').calendar() // "Tuesday at 2:30 PM"
|
|
194
|
+
datevolt().subtract(7,'days').calendar() // "06/08/2024"
|
|
195
195
|
```
|
|
196
196
|
|
|
197
197
|
### Diff
|
|
198
198
|
|
|
199
199
|
```js
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
200
|
+
datevolt('2024-06-15').diff('2024-01-01', 'days') // 166
|
|
201
|
+
datevolt('2024-06-15').diff('2024-01-01', 'months') // 5
|
|
202
|
+
datevolt('2024-06-15').diff('2020-01-01', 'years') // 4
|
|
203
|
+
datevolt('2024-06-15T12:00').diff('2024-06-15T10:00', 'hours') // 2
|
|
204
|
+
datevolt('2024-06-15').diff('2024-01-01', 'days', true) // 166.xxx (float)
|
|
205
205
|
```
|
|
206
206
|
|
|
207
207
|
### Query / Comparison
|
|
208
208
|
|
|
209
209
|
```js
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
210
|
+
datevolt('2024-01-01').isBefore('2024-06-15') // true
|
|
211
|
+
datevolt('2024-06-15').isAfter('2024-01-01') // true
|
|
212
|
+
datevolt('2024-06-15T10:00').isSame('2024-06-15T18:00', 'day') // true
|
|
213
|
+
datevolt('2024-01-01').isSameOrBefore('2024-01-01') // true
|
|
214
|
+
datevolt('2024-06-15').isSameOrAfter('2024-06-15') // true
|
|
215
|
+
datevolt('2024-03-15').isBetween('2024-01-01','2024-12-31') // true
|
|
216
|
+
datevolt('2024-01-01').isBetween('2024-01-01','2024-12-31',null,'[]') // inclusive
|
|
217
|
+
|
|
218
|
+
datevolt('2024-06-15').isLeapYear() // true
|
|
219
|
+
datevolt().isDST() // true/false
|
|
220
|
+
datevolt.isMoment(datevolt()) // true (also isdatevolt)
|
|
221
|
+
datevolt.isDate(new Date()) // true
|
|
222
222
|
```
|
|
223
223
|
|
|
224
224
|
### UTC & Timezone
|
|
225
225
|
|
|
226
226
|
```js
|
|
227
227
|
// UTC mode
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
228
|
+
datevolt.utc('2024-06-15T10:30:00').format('HH:mm') // always UTC hours
|
|
229
|
+
datevolt.utc().isUTC() // true
|
|
230
|
+
datevolt.utc().local() // switch to local mode
|
|
231
231
|
|
|
232
232
|
// UTC offset
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
233
|
+
datevolt().utcOffset() // current offset in minutes
|
|
234
|
+
datevolt().utcOffset('+05:30') // set offset
|
|
235
|
+
datevolt().utcOffset(330) // set by minutes
|
|
236
|
+
datevolt().utcOffset(0, true) // keep local time, change offset
|
|
237
237
|
```
|
|
238
238
|
|
|
239
239
|
### Duration
|
|
240
240
|
|
|
241
241
|
```js
|
|
242
|
-
var d =
|
|
242
|
+
var d = datevolt.duration(2, 'days');
|
|
243
243
|
d.asDays() // 2
|
|
244
244
|
d.asHours() // 48
|
|
245
245
|
d.asMinutes() // 2880
|
|
246
246
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
247
|
+
datevolt.duration({ hours: 1, minutes: 30 }).asMinutes() // 90
|
|
248
|
+
datevolt.duration('P1Y2M3DT4H5M6S') // ISO 8601 duration string
|
|
249
|
+
datevolt.duration(1,'day').humanize() // "a day"
|
|
250
|
+
datevolt.duration(1,'day').humanize(true) // "in a day"
|
|
251
251
|
|
|
252
252
|
d.years() / d.months() / d.days() / d.hours() / d.minutes() / d.seconds()
|
|
253
253
|
d.add(1, 'hour').subtract(30, 'minutes')
|
|
@@ -255,45 +255,45 @@ d.clone()
|
|
|
255
255
|
d.toISOString() // "P2D"
|
|
256
256
|
|
|
257
257
|
// Add duration to date
|
|
258
|
-
|
|
258
|
+
datevolt().add(datevolt.duration(2,'hours'))
|
|
259
259
|
|
|
260
|
-
|
|
260
|
+
datevolt.isDuration(d) // true
|
|
261
261
|
```
|
|
262
262
|
|
|
263
263
|
### Locale (i18n)
|
|
264
264
|
|
|
265
265
|
```js
|
|
266
266
|
// Set global locale
|
|
267
|
-
|
|
268
|
-
|
|
267
|
+
datevolt.locale('hi'); // Hindi
|
|
268
|
+
datevolt().format('MMMM D, YYYY'); // "जून 15, 2024"
|
|
269
269
|
|
|
270
270
|
// Per-instance locale
|
|
271
|
-
|
|
271
|
+
datevolt().locale('es').format('MMMM'); // "junio"
|
|
272
272
|
|
|
273
273
|
// Built-in locales
|
|
274
|
-
|
|
274
|
+
datevolt.locales(); // ['en','hi','es','fr','de','ar','ja']
|
|
275
275
|
|
|
276
276
|
// Define custom locale
|
|
277
|
-
|
|
277
|
+
datevolt.defineLocale('mr', {
|
|
278
278
|
name: 'mr',
|
|
279
279
|
months: ['जानेवारी','फेब्रुवारी','मार्च',...],
|
|
280
280
|
// ...
|
|
281
281
|
});
|
|
282
282
|
|
|
283
283
|
// Get locale data
|
|
284
|
-
|
|
285
|
-
|
|
284
|
+
datevolt.localeData('en').months
|
|
285
|
+
datevolt().localeData()
|
|
286
286
|
```
|
|
287
287
|
|
|
288
288
|
### Static Methods
|
|
289
289
|
|
|
290
290
|
```js
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
291
|
+
datevolt.max(a, b, c) // returns latest datevolt
|
|
292
|
+
datevolt.min(a, b, c) // returns earliest datevolt
|
|
293
|
+
datevolt.invalid() // returns an invalid datevolt
|
|
294
|
+
datevolt.normalizeUnits('y') // 'year'
|
|
295
|
+
datevolt.version // '1.0.0'
|
|
296
|
+
datevolt.fn // datevolt.prototype (for plugins)
|
|
297
297
|
```
|
|
298
298
|
|
|
299
299
|
---
|
|
@@ -303,26 +303,26 @@ tempox.fn // Tempox.prototype (for plugins)
|
|
|
303
303
|
Works directly with React Native CLI (Hermes and JSC). No special configuration needed:
|
|
304
304
|
|
|
305
305
|
```bash
|
|
306
|
-
npm install
|
|
306
|
+
npm install datevolt
|
|
307
307
|
```
|
|
308
308
|
|
|
309
309
|
```js
|
|
310
310
|
// In your component
|
|
311
|
-
import
|
|
311
|
+
import datevolt from 'datevolt'; // ESM syntax works too with Metro
|
|
312
312
|
// or
|
|
313
|
-
const
|
|
313
|
+
const datevolt = require('datevolt');
|
|
314
314
|
|
|
315
315
|
const DateDisplay = () => {
|
|
316
|
-
const [display, setDisplay] = React.useState(
|
|
316
|
+
const [display, setDisplay] = React.useState(datevolt().format('LL'));
|
|
317
317
|
return <Text>{display}</Text>;
|
|
318
318
|
};
|
|
319
319
|
```
|
|
320
320
|
|
|
321
321
|
---
|
|
322
322
|
|
|
323
|
-
## Why
|
|
323
|
+
## Why datevolt over moment?
|
|
324
324
|
|
|
325
|
-
| Feature | moment |
|
|
325
|
+
| Feature | moment | datevolt |
|
|
326
326
|
|---------|--------|--------|
|
|
327
327
|
| Size (minified) | ~290 KB | ~25 KB |
|
|
328
328
|
| Size (gzipped) | ~72 KB | ~8 KB |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "datevolt",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "A complete, lightweight, zero-dependency date library with a moment.js-compatible API. Built for React Native CLI (Android & iOS), Node.js, and browsers.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"react-native": "src/index.js",
|
package/src/index.js
CHANGED
|
@@ -1,78 +1,78 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* datevolt - A complete, lightweight, zero-dependency date library
|
|
5
5
|
* with a moment.js-compatible chainable API.
|
|
6
6
|
*
|
|
7
7
|
* Usage (drop-in moment replacement):
|
|
8
|
-
* const
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* const datevolt = require('datevolt');
|
|
9
|
+
* datevolt().format('YYYY-MM-DD');
|
|
10
|
+
* datevolt('2024-01-15').add(1,'month').fromNow();
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
var
|
|
13
|
+
var datevolt = require('./datevolt');
|
|
14
14
|
var Duration = require('./duration');
|
|
15
15
|
var localeModule = require('./locale');
|
|
16
16
|
|
|
17
17
|
// ─── Factory function ─────────────────────────────────────────────────────────
|
|
18
|
-
function
|
|
19
|
-
return new
|
|
18
|
+
function datevolt(input, fmt, strict) {
|
|
19
|
+
return new datevolt(input, fmt, strict, false, undefined);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
// ─── UTC factory ──────────────────────────────────────────────────────────────
|
|
23
|
-
|
|
24
|
-
return new
|
|
23
|
+
datevolt.utc = function(input, fmt, strict) {
|
|
24
|
+
return new datevolt(input, fmt, strict, true, undefined);
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
// ─── Unix factories ──────────────────────────────────────────────────────────
|
|
28
|
-
|
|
29
|
-
return new
|
|
28
|
+
datevolt.unix = function(ts) {
|
|
29
|
+
return new datevolt(ts * 1000);
|
|
30
30
|
};
|
|
31
31
|
|
|
32
32
|
// ─── Clone / check ────────────────────────────────────────────────────────────
|
|
33
|
-
|
|
34
|
-
return !!(obj && obj.
|
|
33
|
+
datevolt.isMoment = datevolt.isdatevolt = function(obj) {
|
|
34
|
+
return !!(obj && obj.__isdatevolt);
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
datevolt.isDate = function(d) {
|
|
38
38
|
return d instanceof Date;
|
|
39
39
|
};
|
|
40
40
|
|
|
41
41
|
// ─── Duration factory ─────────────────────────────────────────────────────────
|
|
42
|
-
|
|
42
|
+
datevolt.duration = function(input, unit) {
|
|
43
43
|
return new Duration(input, unit);
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
datevolt.isDuration = function(d) {
|
|
47
47
|
return !!(d && d.__isDuration);
|
|
48
48
|
};
|
|
49
49
|
|
|
50
50
|
// ─── Min / Max ────────────────────────────────────────────────────────────────
|
|
51
|
-
|
|
51
|
+
datevolt.max = function() {
|
|
52
52
|
var args = Array.isArray(arguments[0]) ? arguments[0] : Array.prototype.slice.call(arguments);
|
|
53
|
-
if (!args.length) return
|
|
53
|
+
if (!args.length) return datevolt.invalid();
|
|
54
54
|
return args.reduce(function(best, cur) {
|
|
55
|
-
var c = cur instanceof
|
|
55
|
+
var c = cur instanceof datevolt ? cur : new datevolt(cur);
|
|
56
56
|
return c.valueOf() > best.valueOf() ? c : best;
|
|
57
57
|
});
|
|
58
58
|
};
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
datevolt.min = function() {
|
|
61
61
|
var args = Array.isArray(arguments[0]) ? arguments[0] : Array.prototype.slice.call(arguments);
|
|
62
|
-
if (!args.length) return
|
|
62
|
+
if (!args.length) return datevolt.invalid();
|
|
63
63
|
return args.reduce(function(best, cur) {
|
|
64
|
-
var c = cur instanceof
|
|
64
|
+
var c = cur instanceof datevolt ? cur : new datevolt(cur);
|
|
65
65
|
return c.valueOf() < best.valueOf() ? c : best;
|
|
66
66
|
});
|
|
67
67
|
};
|
|
68
68
|
|
|
69
69
|
// ─── Invalid moment ───────────────────────────────────────────────────────────
|
|
70
|
-
|
|
71
|
-
return new
|
|
70
|
+
datevolt.invalid = function(flags) {
|
|
71
|
+
return new datevolt(NaN);
|
|
72
72
|
};
|
|
73
73
|
|
|
74
74
|
// ─── Utilities ────────────────────────────────────────────────────────────────
|
|
75
|
-
|
|
75
|
+
datevolt.normalizeUnits = function(unit) {
|
|
76
76
|
var MAP = {
|
|
77
77
|
year:'year',years:'year',y:'year',
|
|
78
78
|
month:'month',months:'month',M:'month',
|
|
@@ -87,18 +87,18 @@ tempox.normalizeUnits = function(unit) {
|
|
|
87
87
|
};
|
|
88
88
|
|
|
89
89
|
// ─── Locale API ──────────────────────────────────────────────────────────────
|
|
90
|
-
|
|
90
|
+
datevolt.locale = function(loc, def) {
|
|
91
91
|
if (loc === undefined) return localeModule.getGlobalLocale();
|
|
92
92
|
if (def) localeModule.defineLocale(loc, def);
|
|
93
93
|
localeModule.setGlobalLocale(loc);
|
|
94
94
|
return localeModule.getGlobalLocale();
|
|
95
95
|
};
|
|
96
96
|
|
|
97
|
-
|
|
97
|
+
datevolt.defineLocale = function(name, config) {
|
|
98
98
|
return localeModule.defineLocale(name, config);
|
|
99
99
|
};
|
|
100
100
|
|
|
101
|
-
|
|
101
|
+
datevolt.updateLocale = function(name, config) {
|
|
102
102
|
var existing = localeModule.getLocale(name) || {};
|
|
103
103
|
for (var k in config) {
|
|
104
104
|
if (Object.prototype.hasOwnProperty.call(config, k)) existing[k] = config[k];
|
|
@@ -107,11 +107,11 @@ tempox.updateLocale = function(name, config) {
|
|
|
107
107
|
return existing;
|
|
108
108
|
};
|
|
109
109
|
|
|
110
|
-
|
|
110
|
+
datevolt.locales = function() {
|
|
111
111
|
return localeModule.listLocales();
|
|
112
112
|
};
|
|
113
113
|
|
|
114
|
-
|
|
114
|
+
datevolt.localeData = function(loc) {
|
|
115
115
|
return localeModule.getLocale(loc || localeModule.getGlobalLocale());
|
|
116
116
|
};
|
|
117
117
|
|
|
@@ -121,13 +121,13 @@ var _relativeThresholds = {
|
|
|
121
121
|
};
|
|
122
122
|
var _relativeRounding = Math.round;
|
|
123
123
|
|
|
124
|
-
|
|
124
|
+
datevolt.relativeTimeThreshold = function(unit, threshold) {
|
|
125
125
|
if (threshold === undefined) return _relativeThresholds[unit];
|
|
126
126
|
_relativeThresholds[unit] = threshold;
|
|
127
127
|
return true;
|
|
128
128
|
};
|
|
129
129
|
|
|
130
|
-
|
|
130
|
+
datevolt.relativeTimeRounding = function(fn) {
|
|
131
131
|
if (fn === undefined) return _relativeRounding;
|
|
132
132
|
_relativeRounding = fn;
|
|
133
133
|
return true;
|
|
@@ -135,16 +135,16 @@ tempox.relativeTimeRounding = function(fn) {
|
|
|
135
135
|
|
|
136
136
|
// ─── Now override (for testing) ──────────────────────────────────────────────
|
|
137
137
|
var _nowFn = null;
|
|
138
|
-
|
|
138
|
+
datevolt.now = function() {
|
|
139
139
|
return _nowFn ? _nowFn() : Date.now();
|
|
140
140
|
};
|
|
141
141
|
|
|
142
142
|
// ─── Version ─────────────────────────────────────────────────────────────────
|
|
143
|
-
|
|
143
|
+
datevolt.version = require('../package.json').version;
|
|
144
144
|
|
|
145
145
|
// ─── Classes exposed for extension ───────────────────────────────────────────
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
146
|
+
datevolt.fn = datevolt.prototype;
|
|
147
|
+
datevolt.datevolt = datevolt;
|
|
148
|
+
datevolt.Duration = Duration;
|
|
149
149
|
|
|
150
|
-
module.exports =
|
|
150
|
+
module.exports = datevolt;
|
package/src/parse.js
CHANGED
|
@@ -113,7 +113,7 @@ function isoWeekYear(d) {
|
|
|
113
113
|
function parseInput(input, fmt, strict, utcMode, tzOffset) {
|
|
114
114
|
if (input === undefined || input === null) return { d: new Date(), utc: !!utcMode, offset: tzOffset };
|
|
115
115
|
|
|
116
|
-
if (input && input.
|
|
116
|
+
if (input && input.__isdatevolt) return { d: new Date(input._d.getTime()), utc: input._utc, offset: input._offset };
|
|
117
117
|
|
|
118
118
|
if (input instanceof Date) return { d: new Date(input.getTime()), utc: !!utcMode, offset: tzOffset };
|
|
119
119
|
|
package/src/tempox.js
CHANGED
|
@@ -18,11 +18,11 @@ var UNIT_MAP = {
|
|
|
18
18
|
function normalizeUnit(u) { return UNIT_MAP[u] || u; }
|
|
19
19
|
|
|
20
20
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
21
|
-
//
|
|
21
|
+
// datevolt constructor
|
|
22
22
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
23
|
-
function
|
|
24
|
-
if (!(this instanceof
|
|
25
|
-
this.
|
|
23
|
+
function datevolt(input, fmt, strict, utcMode, tzOffset) {
|
|
24
|
+
if (!(this instanceof datevolt)) return new datevolt(input, fmt, strict, utcMode, tzOffset);
|
|
25
|
+
this.__isdatevolt = true;
|
|
26
26
|
|
|
27
27
|
var parsed = parseModule.parseInput(input, fmt, strict, utcMode, tzOffset);
|
|
28
28
|
this._d = parsed.d;
|
|
@@ -34,116 +34,116 @@ function Tempox(input, fmt, strict, utcMode, tzOffset) {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
// ─── Private helpers ─────────────────────────────────────────────────────────
|
|
37
|
-
|
|
37
|
+
datevolt.prototype._get = function(method) {
|
|
38
38
|
return this._utc ? this._d['getUTC'+method]() : this._d['get'+method]();
|
|
39
39
|
};
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
datevolt.prototype._set = function(method, val) {
|
|
42
42
|
if (this._utc) this._d['setUTC'+method](val);
|
|
43
43
|
else this._d['set'+method](val);
|
|
44
44
|
return this;
|
|
45
45
|
};
|
|
46
46
|
|
|
47
47
|
// ─── Validation ──────────────────────────────────────────────────────────────
|
|
48
|
-
|
|
48
|
+
datevolt.prototype.isValid = function() {
|
|
49
49
|
if (this._isValid === null) this._isValid = !isNaN(this._d.getTime());
|
|
50
50
|
return this._isValid;
|
|
51
51
|
};
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
datevolt.prototype.invalidAt = function() { return this._pf.overflow; };
|
|
54
|
+
datevolt.prototype.parsingFlags = function() { return this._pf; };
|
|
55
|
+
datevolt.prototype.creationData = function() {
|
|
56
56
|
return { input: undefined, format: undefined, locale: this._locale, isUTC: this._utc, strict: false };
|
|
57
57
|
};
|
|
58
58
|
|
|
59
59
|
// ─── Getters / Setters ───────────────────────────────────────────────────────
|
|
60
|
-
|
|
60
|
+
datevolt.prototype.millisecond = datevolt.prototype.milliseconds = function(v) {
|
|
61
61
|
if (v === undefined) return this._get('Milliseconds');
|
|
62
62
|
this._set('Milliseconds', v); return this;
|
|
63
63
|
};
|
|
64
|
-
|
|
64
|
+
datevolt.prototype.second = datevolt.prototype.seconds = function(v) {
|
|
65
65
|
if (v === undefined) return this._get('Seconds');
|
|
66
66
|
this._set('Seconds', v); return this;
|
|
67
67
|
};
|
|
68
|
-
|
|
68
|
+
datevolt.prototype.minute = datevolt.prototype.minutes = function(v) {
|
|
69
69
|
if (v === undefined) return this._get('Minutes');
|
|
70
70
|
this._set('Minutes', v); return this;
|
|
71
71
|
};
|
|
72
|
-
|
|
72
|
+
datevolt.prototype.hour = datevolt.prototype.hours = function(v) {
|
|
73
73
|
if (v === undefined) return this._get('Hours');
|
|
74
74
|
this._set('Hours', v); return this;
|
|
75
75
|
};
|
|
76
|
-
|
|
76
|
+
datevolt.prototype.date = function(v) {
|
|
77
77
|
if (v === undefined) return this._get('Date');
|
|
78
78
|
this._set('Date', v); return this;
|
|
79
79
|
};
|
|
80
|
-
|
|
80
|
+
datevolt.prototype.day = datevolt.prototype.days = function(v) {
|
|
81
81
|
if (v === undefined) return this._get('Day');
|
|
82
82
|
var current = this._get('Day');
|
|
83
83
|
this._set('Date', this._get('Date') + (v - current));
|
|
84
84
|
return this;
|
|
85
85
|
};
|
|
86
|
-
|
|
86
|
+
datevolt.prototype.weekday = function(v) {
|
|
87
87
|
var dow = localeModule.getLocale(this._locale).week.dow;
|
|
88
88
|
if (v === undefined) return (this._get('Day') + 7 - dow) % 7;
|
|
89
89
|
var current = this.weekday();
|
|
90
90
|
this._set('Date', this._get('Date') + (v - current));
|
|
91
91
|
return this;
|
|
92
92
|
};
|
|
93
|
-
|
|
93
|
+
datevolt.prototype.isoWeekday = function(v) {
|
|
94
94
|
if (v === undefined) return this._get('Day') || 7;
|
|
95
95
|
var d = this._get('Day') || 7;
|
|
96
96
|
this._set('Date', this._get('Date') + (v - d));
|
|
97
97
|
return this;
|
|
98
98
|
};
|
|
99
|
-
|
|
99
|
+
datevolt.prototype.month = datevolt.prototype.months = function(v) {
|
|
100
100
|
if (v === undefined) return this._get('Month');
|
|
101
101
|
this._set('Month', v); return this;
|
|
102
102
|
};
|
|
103
|
-
|
|
103
|
+
datevolt.prototype.year = datevolt.prototype.years = function(v) {
|
|
104
104
|
if (v === undefined) return this._get('FullYear');
|
|
105
105
|
this._set('FullYear', v); return this;
|
|
106
106
|
};
|
|
107
|
-
|
|
107
|
+
datevolt.prototype.quarter = datevolt.prototype.quarters = function(v) {
|
|
108
108
|
if (v === undefined) return Math.ceil((this._get('Month')+1)/3);
|
|
109
109
|
var targetMonth = (v-1)*3;
|
|
110
110
|
this._set('Month', targetMonth);
|
|
111
111
|
return this;
|
|
112
112
|
};
|
|
113
|
-
|
|
113
|
+
datevolt.prototype.dayOfYear = function(v) {
|
|
114
114
|
var start = new Date(this._get('FullYear'), 0, 1);
|
|
115
115
|
var doy = Math.round((this._d - start) / 86400000) + 1;
|
|
116
116
|
if (v === undefined) return doy;
|
|
117
117
|
this._set('Date', this._get('Date') + (v - doy));
|
|
118
118
|
return this;
|
|
119
119
|
};
|
|
120
|
-
|
|
120
|
+
datevolt.prototype.week = datevolt.prototype.weeks = function() {
|
|
121
121
|
return parseModule.weekOfYear(this._d);
|
|
122
122
|
};
|
|
123
|
-
|
|
123
|
+
datevolt.prototype.isoWeek = datevolt.prototype.isoWeeks = function() {
|
|
124
124
|
return parseModule.isoWeekOfYear(this._d);
|
|
125
125
|
};
|
|
126
|
-
|
|
126
|
+
datevolt.prototype.weeksInYear = function() {
|
|
127
127
|
return parseModule.isoWeekOfYear(new Date(this._get('FullYear'), 11, 28));
|
|
128
128
|
};
|
|
129
|
-
|
|
129
|
+
datevolt.prototype.isoWeeksInYear = datevolt.prototype.weeksInYear;
|
|
130
130
|
|
|
131
131
|
// Generic get/set
|
|
132
|
-
|
|
132
|
+
datevolt.prototype.get = function(unit) {
|
|
133
133
|
var u = normalizeUnit(unit);
|
|
134
134
|
return this[u] ? this[u]() : undefined;
|
|
135
135
|
};
|
|
136
|
-
|
|
136
|
+
datevolt.prototype.set = function(unit, val) {
|
|
137
137
|
var u = normalizeUnit(unit);
|
|
138
138
|
if (this[u]) this[u](val);
|
|
139
139
|
return this;
|
|
140
140
|
};
|
|
141
141
|
|
|
142
142
|
// ─── Manipulation ─────────────────────────────────────────────────────────────
|
|
143
|
-
|
|
143
|
+
datevolt.prototype.add = function(amount, unit) {
|
|
144
144
|
return _manipulate(this, amount, unit, 1);
|
|
145
145
|
};
|
|
146
|
-
|
|
146
|
+
datevolt.prototype.subtract = function(amount, unit) {
|
|
147
147
|
return _manipulate(this, amount, unit, -1);
|
|
148
148
|
};
|
|
149
149
|
|
|
@@ -184,7 +184,7 @@ function _manipulate(inst, amount, unit, sign) {
|
|
|
184
184
|
}
|
|
185
185
|
|
|
186
186
|
// ─── startOf / endOf ─────────────────────────────────────────────────────────
|
|
187
|
-
|
|
187
|
+
datevolt.prototype.startOf = function(unit) {
|
|
188
188
|
var u = normalizeUnit(unit);
|
|
189
189
|
var d = this._d;
|
|
190
190
|
switch(u) {
|
|
@@ -206,21 +206,21 @@ Tempox.prototype.startOf = function(unit) {
|
|
|
206
206
|
return this;
|
|
207
207
|
};
|
|
208
208
|
|
|
209
|
-
|
|
209
|
+
datevolt.prototype.endOf = function(unit) {
|
|
210
210
|
return this.startOf(unit).add(1, unit).subtract(1, 'millisecond');
|
|
211
211
|
};
|
|
212
212
|
|
|
213
213
|
// ─── UTC / Local / Offset ─────────────────────────────────────────────────────
|
|
214
|
-
|
|
214
|
+
datevolt.prototype.utc = function() {
|
|
215
215
|
this._utc = true; return this;
|
|
216
216
|
};
|
|
217
|
-
|
|
217
|
+
datevolt.prototype.local = function() {
|
|
218
218
|
this._utc = false; return this;
|
|
219
219
|
};
|
|
220
|
-
|
|
221
|
-
|
|
220
|
+
datevolt.prototype.isUTC = function() { return this._utc; };
|
|
221
|
+
datevolt.prototype.isLocal = function() { return !this._utc; };
|
|
222
222
|
|
|
223
|
-
|
|
223
|
+
datevolt.prototype.utcOffset = function(offset, keepLocalTime) {
|
|
224
224
|
if (offset === undefined) {
|
|
225
225
|
return this._offset !== undefined ? this._offset : -this._d.getTimezoneOffset();
|
|
226
226
|
}
|
|
@@ -234,7 +234,7 @@ Tempox.prototype.utcOffset = function(offset, keepLocalTime) {
|
|
|
234
234
|
return this;
|
|
235
235
|
};
|
|
236
236
|
|
|
237
|
-
|
|
237
|
+
datevolt.prototype.utcOffset.prototype = null;
|
|
238
238
|
|
|
239
239
|
function parseOffsetString(str) {
|
|
240
240
|
var match = str.match(/([+-])(\d{2}):?(\d{2})/);
|
|
@@ -243,21 +243,21 @@ function parseOffsetString(str) {
|
|
|
243
243
|
return sign * (parseInt(match[2],10)*60 + parseInt(match[3],10));
|
|
244
244
|
}
|
|
245
245
|
|
|
246
|
-
|
|
246
|
+
datevolt.prototype.parseZone = function() {
|
|
247
247
|
return this;
|
|
248
248
|
};
|
|
249
249
|
|
|
250
|
-
|
|
250
|
+
datevolt.prototype.isDST = function() {
|
|
251
251
|
var jan = new Date(this._d.getFullYear(),0,1);
|
|
252
252
|
var jul = new Date(this._d.getFullYear(),6,1);
|
|
253
253
|
return this._d.getTimezoneOffset() < Math.max(jan.getTimezoneOffset(), jul.getTimezoneOffset());
|
|
254
254
|
};
|
|
255
255
|
|
|
256
|
-
|
|
257
|
-
|
|
256
|
+
datevolt.prototype.zoneAbbr = function() { return this._utc ? 'UTC' : ''; };
|
|
257
|
+
datevolt.prototype.zoneName = function() { return this._utc ? 'Coordinated Universal Time' : ''; };
|
|
258
258
|
|
|
259
259
|
// ─── Format ───────────────────────────────────────────────────────────────────
|
|
260
|
-
|
|
260
|
+
datevolt.prototype.format = function(fmt) {
|
|
261
261
|
if (!this.isValid()) return localeModule.getLocale(this._locale).invalidDate || 'Invalid date';
|
|
262
262
|
var f = fmt || localeModule.getLocale(this._locale).longDateFormat.LT;
|
|
263
263
|
var loc = localeModule.getLocale(this._locale);
|
|
@@ -298,10 +298,10 @@ function relativeTime(diffMs, thresholds, rt) {
|
|
|
298
298
|
return str;
|
|
299
299
|
}
|
|
300
300
|
|
|
301
|
-
|
|
302
|
-
|
|
301
|
+
datevolt.prototype.fromNow = function(withoutSuffix) { return this.from(new datevolt(), withoutSuffix); };
|
|
302
|
+
datevolt.prototype.toNow = function(withoutSuffix) { return this.to(new datevolt(), withoutSuffix); };
|
|
303
303
|
|
|
304
|
-
|
|
304
|
+
datevolt.prototype.from = function(other, withoutSuffix) {
|
|
305
305
|
var loc = localeModule.getLocale(this._locale);
|
|
306
306
|
var diff = this._d.getTime() - _toDate(other).getTime();
|
|
307
307
|
var str = relativeTime(diff, null, loc.relativeTime);
|
|
@@ -309,7 +309,7 @@ Tempox.prototype.from = function(other, withoutSuffix) {
|
|
|
309
309
|
return diff < 0 ? loc.relativeTime.past.replace('%s',str) : loc.relativeTime.future.replace('%s',str);
|
|
310
310
|
};
|
|
311
311
|
|
|
312
|
-
|
|
312
|
+
datevolt.prototype.to = function(other, withoutSuffix) {
|
|
313
313
|
var loc = localeModule.getLocale(this._locale);
|
|
314
314
|
var diff = _toDate(other).getTime() - this._d.getTime();
|
|
315
315
|
var str = relativeTime(diff, null, loc.relativeTime);
|
|
@@ -318,9 +318,9 @@ Tempox.prototype.to = function(other, withoutSuffix) {
|
|
|
318
318
|
};
|
|
319
319
|
|
|
320
320
|
// ─── Calendar ────────────────────────────────────────────────────────────────
|
|
321
|
-
|
|
321
|
+
datevolt.prototype.calendar = function(refTime, formats) {
|
|
322
322
|
var loc = localeModule.getLocale(this._locale);
|
|
323
|
-
var ref = refTime ? (refTime instanceof
|
|
323
|
+
var ref = refTime ? (refTime instanceof datevolt ? refTime : new datevolt(refTime)) : new datevolt();
|
|
324
324
|
var cal = formats || loc.calendar;
|
|
325
325
|
|
|
326
326
|
var startOfRef = ref.clone().startOf('day');
|
|
@@ -340,20 +340,20 @@ Tempox.prototype.calendar = function(refTime, formats) {
|
|
|
340
340
|
};
|
|
341
341
|
|
|
342
342
|
// ─── Diff ────────────────────────────────────────────────────────────────────
|
|
343
|
-
|
|
343
|
+
datevolt.prototype.diff = function(other, unit, precise) {
|
|
344
344
|
var b = _toDate(other);
|
|
345
345
|
var diffMs = this._d.getTime() - b.getTime();
|
|
346
346
|
var u = normalizeUnit(unit||'millisecond');
|
|
347
347
|
var result;
|
|
348
348
|
switch(u) {
|
|
349
349
|
case 'year':
|
|
350
|
-
result = (this.year() - new
|
|
351
|
-
(this.month() - new
|
|
352
|
-
(this.date() - new
|
|
350
|
+
result = (this.year() - new datevolt(b).year()) +
|
|
351
|
+
(this.month() - new datevolt(b).month())/12 +
|
|
352
|
+
(this.date() - new datevolt(b).date())/(12*30.4375);
|
|
353
353
|
break;
|
|
354
354
|
case 'month':
|
|
355
|
-
result = (this.year()-new
|
|
356
|
-
(this.date()-new
|
|
355
|
+
result = (this.year()-new datevolt(b).year())*12 + (this.month()-new datevolt(b).month()) +
|
|
356
|
+
(this.date()-new datevolt(b).date())/30.4375;
|
|
357
357
|
break;
|
|
358
358
|
case 'week': result = diffMs/604800000; break;
|
|
359
359
|
case 'day': result = diffMs/86400000; break;
|
|
@@ -367,90 +367,90 @@ Tempox.prototype.diff = function(other, unit, precise) {
|
|
|
367
367
|
|
|
368
368
|
// ─── Query methods ───────────────────────────────────────────────────────────
|
|
369
369
|
function _toDate(input) {
|
|
370
|
-
if (input instanceof
|
|
370
|
+
if (input instanceof datevolt) return input._d;
|
|
371
371
|
if (input instanceof Date) return input;
|
|
372
|
-
return new
|
|
372
|
+
return new datevolt(input)._d;
|
|
373
373
|
}
|
|
374
374
|
|
|
375
|
-
|
|
375
|
+
datevolt.prototype.isBefore = function(other, unit) {
|
|
376
376
|
if (!unit) return this._d.getTime() < _toDate(other).getTime();
|
|
377
|
-
return this.clone().endOf(unit)._d < new
|
|
377
|
+
return this.clone().endOf(unit)._d < new datevolt(other).startOf(unit)._d;
|
|
378
378
|
};
|
|
379
|
-
|
|
379
|
+
datevolt.prototype.isAfter = function(other, unit) {
|
|
380
380
|
if (!unit) return this._d.getTime() > _toDate(other).getTime();
|
|
381
|
-
return this.clone().startOf(unit)._d > new
|
|
381
|
+
return this.clone().startOf(unit)._d > new datevolt(other).endOf(unit)._d;
|
|
382
382
|
};
|
|
383
|
-
|
|
383
|
+
datevolt.prototype.isSame = function(other, unit) {
|
|
384
384
|
if (!unit) return this._d.getTime() === _toDate(other).getTime();
|
|
385
|
-
return this.clone().startOf(unit)._d.getTime() === new
|
|
385
|
+
return this.clone().startOf(unit)._d.getTime() === new datevolt(other).startOf(unit)._d.getTime();
|
|
386
386
|
};
|
|
387
|
-
|
|
387
|
+
datevolt.prototype.isSameOrBefore = function(other, unit) {
|
|
388
388
|
return this.isSame(other,unit) || this.isBefore(other,unit);
|
|
389
389
|
};
|
|
390
|
-
|
|
390
|
+
datevolt.prototype.isSameOrAfter = function(other, unit) {
|
|
391
391
|
return this.isSame(other,unit) || this.isAfter(other,unit);
|
|
392
392
|
};
|
|
393
|
-
|
|
393
|
+
datevolt.prototype.isBetween = function(start, end, unit, incl) {
|
|
394
394
|
incl = incl || '()';
|
|
395
395
|
var afterStart = incl[0]==='[' ? this.isSameOrAfter(start,unit) : this.isAfter(start,unit);
|
|
396
396
|
var beforeEnd = incl[1]===']' ? this.isSameOrBefore(end,unit) : this.isBefore(end,unit);
|
|
397
397
|
return afterStart && beforeEnd;
|
|
398
398
|
};
|
|
399
|
-
|
|
399
|
+
datevolt.prototype.isDST = function() {
|
|
400
400
|
var jan = new Date(this._d.getFullYear(),0,1);
|
|
401
401
|
var jul = new Date(this._d.getFullYear(),6,1);
|
|
402
402
|
return this._d.getTimezoneOffset() < Math.max(jan.getTimezoneOffset(),jul.getTimezoneOffset());
|
|
403
403
|
};
|
|
404
|
-
|
|
404
|
+
datevolt.prototype.isLeapYear = function() {
|
|
405
405
|
var y = this.year();
|
|
406
406
|
return (y%4===0 && y%100!==0) || y%400===0;
|
|
407
407
|
};
|
|
408
|
-
|
|
408
|
+
datevolt.prototype.isMoment = datevolt.prototype.isdatevolt = function() { return true; };
|
|
409
409
|
|
|
410
410
|
// ─── Output helpers ──────────────────────────────────────────────────────────
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
411
|
+
datevolt.prototype.valueOf = function() { return this._d.getTime(); };
|
|
412
|
+
datevolt.prototype.unix = function() { return Math.floor(this._d.getTime()/1000); };
|
|
413
|
+
datevolt.prototype.toDate = function() { return new Date(this._d.getTime()); };
|
|
414
|
+
datevolt.prototype.toArray = function() {
|
|
415
415
|
return [this.year(),this.month(),this.date(),this.hour(),this.minute(),this.second(),this.millisecond()];
|
|
416
416
|
};
|
|
417
|
-
|
|
417
|
+
datevolt.prototype.toObject = function() {
|
|
418
418
|
return { years:this.year(), months:this.month(), date:this.date(), hours:this.hour(),
|
|
419
419
|
minutes:this.minute(), seconds:this.second(), milliseconds:this.millisecond() };
|
|
420
420
|
};
|
|
421
|
-
|
|
421
|
+
datevolt.prototype.toISOString = function() {
|
|
422
422
|
return this.isValid() ? this._d.toISOString() : null;
|
|
423
423
|
};
|
|
424
|
-
|
|
425
|
-
|
|
424
|
+
datevolt.prototype.toJSON = datevolt.prototype.toISOString;
|
|
425
|
+
datevolt.prototype.toString = function() {
|
|
426
426
|
return this.format('ddd MMM DD YYYY HH:mm:ss [GMT]ZZ');
|
|
427
427
|
};
|
|
428
|
-
|
|
429
|
-
return '
|
|
428
|
+
datevolt.prototype.inspect = function() {
|
|
429
|
+
return 'datevolt("'+this.format()+'")';
|
|
430
430
|
};
|
|
431
|
-
|
|
431
|
+
datevolt.prototype.daysInMonth = function() {
|
|
432
432
|
return new Date(this.year(), this.month()+1, 0).getDate();
|
|
433
433
|
};
|
|
434
434
|
|
|
435
435
|
// ─── Locale ───────────────────────────────────────────────────────────────────
|
|
436
|
-
|
|
436
|
+
datevolt.prototype.locale = function(loc) {
|
|
437
437
|
if (loc === undefined) return this._locale;
|
|
438
438
|
this._locale = loc;
|
|
439
439
|
return this;
|
|
440
440
|
};
|
|
441
|
-
|
|
441
|
+
datevolt.prototype.lang = datevolt.prototype.locale;
|
|
442
442
|
|
|
443
|
-
|
|
443
|
+
datevolt.prototype.localeData = function() {
|
|
444
444
|
return localeModule.getLocale(this._locale);
|
|
445
445
|
};
|
|
446
446
|
|
|
447
447
|
// ─── Clone ────────────────────────────────────────────────────────────────────
|
|
448
|
-
|
|
449
|
-
var c = new
|
|
448
|
+
datevolt.prototype.clone = function() {
|
|
449
|
+
var c = new datevolt(this._d);
|
|
450
450
|
c._utc = this._utc;
|
|
451
451
|
c._offset = this._offset;
|
|
452
452
|
c._locale = this._locale;
|
|
453
453
|
return c;
|
|
454
454
|
};
|
|
455
455
|
|
|
456
|
-
module.exports =
|
|
456
|
+
module.exports = datevolt;
|