Skip to content

Commit

Permalink
Bump Luxon (#3289)
Browse files Browse the repository at this point in the history
  • Loading branch information
CarsonF authored Sep 20, 2024
1 parent 45ef0db commit bd548c0
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 49 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"lazy-get-decorator": "^2.2.1",
"lodash": "npm:lodash-es@^4.17.21",
"lru-cache": "^7.18.3",
"luxon": "^3.4.3",
"luxon": "^3.5.0",
"mime": "beta",
"nanoid": "^4.0.2",
"neo4j-driver": "^5.20.0",
Expand Down Expand Up @@ -122,7 +122,7 @@
"@types/jest": "^29.5.7",
"@types/jsonwebtoken": "^9.0.4",
"@types/lodash": "^4.14.200",
"@types/luxon": "^3.3.3",
"@types/luxon": "^3.4.2",
"@types/node": "^20.12.5",
"@types/prismjs": "^1.26.2",
"@types/react": "^18.2.33",
Expand Down
2 changes: 1 addition & 1 deletion src/common/luxon.graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class DateTimeScalar
}

serialize(value: unknown): string {
if (value instanceof DateTime) {
if (DateTime.isDateTime(value)) {
return value.toISO();
}
if (typeof value === 'string') {
Expand Down
63 changes: 37 additions & 26 deletions src/common/temporal/calendar-date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
Zone,
ZoneOptions,
} from 'luxon';
import type { DefaultValidity, IfValid } from 'luxon/src/_util';
import { inspect } from 'util';
import { DateInterval } from './date-interval';

Expand All @@ -21,17 +22,19 @@ import { DateInterval } from './date-interval';
* Whether or not we need/want it to be type compatible with DateTime has yet to
* be determined - currently it is.
*/
export class CalendarDate
export class CalendarDate<IsValid extends boolean = DefaultValidity>
// @ts-expect-error library doesn't explicitly support extension
extends DateTime
extends DateTime<IsValid>
{
static isDate(o: any): o is CalendarDate {
return o instanceof CalendarDate;
}

static fromDateTime(dt: DateTime): CalendarDate {
static fromDateTime<IsValid extends boolean>(
dt: DateTime<IsValid>,
): CalendarDate<IsValid> {
return Object.assign(
new CalendarDate(),
new CalendarDate<IsValid>(),
dt instanceof CalendarDate ? dt : dt.startOf('day'),
);
}
Expand All @@ -44,7 +47,7 @@ export class CalendarDate
super({});
}

toISO(_options?: ToISOTimeOptions): string {
toISO(_options?: ToISOTimeOptions) {
return this.toISODate();
}

Expand Down Expand Up @@ -88,7 +91,7 @@ export class CalendarDate
return CalendarDate.fromDateTime(super.fromFormat(text, format, opts));
}

static invalid(reason: any): CalendarDate {
static invalid(reason: any) {
return CalendarDate.fromDateTime(super.invalid(reason));
}

Expand Down Expand Up @@ -207,52 +210,60 @@ export class CalendarDate
return CalendarDate.fromDateTime(super.utc(...args));
}

until(other: CalendarDate): DateInterval {
return DateInterval.fromDateTimes(this, other);
until(other: CalendarDate): IfValid<DateInterval, DateTime<false>, IsValid> {
return DateInterval.fromDateTimes(this as DateTime, other) as IfValid<
DateInterval,
DateTime<false>,
IsValid
>;
}

endOf(unit: DateTimeUnit): CalendarDate {
return CalendarDate.fromDateTime(super.endOf(unit));
endOf(unit: DateTimeUnit): this {
return CalendarDate.fromDateTime(super.endOf(unit) as DateTime) as this;
}

minus(duration: DurationLike): CalendarDate {
return CalendarDate.fromDateTime(super.minus(duration));
minus(duration: DurationLike): this {
return CalendarDate.fromDateTime(super.minus(duration) as DateTime) as this;
}

plus(duration: DurationLike): CalendarDate {
return CalendarDate.fromDateTime(super.plus(duration));
plus(duration: DurationLike): this {
return CalendarDate.fromDateTime(super.plus(duration) as DateTime) as this;
}

reconfigure(properties: LocaleOptions): CalendarDate {
return CalendarDate.fromDateTime(super.reconfigure(properties));
reconfigure(properties: LocaleOptions): this {
return CalendarDate.fromDateTime(
super.reconfigure(properties) as DateTime,
) as this;
}

set(values: DateObjectUnits): CalendarDate {
return CalendarDate.fromDateTime(super.set(values));
set(values: DateObjectUnits): this {
return CalendarDate.fromDateTime(super.set(values) as DateTime) as this;
}

setLocale(locale: string): CalendarDate {
return CalendarDate.fromDateTime(super.setLocale(locale));
setLocale(locale: string): this {
return CalendarDate.fromDateTime(
super.setLocale(locale) as DateTime,
) as this;
}

setZone(_zone: string | Zone, _options?: ZoneOptions): CalendarDate {
return this; // noop
return this as CalendarDate; // noop
}

startOf(unit: DateTimeUnit): CalendarDate {
return CalendarDate.fromDateTime(super.startOf(unit));
startOf(unit: DateTimeUnit): this {
return CalendarDate.fromDateTime(super.startOf(unit) as DateTime) as this;
}

toLocal(): CalendarDate {
toLocal() {
return this; // noop
}

toUTC(): CalendarDate {
toUTC() {
return this; // noop
}

toPostgres() {
return this.toSQLDate();
return this.toSQLDate()!;
}

[inspect.custom]() {
Expand Down
14 changes: 6 additions & 8 deletions src/common/temporal/date-interval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,12 @@ export class DateInterval
}

protected constructor(config: Required<IntervalObject>) {
config.start =
config.start instanceof CalendarDate
? config.start
: CalendarDate.fromDateTime(config.start);
config.end =
config.end instanceof CalendarDate
? config.end
: CalendarDate.fromDateTime(config.end);
config.start = CalendarDate.isDate(config.start)
? config.start
: CalendarDate.fromDateTime(config.start);
config.end = CalendarDate.isDate(config.end)
? config.end
: CalendarDate.fromDateTime(config.end);
super(config);
}

Expand Down
4 changes: 2 additions & 2 deletions src/core/database/parameter-transformer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ export class ParameterTransformer {
return value;
}

if (value instanceof CalendarDate) {
if (CalendarDate.isDate(value)) {
return value.toNeo4JDate();
}

if (value instanceof DateTime) {
if (DateTime.isDateTime(value)) {
return value.toNeo4JDateTime();
}

Expand Down
20 changes: 10 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3628,10 +3628,10 @@ __metadata:
languageName: node
linkType: hard

"@types/luxon@npm:^3.3.3":
version: 3.3.3
resolution: "@types/luxon@npm:3.3.3"
checksum: 10c0/169ce8eb8860f3ad9ef146c2c7a2d9bc09775b8af93fb346f1222e67e4f98559201cf38ed6d8dc9a72d9535b1cf9a46415cf95591e56d2d72101babce2996de3
"@types/luxon@npm:^3.4.2":
version: 3.4.2
resolution: "@types/luxon@npm:3.4.2"
checksum: 10c0/d835467de3daf7e17ba78b50bb5a14efd94272439ca067990d71332a54b311544459c69623eddd243b511b28d70194c9591a9ee8cf9c038962c965f991affd7e
languageName: node
linkType: hard

Expand Down Expand Up @@ -5370,7 +5370,7 @@ __metadata:
"@types/jest": "npm:^29.5.7"
"@types/jsonwebtoken": "npm:^9.0.4"
"@types/lodash": "npm:^4.14.200"
"@types/luxon": "npm:^3.3.3"
"@types/luxon": "npm:^3.4.2"
"@types/node": "npm:^20.12.5"
"@types/prismjs": "npm:^1.26.2"
"@types/react": "npm:^18.2.33"
Expand Down Expand Up @@ -5420,7 +5420,7 @@ __metadata:
lint-staged: "npm:^14.0.1"
lodash: "npm:lodash-es@^4.17.21"
lru-cache: "npm:^7.18.3"
luxon: "npm:^3.4.3"
luxon: "npm:^3.5.0"
mime: "npm:beta"
nanoid: "npm:^4.0.2"
neo4j-driver: "npm:^5.20.0"
Expand Down Expand Up @@ -9416,10 +9416,10 @@ __metadata:
languageName: node
linkType: hard

"luxon@npm:^3.4.3":
version: 3.4.3
resolution: "luxon@npm:3.4.3"
checksum: 10c0/65ad727684d367af9c8fcbde05ad7989ef2436a4496b62d993059baaa641e90a5fa74e98f34ee2ff29f7af7f2b27238ca78b87834f9068624e4133d786f87bc7
"luxon@npm:^3.5.0":
version: 3.5.0
resolution: "luxon@npm:3.5.0"
checksum: 10c0/335789bba95077db831ef99894edadeb23023b3eb2137a1b56acd0d290082b691cf793143d69e30bc069ec95f0b49f36419f48e951c68014f19ffe12045e3494
languageName: node
linkType: hard

Expand Down

0 comments on commit bd548c0

Please sign in to comment.