@naturalcycles/js-lib 14.96.0 → 14.97.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/dist/datetime/dateInterval.d.ts +8 -7
- package/dist/datetime/dateInterval.js +18 -15
- package/dist/datetime/localDate.d.ts +20 -17
- package/dist/datetime/localDate.js +130 -102
- package/dist/datetime/localTime.d.ts +14 -12
- package/dist/datetime/localTime.js +34 -11
- package/dist/datetime/timeInterval.d.ts +38 -0
- package/dist/datetime/timeInterval.js +91 -0
- package/dist/error/try.d.ts +8 -2
- package/dist/error/try.js +7 -1
- package/dist/error/tryCatch.d.ts +1 -1
- package/dist/error/tryCatch.js +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.js +1 -0
- package/dist/types.d.ts +11 -3
- package/dist-esm/datetime/dateInterval.js +18 -15
- package/dist-esm/datetime/localDate.js +130 -102
- package/dist-esm/datetime/localTime.js +34 -11
- package/dist-esm/datetime/timeInterval.js +87 -0
- package/dist-esm/error/try.js +7 -1
- package/dist-esm/error/tryCatch.js +2 -2
- package/dist-esm/index.js +1 -0
- package/package.json +1 -1
- package/src/datetime/dateInterval.ts +22 -18
- package/src/datetime/localDate.ts +149 -132
- package/src/datetime/localTime.ts +48 -22
- package/src/datetime/timeInterval.ts +104 -0
- package/src/error/try.ts +9 -3
- package/src/error/tryCatch.ts +3 -3
- package/src/index.ts +10 -2
- package/src/types.ts +13 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { LocalDate, LocalDateConfig } from './localDate'
|
|
1
|
+
import { Inclusiveness, LocalDate, LocalDateConfig, LocalDateUnit } from './localDate'
|
|
2
2
|
|
|
3
|
-
export type DateIntervalConfig = DateInterval |
|
|
3
|
+
export type DateIntervalConfig = DateInterval | DateIntervalString
|
|
4
4
|
export type DateIntervalString = string
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -34,16 +34,18 @@ export class DateInterval {
|
|
|
34
34
|
return this.cmp(d) === 0
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
isBefore(d: DateIntervalConfig): boolean {
|
|
38
|
-
|
|
37
|
+
isBefore(d: DateIntervalConfig, inclusive = false): boolean {
|
|
38
|
+
const r = this.cmp(d)
|
|
39
|
+
return r === -1 || (r === 0 && inclusive)
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
isSameOrBefore(d: DateIntervalConfig): boolean {
|
|
42
43
|
return this.cmp(d) <= 0
|
|
43
44
|
}
|
|
44
45
|
|
|
45
|
-
isAfter(d: DateIntervalConfig): boolean {
|
|
46
|
-
|
|
46
|
+
isAfter(d: DateIntervalConfig, inclusive = false): boolean {
|
|
47
|
+
const r = this.cmp(d)
|
|
48
|
+
return r === 1 || (r === 0 && inclusive)
|
|
47
49
|
}
|
|
48
50
|
|
|
49
51
|
isSameOrAfter(d: DateIntervalConfig): boolean {
|
|
@@ -53,9 +55,15 @@ export class DateInterval {
|
|
|
53
55
|
/**
|
|
54
56
|
* Ranges of DateInterval (start, end) are INCLUSIVE.
|
|
55
57
|
*/
|
|
56
|
-
includes(d: LocalDateConfig): boolean {
|
|
58
|
+
includes(d: LocalDateConfig, incl: Inclusiveness = '[]'): boolean {
|
|
57
59
|
d = LocalDate.of(d)
|
|
58
|
-
return d.
|
|
60
|
+
return d.isAfter(this.start, incl[0] === '[') && d.isBefore(this.end, incl[1] === ']')
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
intersects(int: DateIntervalConfig, inclusive = true): boolean {
|
|
64
|
+
const $int = DateInterval.parse(int)
|
|
65
|
+
const incl = inclusive ? '[]' : '()'
|
|
66
|
+
return this.includes($int.start, incl) || this.includes($int.end, incl)
|
|
59
67
|
}
|
|
60
68
|
|
|
61
69
|
/**
|
|
@@ -67,19 +75,15 @@ export class DateInterval {
|
|
|
67
75
|
return this.start.cmp(d.start) || this.end.cmp(d.end)
|
|
68
76
|
}
|
|
69
77
|
|
|
78
|
+
getDays(incl: Inclusiveness = '[]'): LocalDate[] {
|
|
79
|
+
return LocalDate.range(this.start, this.end, incl, 1, 'day')
|
|
80
|
+
}
|
|
81
|
+
|
|
70
82
|
/**
|
|
71
83
|
* Returns an array of LocalDates that are included in the interval.
|
|
72
|
-
* Ranges are INCLUSIVE.
|
|
73
84
|
*/
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
let current = this.start
|
|
77
|
-
do {
|
|
78
|
-
days.push(current)
|
|
79
|
-
current = current.add(1, 'day')
|
|
80
|
-
} while (current.isSameOrBefore(this.end))
|
|
81
|
-
|
|
82
|
-
return days
|
|
85
|
+
range(incl: Inclusiveness = '[]', step = 1, stepUnit: LocalDateUnit = 'day'): LocalDate[] {
|
|
86
|
+
return LocalDate.range(this.start, this.end, incl, step, stepUnit)
|
|
83
87
|
}
|
|
84
88
|
|
|
85
89
|
toString(): DateIntervalString {
|
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
import { _assert } from '../error/assert'
|
|
2
|
-
import {
|
|
3
|
-
import { END, IsoDate, UnixTimestamp } from '../types'
|
|
2
|
+
import { IsoDateString, UnixTimestampNumber } from '../types'
|
|
4
3
|
import { LocalTime } from './localTime'
|
|
5
4
|
|
|
6
5
|
export type LocalDateUnit = 'year' | 'month' | 'day'
|
|
7
6
|
export type Inclusiveness = '()' | '[]' | '[)' | '(]'
|
|
8
7
|
|
|
9
|
-
const
|
|
8
|
+
const MDAYS = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
|
|
9
|
+
const DATE_REGEX = /^(\d\d\d\d)-(\d\d)-(\d\d)$/
|
|
10
10
|
|
|
11
|
-
export type LocalDateConfig = LocalDate |
|
|
11
|
+
export type LocalDateConfig = LocalDate | IsoDateString
|
|
12
|
+
|
|
13
|
+
/* eslint-disable no-dupe-class-members */
|
|
12
14
|
|
|
13
15
|
/**
|
|
14
16
|
* @experimental
|
|
15
17
|
*/
|
|
16
18
|
export class LocalDate {
|
|
17
|
-
private constructor(
|
|
19
|
+
private constructor(private $year: number, private $month: number, private $day: number) {}
|
|
18
20
|
|
|
19
21
|
static create(year: number, month: number, day: number): LocalDate {
|
|
20
22
|
return new LocalDate(year, month, day)
|
|
@@ -59,8 +61,13 @@ export class LocalDate {
|
|
|
59
61
|
if (!d) return null
|
|
60
62
|
if (d instanceof LocalDate) return d
|
|
61
63
|
|
|
62
|
-
//
|
|
63
|
-
const
|
|
64
|
+
// const [year, month, day] = d.slice(0, 10).split('-').map(Number)
|
|
65
|
+
const matches = DATE_REGEX.exec(d.slice(0, 10))
|
|
66
|
+
if (!matches) return null
|
|
67
|
+
|
|
68
|
+
const year = Number(matches[1])
|
|
69
|
+
const month = Number(matches[2])
|
|
70
|
+
const day = Number(matches[3])
|
|
64
71
|
|
|
65
72
|
if (
|
|
66
73
|
!year ||
|
|
@@ -77,6 +84,11 @@ export class LocalDate {
|
|
|
77
84
|
return new LocalDate(year, month, day)
|
|
78
85
|
}
|
|
79
86
|
|
|
87
|
+
// Can use just .toString()
|
|
88
|
+
// static parseToString(d: LocalDateConfig): IsoDateString {
|
|
89
|
+
// return typeof d === 'string' ? d : d.toString()
|
|
90
|
+
// }
|
|
91
|
+
|
|
80
92
|
static isValid(iso: string | undefined | null): boolean {
|
|
81
93
|
return this.parseOrNull(iso) !== null
|
|
82
94
|
}
|
|
@@ -115,81 +127,83 @@ export class LocalDate {
|
|
|
115
127
|
}
|
|
116
128
|
|
|
117
129
|
static range(
|
|
118
|
-
|
|
119
|
-
|
|
130
|
+
min: LocalDateConfig,
|
|
131
|
+
max: LocalDateConfig,
|
|
132
|
+
incl: Inclusiveness = '[)',
|
|
120
133
|
step = 1,
|
|
121
134
|
stepUnit: LocalDateUnit = 'day',
|
|
122
135
|
): LocalDate[] {
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
const max = LocalDate.of(
|
|
136
|
+
const dates: LocalDate[] = []
|
|
137
|
+
const $min = LocalDate.of(min)
|
|
138
|
+
const $max = LocalDate.of(max).startOf(stepUnit)
|
|
139
|
+
|
|
140
|
+
let current = $min.startOf(stepUnit)
|
|
141
|
+
if (current.isAfter($min, incl[0] === '[')) {
|
|
142
|
+
// ok
|
|
143
|
+
} else {
|
|
144
|
+
current.add(1, stepUnit, true)
|
|
145
|
+
}
|
|
126
146
|
|
|
127
|
-
|
|
128
|
-
|
|
147
|
+
const incl2 = incl[1] === ']'
|
|
148
|
+
while (current.isBefore($max, incl2)) {
|
|
149
|
+
dates.push(current)
|
|
129
150
|
current = current.add(step, stepUnit)
|
|
130
|
-
}
|
|
151
|
+
}
|
|
131
152
|
|
|
132
|
-
return
|
|
153
|
+
return dates
|
|
133
154
|
}
|
|
134
155
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
maxExcl: LocalDateConfig,
|
|
138
|
-
step = 1,
|
|
139
|
-
stepUnit: LocalDateUnit = 'day',
|
|
140
|
-
): Sequence<LocalDate> {
|
|
141
|
-
const min = LocalDate.of(minIncl).startOf(stepUnit)
|
|
142
|
-
const max = LocalDate.of(maxExcl).startOf(stepUnit)
|
|
143
|
-
return Sequence.create(min, d => {
|
|
144
|
-
const next = d.add(step, stepUnit)
|
|
145
|
-
return next.isAfter(max) ? END : next
|
|
146
|
-
})
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
static rangeString(
|
|
150
|
-
minIncl: LocalDateConfig,
|
|
151
|
-
maxExcl: LocalDateConfig,
|
|
152
|
-
step = 1,
|
|
153
|
-
stepUnit: LocalDateUnit = 'day',
|
|
154
|
-
): IsoDate[] {
|
|
155
|
-
return LocalDate.range(minIncl, maxExcl, step, stepUnit).map(ld => ld.toString())
|
|
156
|
+
get(unit: LocalDateUnit): number {
|
|
157
|
+
return unit === 'year' ? this.$year : unit === 'month' ? this.$month : this.$day
|
|
156
158
|
}
|
|
157
159
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
160
|
+
set(unit: LocalDateUnit, v: number, mutate = false): LocalDate {
|
|
161
|
+
const t = mutate ? this : this.clone()
|
|
162
|
+
|
|
163
|
+
if (unit === 'year') {
|
|
164
|
+
t.$year = v
|
|
165
|
+
} else if (unit === 'month') {
|
|
166
|
+
t.$month = v
|
|
167
|
+
} else {
|
|
168
|
+
t.$day = v
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return t
|
|
165
172
|
}
|
|
166
173
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
):
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
)
|
|
174
|
+
year(): number
|
|
175
|
+
year(v: number): LocalDate
|
|
176
|
+
year(v?: number): number | LocalDate {
|
|
177
|
+
return v === undefined ? this.$year : this.set('year', v)
|
|
178
|
+
}
|
|
179
|
+
month(): number
|
|
180
|
+
month(v: number): LocalDate
|
|
181
|
+
month(v?: number): number | LocalDate {
|
|
182
|
+
return v === undefined ? this.$month : this.set('month', v)
|
|
183
|
+
}
|
|
184
|
+
day(): number
|
|
185
|
+
day(v: number): LocalDate
|
|
186
|
+
day(v?: number): number | LocalDate {
|
|
187
|
+
return v === undefined ? this.$day : this.set('day', v)
|
|
176
188
|
}
|
|
177
189
|
|
|
178
190
|
isSame(d: LocalDateConfig): boolean {
|
|
179
191
|
d = LocalDate.of(d)
|
|
180
|
-
return this
|
|
192
|
+
return this.$day === d.$day && this.$month === d.$month && this.$year === d.$year
|
|
181
193
|
}
|
|
182
194
|
|
|
183
|
-
isBefore(d: LocalDateConfig): boolean {
|
|
184
|
-
|
|
195
|
+
isBefore(d: LocalDateConfig, inclusive = false): boolean {
|
|
196
|
+
const r = this.cmp(d)
|
|
197
|
+
return r === -1 || (r === 0 && inclusive)
|
|
185
198
|
}
|
|
186
199
|
|
|
187
200
|
isSameOrBefore(d: LocalDateConfig): boolean {
|
|
188
201
|
return this.cmp(d) <= 0
|
|
189
202
|
}
|
|
190
203
|
|
|
191
|
-
isAfter(d: LocalDateConfig): boolean {
|
|
192
|
-
|
|
204
|
+
isAfter(d: LocalDateConfig, inclusive = false): boolean {
|
|
205
|
+
const r = this.cmp(d)
|
|
206
|
+
return r === 1 || (r === 0 && inclusive)
|
|
193
207
|
}
|
|
194
208
|
|
|
195
209
|
isSameOrAfter(d: LocalDateConfig): boolean {
|
|
@@ -211,12 +225,12 @@ export class LocalDate {
|
|
|
211
225
|
*/
|
|
212
226
|
cmp(d: LocalDateConfig): -1 | 0 | 1 {
|
|
213
227
|
d = LocalDate.of(d)
|
|
214
|
-
if (this
|
|
215
|
-
if (this
|
|
216
|
-
if (this
|
|
217
|
-
if (this
|
|
218
|
-
if (this
|
|
219
|
-
if (this
|
|
228
|
+
if (this.$year < d.$year) return -1
|
|
229
|
+
if (this.$year > d.$year) return 1
|
|
230
|
+
if (this.$month < d.$month) return -1
|
|
231
|
+
if (this.$month > d.$month) return 1
|
|
232
|
+
if (this.$day < d.$day) return -1
|
|
233
|
+
if (this.$day > d.$day) return 1
|
|
220
234
|
return 0
|
|
221
235
|
}
|
|
222
236
|
|
|
@@ -236,33 +250,33 @@ export class LocalDate {
|
|
|
236
250
|
d = LocalDate.of(d)
|
|
237
251
|
|
|
238
252
|
if (unit === 'year') {
|
|
239
|
-
return this
|
|
253
|
+
return this.$year - d.$year
|
|
240
254
|
}
|
|
241
255
|
|
|
242
256
|
if (unit === 'month') {
|
|
243
|
-
return (this
|
|
257
|
+
return (this.$year - d.$year) * 12 + (this.$month - d.$month)
|
|
244
258
|
}
|
|
245
259
|
|
|
246
260
|
// unit is 'day'
|
|
247
|
-
let days = this
|
|
261
|
+
let days = this.$day - d.$day
|
|
248
262
|
|
|
249
|
-
if (d
|
|
250
|
-
for (let year = d
|
|
263
|
+
if (d.$year < this.$year) {
|
|
264
|
+
for (let year = d.$year; year < this.$year; year++) {
|
|
251
265
|
days += LocalDate.getYearLength(year)
|
|
252
266
|
}
|
|
253
|
-
} else if (this
|
|
254
|
-
for (let year = this
|
|
267
|
+
} else if (this.$year < d.$year) {
|
|
268
|
+
for (let year = this.$year; year < d.$year; year++) {
|
|
255
269
|
days -= LocalDate.getYearLength(year)
|
|
256
270
|
}
|
|
257
271
|
}
|
|
258
272
|
|
|
259
|
-
if (d
|
|
260
|
-
for (let month = d
|
|
261
|
-
days += LocalDate.getMonthLength(this
|
|
273
|
+
if (d.$month < this.$month) {
|
|
274
|
+
for (let month = d.$month; month < this.$month; month++) {
|
|
275
|
+
days += LocalDate.getMonthLength(this.$year, month)
|
|
262
276
|
}
|
|
263
|
-
} else if (this
|
|
264
|
-
for (let month = this
|
|
265
|
-
days -= LocalDate.getMonthLength(d
|
|
277
|
+
} else if (this.$month < d.$month) {
|
|
278
|
+
for (let month = this.$month; month < d.$month; month++) {
|
|
279
|
+
days -= LocalDate.getMonthLength(d.$year, month)
|
|
266
280
|
}
|
|
267
281
|
}
|
|
268
282
|
|
|
@@ -270,57 +284,62 @@ export class LocalDate {
|
|
|
270
284
|
}
|
|
271
285
|
|
|
272
286
|
add(num: number, unit: LocalDateUnit, mutate = false): LocalDate {
|
|
273
|
-
let { day, month, year } = this
|
|
287
|
+
let { $day, $month, $year } = this
|
|
274
288
|
|
|
275
289
|
if (unit === 'day') {
|
|
276
|
-
day += num
|
|
290
|
+
$day += num
|
|
277
291
|
} else if (unit === 'month') {
|
|
278
|
-
month += num
|
|
292
|
+
$month += num
|
|
279
293
|
} else if (unit === 'year') {
|
|
280
|
-
year += num
|
|
294
|
+
$year += num
|
|
281
295
|
}
|
|
282
296
|
|
|
283
297
|
// check day overflow
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
298
|
+
if (unit === 'day') {
|
|
299
|
+
if ($day < 1) {
|
|
300
|
+
while ($day < 1) {
|
|
301
|
+
$month -= 1
|
|
302
|
+
if ($month < 1) {
|
|
303
|
+
$year -= 1
|
|
304
|
+
$month += 12
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
$day += LocalDate.getMonthLength($year, $month)
|
|
308
|
+
}
|
|
309
|
+
} else {
|
|
310
|
+
let monLen = LocalDate.getMonthLength($year, $month)
|
|
311
|
+
|
|
312
|
+
while ($day > monLen) {
|
|
313
|
+
$day -= monLen
|
|
314
|
+
$month += 1
|
|
315
|
+
if ($month > 12) {
|
|
316
|
+
$year += 1
|
|
317
|
+
$month -= 12
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
monLen = LocalDate.getMonthLength($year, $month)
|
|
321
|
+
}
|
|
301
322
|
}
|
|
302
|
-
|
|
303
|
-
monLen = LocalDate.getMonthLength(year, month)
|
|
304
323
|
}
|
|
305
324
|
|
|
306
325
|
// check month overflow
|
|
307
|
-
while (month > 12) {
|
|
308
|
-
year += 1
|
|
309
|
-
month -= 12
|
|
326
|
+
while ($month > 12) {
|
|
327
|
+
$year += 1
|
|
328
|
+
$month -= 12
|
|
310
329
|
}
|
|
311
|
-
while (month < 1) {
|
|
312
|
-
year -= 1
|
|
313
|
-
month += 12
|
|
330
|
+
while ($month < 1) {
|
|
331
|
+
$year -= 1
|
|
332
|
+
$month += 12
|
|
314
333
|
}
|
|
315
334
|
|
|
316
335
|
if (mutate) {
|
|
317
|
-
this
|
|
318
|
-
this
|
|
319
|
-
this
|
|
336
|
+
this.$year = $year
|
|
337
|
+
this.$month = $month
|
|
338
|
+
this.$day = $day
|
|
320
339
|
return this
|
|
321
340
|
}
|
|
322
341
|
|
|
323
|
-
return new LocalDate(year, month, day)
|
|
342
|
+
return new LocalDate($year, $month, $day)
|
|
324
343
|
}
|
|
325
344
|
|
|
326
345
|
subtract(num: number, unit: LocalDateUnit, mutate = false): LocalDate {
|
|
@@ -329,21 +348,21 @@ export class LocalDate {
|
|
|
329
348
|
|
|
330
349
|
startOf(unit: LocalDateUnit): LocalDate {
|
|
331
350
|
if (unit === 'day') return this
|
|
332
|
-
if (unit === 'month') return LocalDate.create(this
|
|
351
|
+
if (unit === 'month') return LocalDate.create(this.$year, this.$month, 1)
|
|
333
352
|
// year
|
|
334
|
-
return LocalDate.create(this
|
|
353
|
+
return LocalDate.create(this.$year, 1, 1)
|
|
335
354
|
}
|
|
336
355
|
|
|
337
356
|
endOf(unit: LocalDateUnit): LocalDate {
|
|
338
357
|
if (unit === 'day') return this
|
|
339
358
|
if (unit === 'month')
|
|
340
359
|
return LocalDate.create(
|
|
341
|
-
this
|
|
342
|
-
this
|
|
343
|
-
LocalDate.getMonthLength(this
|
|
360
|
+
this.$year,
|
|
361
|
+
this.$month,
|
|
362
|
+
LocalDate.getMonthLength(this.$year, this.$month),
|
|
344
363
|
)
|
|
345
364
|
// year
|
|
346
|
-
return LocalDate.create(this
|
|
365
|
+
return LocalDate.create(this.$year, 12, 31)
|
|
347
366
|
}
|
|
348
367
|
|
|
349
368
|
static getYearLength(year: number): number {
|
|
@@ -352,17 +371,15 @@ export class LocalDate {
|
|
|
352
371
|
|
|
353
372
|
static getMonthLength(year: number, month: number): number {
|
|
354
373
|
if (month === 2) return this.isLeapYear(year) ? 29 : 28
|
|
355
|
-
return
|
|
374
|
+
return MDAYS[month]!
|
|
356
375
|
}
|
|
357
376
|
|
|
358
377
|
static isLeapYear(year: number): boolean {
|
|
359
|
-
|
|
360
|
-
if (year % 100 !== 0) return true
|
|
361
|
-
return year % 400 === 0
|
|
378
|
+
return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0)
|
|
362
379
|
}
|
|
363
380
|
|
|
364
381
|
clone(): LocalDate {
|
|
365
|
-
return new LocalDate(this
|
|
382
|
+
return new LocalDate(this.$year, this.$month, this.$day)
|
|
366
383
|
}
|
|
367
384
|
|
|
368
385
|
/**
|
|
@@ -372,35 +389,35 @@ export class LocalDate {
|
|
|
372
389
|
* Timezone will match local timezone.
|
|
373
390
|
*/
|
|
374
391
|
toDate(): Date {
|
|
375
|
-
return new Date(this
|
|
392
|
+
return new Date(this.$year, this.$month - 1, this.$day)
|
|
376
393
|
}
|
|
377
394
|
|
|
378
395
|
toLocalTime(): LocalTime {
|
|
379
396
|
return LocalTime.of(this.toDate())
|
|
380
397
|
}
|
|
381
398
|
|
|
382
|
-
toISODate():
|
|
399
|
+
toISODate(): IsoDateString {
|
|
383
400
|
return this.toString()
|
|
384
401
|
}
|
|
385
402
|
|
|
386
|
-
toString():
|
|
403
|
+
toString(): IsoDateString {
|
|
387
404
|
return [
|
|
388
|
-
String(this
|
|
389
|
-
String(this
|
|
390
|
-
String(this
|
|
405
|
+
String(this.$year).padStart(4, '0'),
|
|
406
|
+
String(this.$month).padStart(2, '0'),
|
|
407
|
+
String(this.$day).padStart(2, '0'),
|
|
391
408
|
].join('-')
|
|
392
409
|
}
|
|
393
410
|
|
|
394
411
|
toStringCompact(): string {
|
|
395
412
|
return [
|
|
396
|
-
String(this
|
|
397
|
-
String(this
|
|
398
|
-
String(this
|
|
413
|
+
String(this.$year).padStart(4, '0'),
|
|
414
|
+
String(this.$month).padStart(2, '0'),
|
|
415
|
+
String(this.$day).padStart(2, '0'),
|
|
399
416
|
].join('')
|
|
400
417
|
}
|
|
401
418
|
|
|
402
419
|
// May be not optimal, as LocalTime better suits it
|
|
403
|
-
unix():
|
|
420
|
+
unix(): UnixTimestampNumber {
|
|
404
421
|
return Math.floor(this.toDate().valueOf() / 1000)
|
|
405
422
|
}
|
|
406
423
|
|
|
@@ -408,7 +425,7 @@ export class LocalDate {
|
|
|
408
425
|
return this.toDate().valueOf()
|
|
409
426
|
}
|
|
410
427
|
|
|
411
|
-
toJSON():
|
|
428
|
+
toJSON(): IsoDateString {
|
|
412
429
|
return this.toString()
|
|
413
430
|
}
|
|
414
431
|
}
|