Skip to content

Commit 8eb126c

Browse files
fix: require orNow, orToday to pass an argument
Prevents misuse like `localTime.orNow().toIsoDate`
1 parent a7a3005 commit 8eb126c

File tree

5 files changed

+10
-10
lines changed

5 files changed

+10
-10
lines changed

docs/date.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ Examples:
6060

6161
| | day.js (via time-lib) | LocalTime | LocalDate |
6262
| ----------------------------------- | ------------------------------------ | ------------------------------ | ------------------------------ |
63-
| now | dayjs() | localTimeNow() | |
64-
| today | dayjs().startOf('day') | | localDateToday() |
63+
| now | dayjs() | localTime.now() | |
64+
| today | dayjs().startOf('day') | | localDate.today() |
6565
| create from unixtimestamp | dayjs.unix(ts) | localTime(ts) | |
6666
| parse from ISO8601 date string | dayjs(str) | | localDate(str) |
6767
| parse from ISO8601 date+time string | dayjs(str) | localTime(str) | |

src/datetime/localDate.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ test('basic', () => {
4242
expect(ld.month(7).daysInMonth()).toBe(31)
4343
expect(ld.month(2).daysInMonth()).toBe(29)
4444

45-
expect(localDate.orUndefined()).toBeUndefined()
45+
expect(localDate.orUndefined(undefined)).toBeUndefined()
4646
expect(localDate.orUndefined(null)).toBeUndefined()
4747
expect(localDate.orUndefined(0 as any)).toBeUndefined()
4848
expect(localDate.orUndefined(str)?.toString()).toBe(str)
4949

5050
expect(localDate.today().toISODate()).toBeDefined()
51-
expect(localDate.orToday().toISODate()).toBe(localDate.today().toISODate())
51+
expect(localDate.orToday(undefined).toISODate()).toBe(localDate.today().toISODate())
5252
expect(localDate.orToday(ld).toISODate()).toBe(ld.toISODate())
5353

5454
expect(() => localDate(undefined as any)).toThrowErrorMatchingInlineSnapshot(

src/datetime/localDate.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -665,14 +665,14 @@ class LocalDateFactory {
665665
*
666666
* Similar to `localDate.orToday`, but that will instead return Today on falsy input.
667667
*/
668-
orUndefined(d?: LocalDateInput | null): LocalDate | undefined {
668+
orUndefined(d: LocalDateInput | null | undefined): LocalDate | undefined {
669669
return d ? this.of(d) : undefined
670670
}
671671

672672
/**
673673
* Creates a LocalDate from the input, unless it's falsy - then returns localDate.today.
674674
*/
675-
orToday(d?: LocalDateInput | null): LocalDate {
675+
orToday(d: LocalDateInput | null | undefined): LocalDate {
676676
return d ? this.of(d) : this.today()
677677
}
678678
}

src/datetime/localTime.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,13 @@ test('basic', () => {
117117
expect(lt.month(2).daysInMonth()).toBe(28)
118118
expect(lt.month(4).daysInMonth()).toBe(30)
119119

120-
expect(localTime.orUndefined()).toBeUndefined()
120+
expect(localTime.orUndefined(undefined)).toBeUndefined()
121121
expect(localTime.orUndefined(null)).toBeUndefined()
122122
expect(localTime.orUndefined(0 as any)).toBeUndefined()
123123
expect(localTime.orUndefined(start)?.toISODate()).toBe('2022-01-01')
124124

125125
expect(localTime.now().toString()).toBeDefined()
126-
expect(localTime.orNow().toString()).toBeDefined()
126+
expect(localTime.orNow(undefined).toString()).toBeDefined()
127127
expect(localTime.orNow(lt).toISODate()).toBe(lt.toISODate())
128128

129129
expect(() => localTime(undefined as any)).toThrowErrorMatchingInlineSnapshot(

src/datetime/localTime.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,14 +638,14 @@ class LocalTimeFactory {
638638
*
639639
* `localTime` function will instead return LocalTime of `now` for falsy input.
640640
*/
641-
orUndefined(d?: LocalTimeInput | null): LocalTime | undefined {
641+
orUndefined(d: LocalTimeInput | null | undefined): LocalTime | undefined {
642642
return d ? this.of(d) : undefined
643643
}
644644

645645
/**
646646
* Creates a LocalTime from the input, unless it's falsy - then returns LocalTime.now
647647
*/
648-
orNow(d?: LocalTimeInput | null): LocalTime {
648+
orNow(d: LocalTimeInput | null | undefined): LocalTime {
649649
return d ? this.of(d) : this.now()
650650
}
651651

0 commit comments

Comments
 (0)