diff --git a/src/datetime/localDate.test.ts b/src/datetime/localDate.test.ts index 980ef130..a1f22ad6 100644 --- a/src/datetime/localDate.test.ts +++ b/src/datetime/localDate.test.ts @@ -71,6 +71,12 @@ test('basic', () => { expect(ld.getAgeInMonths('2024-05-15')).toBe(478) expect(ld.getAgeInDays('2024-05-15')).toBe(14573) expect(ld.getAgeIn('day', '2024-05-15')).toBe(14573) + + expect(ld.isToday()).toBe(false) + expect(ld.isAfterToday()).toBe(false) + expect(ld.isSameOrAfterToday()).toBe(false) + expect(ld.isBeforeToday()).toBe(true) + expect(ld.isSameOrBeforeToday()).toBe(true) }) test('constructors', () => { diff --git a/src/datetime/localDate.ts b/src/datetime/localDate.ts index 1fbb3f39..9e9d5902 100644 --- a/src/datetime/localDate.ts +++ b/src/datetime/localDate.ts @@ -141,6 +141,22 @@ export class LocalDate { return this.isSameOrAfter(localDate.fromInput(today || new Date()).plus(-n, unit)) } + isToday(): boolean { + return this.isSame(localDate.today()) + } + isAfterToday(): boolean { + return this.isAfter(localDate.today()) + } + isSameOrAfterToday(): boolean { + return this.isSameOrAfter(localDate.today()) + } + isBeforeToday(): boolean { + return this.isBefore(localDate.today()) + } + isSameOrBeforeToday(): boolean { + return this.isSameOrBefore(localDate.today()) + } + getAgeInYears(today?: LocalDateInput): number { return this.getAgeIn('year', today) } diff --git a/src/datetime/localTime.test.ts b/src/datetime/localTime.test.ts index 608c60ad..baa73903 100644 --- a/src/datetime/localTime.test.ts +++ b/src/datetime/localTime.test.ts @@ -51,6 +51,9 @@ test('basic', () => { expect(lt.getAgeInDays('2024-05-15')).toBe(865) expect(lt.getAgeIn('day', '2024-05-15')).toBe(865) + expect(lt.isAfterNow()).toBe(false) + expect(lt.isBeforeNow()).toBe(true) + expect(lt.setYear(2023).year).toBe(2023) expect(lt.year).toBe(2022) // not changed diff --git a/src/datetime/localTime.ts b/src/datetime/localTime.ts index 5fd4443f..447225e1 100644 --- a/src/datetime/localTime.ts +++ b/src/datetime/localTime.ts @@ -538,6 +538,13 @@ export class LocalTime { return localTime.fromInput(now ?? new Date()).diff(this, unit) } + isAfterNow(): boolean { + return this.$date.valueOf() > Date.now() + } + isBeforeNow(): boolean { + return this.$date.valueOf() < Date.now() + } + /** * Returns 1 if this > d * returns 0 if they are equal