Skip to content

Commit

Permalink
Merge pull request #402 from InExtremaRes/ts-temporal-adjusters
Browse files Browse the repository at this point in the history
Fix TS declarations of some TemporalAdjuster implementations (like DayOfWeak)
  • Loading branch information
pithu committed Jun 3, 2020
2 parents 3752afb + 6ce7010 commit e3a3b01
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
35 changes: 18 additions & 17 deletions packages/core/dist/js-joda.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export abstract class Clock {
abstract equals(other: any): boolean;
}

export class DayOfWeek extends TemporalAccessor {
export class DayOfWeek extends TemporalAccessor implements TemporalAdjuster {
static MONDAY: DayOfWeek;
static TUESDAY: DayOfWeek;
static WEDNESDAY: DayOfWeek;
Expand All @@ -72,7 +72,7 @@ export class DayOfWeek extends TemporalAccessor {

private constructor();

adjustInto(temporal: TemporalAdjuster): this;
adjustInto(temporal: Temporal): Temporal;
compareTo(other: DayOfWeek): number;
equals(other: any): boolean;
getDisplayName(style: TextStyle, locale: Locale): string;
Expand Down Expand Up @@ -153,7 +153,7 @@ export class Duration extends TemporalAmount {
withSeconds(seconds: number): Duration;
}

export class Instant extends Temporal {
export class Instant extends Temporal implements TemporalAdjuster {
static EPOCH: Instant;
static MIN: Instant;
static MAX: Instant;
Expand Down Expand Up @@ -274,7 +274,7 @@ export class DateTimeFormatterBuilder {
// for now. Change this if Chronology is added.
export type Chronology = IsoChronology;

export class LocalTime extends Temporal {
export class LocalTime extends Temporal implements TemporalAdjuster {
static MIN: LocalTime;
static MAX: LocalTime;
static MIDNIGHT: LocalTime;
Expand Down Expand Up @@ -304,7 +304,7 @@ export class LocalTime extends Temporal {

private constructor();

adjustInto(temporal: TemporalAdjuster): Temporal;
adjustInto(temporal: Temporal): Temporal;
atDate(date: LocalDate): LocalDateTime;
compareTo(other: LocalTime): number;
equals(other: any): boolean;
Expand Down Expand Up @@ -347,7 +347,7 @@ export class LocalTime extends Temporal {
withSecond(second: number): LocalTime;
}

export class Month extends TemporalAccessor {
export class Month extends TemporalAccessor implements TemporalAdjuster {
static JANUARY: Month;
static FEBRUARY: Month;
static MARCH: Month;
Expand Down Expand Up @@ -389,7 +389,7 @@ export class Month extends TemporalAccessor {
value(): number;
}

export class MonthDay extends TemporalAccessor {
export class MonthDay extends TemporalAccessor implements TemporalAdjuster {
static FROM: TemporalQuery<LocalDate>;

static from(temporal: TemporalAccessor): MonthDay;
Expand Down Expand Up @@ -540,13 +540,13 @@ export class ChronoUnit extends TemporalUnit {
toString(): string;
}

export abstract class ChronoLocalDate extends Temporal {
adjustInto(temporal: TemporalAdjuster): this;
export abstract class ChronoLocalDate extends Temporal implements TemporalAdjuster {
adjustInto(temporal: Temporal): Temporal;
format(formatter: DateTimeFormatter): string;
isSupported(fieldOrUnit: TemporalField | TemporalUnit): boolean;
}

export class LocalDate extends ChronoLocalDate {
export class LocalDate extends ChronoLocalDate implements TemporalAdjuster {
static MIN: LocalDate;
static MAX: LocalDate;
static EPOCH_0: LocalDate;
Expand Down Expand Up @@ -614,14 +614,14 @@ export class LocalDate extends ChronoLocalDate {
year(): number;
}

export abstract class ChronoLocalDateTime extends Temporal {
adjustInto(temporal: TemporalAdjuster): ChronoLocalDate;
export abstract class ChronoLocalDateTime extends Temporal implements TemporalAdjuster {
adjustInto(temporal: Temporal): Temporal;
chronology(): Chronology;
toEpochSecond(offset: ZoneOffset): number;
toInstant(offset: ZoneOffset): Instant;
}

export class LocalDateTime extends ChronoLocalDateTime {
export class LocalDateTime extends ChronoLocalDateTime implements TemporalAdjuster {
static MIN: LocalDateTime;
static MAX: LocalDateTime;

Expand All @@ -638,7 +638,6 @@ export class LocalDateTime extends ChronoLocalDateTime {

private constructor();

adjustInto(temporal: TemporalAdjuster): LocalDateTime;
atZone(zone: ZoneId): ZonedDateTime;
compareTo(other: LocalDateTime): number;
dayOfMonth(): number;
Expand Down Expand Up @@ -799,7 +798,7 @@ export class ValueRange {
toString(): string;
}

export class Year extends Temporal {
export class Year extends Temporal implements TemporalAdjuster {
static MIN_VALUE: number;
static MAX_VALUE: number;

Expand All @@ -813,6 +812,7 @@ export class Year extends Temporal {

private constructor();

adjustInto(temporal: Temporal): Temporal;
atDay(dayOfYear: number): LocalDate;
atMonth(month: Month | number): YearMonth;
atMonthDay(monthDay: MonthDay): LocalDate;
Expand All @@ -834,7 +834,7 @@ export class Year extends Temporal {
with(field: TemporalField, newValue: number): Year;
}

export class YearMonth extends Temporal {
export class YearMonth extends Temporal implements TemporalAdjuster {
static FROM: TemporalQuery<LocalDate>;

static from(temporal: TemporalAccessor): YearMonth;
Expand All @@ -844,6 +844,7 @@ export class YearMonth extends Temporal {

private constructor();

adjustInto(temporal: Temporal): Temporal;
minus(amount: TemporalAmount): YearMonth;
minus(amountToSubtract: number, unit: TemporalUnit): YearMonth;
minusYears(yearsToSubtract: number): YearMonth;
Expand Down Expand Up @@ -894,7 +895,7 @@ export abstract class ZoneId {
toString(): string;
}

export class ZoneOffset extends ZoneId {
export class ZoneOffset extends ZoneId implements TemporalAdjuster {
static MAX_SECONDS: ZoneOffset;
static UTC: ZoneOffset;
static MIN: ZoneOffset;
Expand Down
11 changes: 11 additions & 0 deletions packages/core/test/typescript_definitions/js-joda-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,17 @@ function test_Temporal() {

temporal.with(nextYear);
temporal.with(ChronoField.YEAR, 2020);

temporal.with(DayOfWeek.MONDAY);
temporal.with(Instant.now());
temporal.with(LocalDate.now());
temporal.with(LocalDateTime.now());
temporal.with(LocalTime.now());
temporal.with(Month.FEBRUARY);
temporal.with(MonthDay.now());
temporal.with(Year.now());
temporal.with(YearMonth.now());
temporal.with(ZoneOffset.ofHours(1));
}

function test_TemporalQuery() {
Expand Down

0 comments on commit e3a3b01

Please sign in to comment.