Skip to content

Commit eb95c5a

Browse files
committed
Fix type incompatibility in some functions
1 parent 3b6f1e3 commit eb95c5a

File tree

4 files changed

+19
-11
lines changed

4 files changed

+19
-11
lines changed

src/datetime/endOfDay.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ import type { Temporal } from "../types.js";
55
* @param dt datetime object which includes date and time info
66
* @returns Temporal object which represents the end of the day
77
*/
8-
export function endOfDay(dt: Temporal.PlainDateTime): Temporal.PlainDateTime {
8+
export function endOfDay<DateTime extends Temporal.PlainDateTime>(
9+
dt: DateTime,
10+
): DateTime {
911
return dt.with({
1012
hour: 23,
1113
minute: 59,
1214
second: 59,
1315
millisecond: 999,
1416
microsecond: 999,
1517
nanosecond: 999,
16-
});
18+
}) as DateTime;
1719
}

src/datetime/fromJulianDate.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ import { fromModifiedJulianDate } from "./fromModifiedJulianDate.js";
88
* @param Instant `Temporal.Instant` class
99
* @returns `Temporal.Instant` which corresponds to the given julian date
1010
*/
11-
export function fromJulianDate(
11+
export function fromJulianDate<
12+
InstantClassType extends typeof Temporal.Instant,
13+
>(
1214
julianDate: number,
13-
Instant: typeof Temporal.Instant,
14-
): Temporal.Instant {
15+
Instant: InstantClassType,
16+
): InstanceType<InstantClassType> {
1517
return fromModifiedJulianDate(julianDate - 2400000.5, Instant);
1618
}

src/datetime/fromModifiedJulianDate.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@ import type { Temporal } from "../types.js";
77
* @param Instant `Temporal.Instant` class
88
* @returns `Temporal.Instant` which corresponds to the given modified julian date
99
*/
10-
export function fromModifiedJulianDate(
10+
export function fromModifiedJulianDate<
11+
InstantClassType extends typeof Temporal.Instant,
12+
>(
1113
modifiedJulianDate: number,
12-
Instant: typeof Temporal.Instant,
13-
): Temporal.Instant {
14+
Instant: InstantClassType,
15+
): InstanceType<InstantClassType> {
1416
const modifiedJulianDayInt = Math.floor(modifiedJulianDate);
1517
const nanoseconds = Math.floor(
1618
(modifiedJulianDate - modifiedJulianDayInt) * 8.64e13,
1719
);
1820
return Instant.from("1858-11-17T00:00:00Z").add({
1921
hours: modifiedJulianDayInt * 24,
2022
nanoseconds,
21-
});
23+
}) as InstanceType<InstantClassType>;
2224
}

src/datetime/startOfDay.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ import type { Temporal } from "../types.js";
55
* @param dt datetime object which includes date and time info
66
* @returns Temporal object which represents the start of a day
77
*/
8-
export function startOfDay(dt: Temporal.PlainDateTime): Temporal.PlainDateTime {
8+
export function startOfDay<DateTime extends Temporal.PlainDateTime>(
9+
dt: DateTime,
10+
): DateTime {
911
return dt.with({
1012
hour: 0,
1113
minute: 0,
1214
second: 0,
1315
millisecond: 0,
1416
microsecond: 0,
1517
nanosecond: 0,
16-
});
18+
}) as DateTime;
1719
}

0 commit comments

Comments
 (0)