UNPKG

@js-joda/core

Version:

a date and time library for javascript

1,079 lines (1,053 loc) 111 kB
// ---------------------------------------------------------------------------- // TEMPORAL // ---------------------------------------------------------------------------- /** * A field of date-time, such as month-of-year or hour-of-minute. * * Date and time is expressed using fields which partition the time-line into something meaningful * for humans. Implementations of this interface represent those fields. * * The most commonly used units are defined in `ChronoField`. Further fields are supplied in * `IsoFields`. Fields can also be written by application code by implementing this interface. */ export abstract class TemporalField { /** Checks if this field is supported by the temporal object. */ abstract isSupportedBy(temporal: TemporalAccessor): boolean; /** Checks if this field represents a component of a date. */ abstract isDateBased(): boolean; /** Checks if this field represents a component of a time. */ abstract isTimeBased(): boolean; /** Gets the unit that the field is measured in. */ abstract baseUnit(): TemporalUnit; /** Gets the range that the field is bound by. */ abstract rangeUnit(): TemporalUnit; /** Gets the range of valid values for the field. */ abstract range(): ValueRange; /** * Get the range of valid values for this field using the temporal object to * refine the result. */ abstract rangeRefinedBy(temporal: TemporalAccessor): ValueRange; /** Gets the value of this field from the specified temporal object. */ abstract getFrom(temporal: TemporalAccessor): number; /** Returns a copy of the specified temporal object with the value of this field set. */ abstract adjustInto<R extends Temporal>(temporal: R, newValue: number): R; abstract name(): string; abstract displayName(/* TODO: locale */): string; abstract equals(other: any): boolean; } /** * A unit of date-time, such as Days or Hours. * * Measurement of time is built on units, such as years, months, days, hours, minutes and seconds. * Implementations of this interface represent those units. * * An instance of this interface represents the unit itself, rather than an amount of the unit. * See `Period` for a class that represents an amount in terms of the common units. * * The most commonly used units are defined in `ChronoUnit`. Further units are supplied in * `IsoFields`. Units can also be written by application code by implementing this interface. */ export abstract class TemporalUnit { /** Returns a copy of the specified temporal object with the specified period added. */ abstract addTo<T extends Temporal>(temporal: T, amount: number): T; /** * Calculates the period in terms of this unit between two temporal objects of the same type. * * Returns the period between temporal1 and temporal2 in terms of this unit; a positive number * if `temporal2` is later than `temporal1`, negative if earlier. */ abstract between(temporal1: Temporal, temporal2: Temporal): number; /** Gets the duration of this unit, which may be an estimate. */ abstract duration(): Duration; /** Checks if this unit is date-based. */ abstract isDateBased(): boolean; /** Checks if the duration of the unit is an estimate. */ abstract isDurationEstimated(): boolean; /** Checks if this unit is supported by the specified temporal object. */ abstract isSupportedBy(temporal: Temporal): boolean; /** Checks if this unit is time-based. */ abstract isTimeBased(): boolean; } /** * The range of valid values for a date-time field. * * All TemporalField instances have a valid range of values. For example, the ISO day-of-month * runs from 1 to somewhere between 28 and 31. This class captures that valid range. * * It is important to be aware of the limitations of this class. Only the minimum and maximum * values are provided. It is possible for there to be invalid values within the outer range. * For example, a weird field may have valid values of 1, 2, 4, 6, 7, thus have a range of '1 - 7', * despite that fact that values 3 and 5 are invalid. * * Instances of this class are not tied to a specific field. */ export class ValueRange { static of(min: number, max: number): ValueRange; static of(min: number, maxSmallest: number, maxLargest: number): ValueRange; static of(minSmallest: number, minLargest: number, maxSmallest: number, maxLargest: number): ValueRange; private constructor(); checkValidValue(value: number, field: TemporalField): number; checkValidIntValue(value: number, field: TemporalField): number; equals(other: any): boolean; hashCode(): number; isFixed(): boolean; isIntValue(): boolean; isValidIntValue(value: number): boolean; isValidValue(value: number): boolean; largestMinimum(): number; maximum(): number; minimum(): number; smallestMaximum(): number; toString(): string; } /** * Framework-level class defining an amount of time, such as "6 hours", "8 days" or * "2 years and 3 months". * * This is the base class type for amounts of time. An amount is distinct from a date or * time-of-day in that it is not tied to any specific point on the time-line. * * The amount can be thought of as a `Map` of `TemporalUnit` to `number`, exposed via * `units()` and `get()`. A simple case might have a single unit-value pair, such * as "6 hours". A more complex case may have multiple unit-value pairs, such as "7 years, * 3 months and 5 days". * * There are two common implementations. `Period` is a date-based implementation, * storing years, months and days. `Duration` is a time-based implementation, storing * seconds and nanoseconds, but providing some access using other duration based units such * as minutes, hours and fixed 24-hour days. * * This class is a framework-level class that should not be widely used in application code. * Instead, applications should create and pass around instances of concrete types, such as * `Period` and `Duration`. */ export abstract class TemporalAmount { /** * This adds to the specified temporal object using the logic encapsulated in the * implementing class. * * There are two equivalent ways of using this method. The first is to invoke this method * directly. The second is to use `Temporal.plus(TemporalAmount)`: * * ``` * // these two lines are equivalent, but the second approach is recommended * dateTime = amount.addTo(dateTime); * dateTime = dateTime.plus(amount); * ``` * * It is recommended to use the second approach, `plus(TemporalAmount)`, as it is a lot * clearer to read in code. */ abstract addTo<T extends Temporal>(temporal: T): T; /** Gets the amount associated with the specified unit. */ abstract get(unit: TemporalUnit): number; /** Gets the list of units, from largest to smallest, that fully define this amount. */ abstract units(): TemporalUnit[]; /** * This substract to the specified temporal object using the logic encapsulated in the * implementing class. * * There are two equivalent ways of using this method. The first is to invoke this method * directly. The second is to use `Temporal.minus(TemporalAmount)`: * ``` * // these two lines are equivalent, but the second approach is recommended * dateTime = amount.substractFrom(dateTime); * dateTime = dateTime.minus(amount); * ``` * * It is recommended to use the second approach, `minus(TemporalAmount)`, as it is a lot * clearer to read in code. */ abstract subtractFrom<T extends Temporal>(temporal: T): T; } /** * Framework-level interface defining read-only access to a temporal object, such as a date, time, * offset or some combination of these. * * This is the base interface type for date, time and offset objects. It is implemented by those * classes that can provide information as fields or queries. * * Most date and time information can be represented as a number. These are modeled using * `TemporalField` with the number held using a long to handle large values. Year, month and * day-of-month are simple examples of fields, but they also include instant and offsets. See * `ChronoField` for the standard set of fields. * * Two pieces of date/time information cannot be represented by numbers, the chronology and the * time-zone. These can be accessed via queries using the static methods defined on * `TemporalQueries`. * * A sub-interface, `Temporal`, extends this definition to one that also supports adjustment and * manipulation on more complete temporal objects. * * This interface is a framework-level interface that should not be widely used in application code. * Instead, applications should create and pass around instances of concrete types, such as * `LocalDate`. There are many reasons for this, part of which is that implementations of this * interface may be in calendar systems other than ISO. See `ChronoLocalDate` for a fuller * discussion of the issues. */ export abstract class TemporalAccessor { /** * Gets the value of the specified field as an integer number. * * This queries the date-time for the value for the specified field. The returned value will * always be within the valid range of values for the field. If the date-time cannot return * the value, because the field is unsupported or for some other reason, an exception will * be thrown. */ get(field: TemporalField): number; /** * Queries this date-time. * * This queries this date-time using the specified query strategy object. * * Queries are a key tool for extracting information from date-times. They exists to * externalize the process of querying, permitting different approaches, as per the strategy * design pattern. Examples might be a query that checks if the date is the day before * February 29th in a leap year, or calculates the number of days to your next birthday. * * The most common query implementations are method references, such as `LocalDate::FROM` and * `ZoneId::FROM`. Further implementations are on `TemporalQueries`. Queries may also be * defined by applications. */ query<R>(query: TemporalQuery<R>): R | null; /** * Gets the range of valid values for the specified field. * * All fields can be expressed as an integer number. This method returns an object that * describes the valid range for that value. The value of this temporal object is used to * enhance the accuracy of the returned range. If the date-time cannot return the range, * because the field is unsupported or for some other reason, an exception will be thrown. * * Note that the result only describes the minimum and maximum valid values and it is * important not to read too much into them. For example, there could be values within the * range that are invalid for the field. */ range(field: TemporalField): ValueRange; abstract getLong(field: TemporalField): number; /** * Checks if the specified field is supported. * * This checks if the date-time can be queried for the specified field. If false, then * calling the `range` and `get` methods will throw an exception. */ abstract isSupported(field: TemporalField): boolean; } /** * Framework-level interface defining read-write access to a temporal object, such as a date, time, * offset or some combination of these. * * This is the base interface type for date, time and offset objects that are complete enough to be * manipulated using plus and minus. It is implemented by those classes that can provide and * manipulate information as fields or queries. See `TemporalAccessor` for the read-only version of * this interface. * * Most date and time information can be represented as a number. These are modeled using * `TemporalField` with the number held using a long to handle large values. Year, month and * day-of-month are simple examples of fields, but they also include instant and offsets. See * `ChronoField` for the standard set of fields. * * Two pieces of date/time information cannot be represented by numbers, the chronology and the * time-zone. These can be accessed via queries using the static methods defined on * `TemporalQueries`. * * This interface is a framework-level interface that should not be widely used in application code. * Instead, applications should create and pass around instances of concrete types, such as * `LocalDate`. There are many reasons for this, part of which is that implementations of this * interface may be in calendar systems other than ISO. See `ChronoLocalDate` for a fuller * discussion of the issues. */ export abstract class Temporal extends TemporalAccessor { minus(amountToSubtract: number, unit: TemporalUnit): Temporal; /** * Returns an object of the same type as this object with an amount subtracted. * * This adjusts this temporal, subtracting according to the rules of the specified amount. * The amount is typically a `Period` but may be any other type implementing `TemporalAmount`, * such as `Duration`. * * Some example code indicating how and why this method is used: * ``` * date = date.minus(period); // subtract a Period instance * date = date.minus(duration); // subtract a Duration instance * date = date.minus(workingDays(6)); // example user-written workingDays method * ``` * * Note that calling plus followed by minus is not guaranteed to return the same date-time. */ minus(amount: TemporalAmount): Temporal; plus(amountToAdd: number, unit: TemporalUnit): Temporal; /** * Returns an object of the same type as this object with an amount added. * * This adjusts this temporal, adding according to the rules of the specified amount. The * amount is typically a `Period` but may be any other type implementing `TemporalAmount`, * such as `Duration`. * * Some example code indicating how and why this method is used: * ``` * date = date.plus(period); // add a Period instance * date = date.plus(duration); // add a Duration instance * date = date.plus(workingDays(6)); // example user-written workingDays method * ``` * * Note that calling plus followed by minus is not guaranteed to return the same date-time. */ plus(amount: TemporalAmount): Temporal; /** * Returns an adjusted object of the same type as this object with the adjustment made. * * This adjusts this date-time according to the rules of the specified adjuster. A simple * adjuster might simply set the one of the fields, such as the year field. A more complex * adjuster might set the date to the last day of the month. A selection of common adjustments * is provided in `TemporalAdjusters`. These include finding the "last day of the month" and * "next Wednesday". The adjuster is responsible for handling special cases, such as the * varying lengths of month and leap years. * * Some example code indicating how and why this method is used: * ``` * date = date.with(Month.JULY); // most key classes implement TemporalAdjuster * date = date.with(lastDayOfMonth()); // static import from TemporalAdjusters * date = date.with(next(WEDNESDAY)); // static import from TemporalAdjusters and DayOfWeek * ``` */ with(adjuster: TemporalAdjuster): Temporal; /** * Returns an object of the same type as this object with the specified field altered. * * This returns a new object based on this one with the value for the specified field changed. * For example, on a `LocalDate`, this could be used to set the year, month or day-of-month. * The returned object will have the same observable type as this object. * * In some cases, changing a field is not fully defined. For example, if the target object is * a date representing the 31st January, then changing the month to February would be unclear. * In cases like this, the field is responsible for resolving the result. Typically it will * choose the previous valid date, which would be the last valid day of February in this * example. */ with(field: TemporalField, newValue: number): Temporal; abstract isSupported(field: TemporalField): boolean; /** * Checks if the specified unit is supported. * * This checks if the date-time can be queried for the specified unit. If false, then calling * the plus and minus methods will throw an exception. */ abstract isSupported(unit: TemporalUnit): boolean; /** * Calculates the period between this temporal and another temporal in terms of the * specified unit. * * This calculates the period between two temporals in terms of a single unit. The start * and end points are this and the specified temporal. The result will be negative if the * end is before the start. For example, the period in hours between two temporal objects * can be calculated using `startTime.until(endTime, HOURS)`. * * The calculation returns a whole number, representing the number of complete units between * the two temporals. For example, the period in hours between the times 11:30 and 13:29 will * only be one hour as it is one minute short of two hours. * * There are two equivalent ways of using this method. The first is to invoke this method * directly. The second is to use `TemporalUnit.between(Temporal, Temporal)`: * ``` * // these two lines are equivalent * between = thisUnit.between(start, end); * between = start.until(end, thisUnit); * ``` * * The choice should be made based on which makes the code more readable. * * For example, this method allows the number of days between two dates to be calculated: * ``` * const daysBetween = DAYS.between(start, end); * // or alternatively * const daysBetween = start.until(end, DAYS); * ``` */ abstract until(endTemporal: Temporal, unit: TemporalUnit): number; protected _minusUnit(amountToSubtract: number, unit: TemporalUnit): Temporal; protected _minusAmount(amount: TemporalAmount): Temporal; protected _plusAmount(amount: TemporalAmount): Temporal; protected _withAdjuster(adjuster: TemporalAdjuster): Temporal; protected abstract _plusUnit(amountToAdd: number, unit: TemporalUnit): Temporal; protected abstract _withField(field: TemporalField, newValue: number): Temporal; } /** * Strategy for adjusting a temporal object. * * Adjusters are a key tool for modifying temporal objects. They exist to externalize the process * of adjustment, permitting different approaches, as per the strategy design pattern. Examples * might be an adjuster that sets the date avoiding weekends, or one that sets the date to the * last day of the month. * * There are two equivalent ways of using a `TemporalAdjuster`. The first is to invoke the method * on this interface directly. The second is to use `Temporal.with(TemporalAdjuster)`: * * ``` * // these two lines are equivalent, but the second approach is recommended * temporal = thisAdjuster.adjustInto(temporal); * temporal = temporal.with(thisAdjuster); * ``` * * It is recommended to use the second approach, `with(TemporalAdjuster)`, as it is a lot clearer * to read in code. * * See `TemporalAdjusters` for a standard set of adjusters, including finding the last day of * the month. Adjusters may also be defined by applications. */ export abstract class TemporalAdjuster { abstract adjustInto(temporal: Temporal): Temporal; } export abstract class TemporalQuery<R> { abstract queryFrom(temporal: TemporalAccessor): R; } /** A standard set of fields. * * This set of fields provide field-based access to manipulate a date, time or date-time. * The standard set of fields can be extended by implementing {@link TemporalField}. */ export class ChronoField extends TemporalField { /** * This represents concept of the count of * days within the period of a week where the weeks are aligned to the start of the month. * This field is typically used with `ALIGNED_WEEK_OF_MONTH`. */ static ALIGNED_DAY_OF_WEEK_IN_MONTH: ChronoField; /** * This represents concept of the count of days * within the period of a week where the weeks are aligned to the start of the year. * This field is typically used with `ALIGNED_WEEK_OF_YEAR`. */ static ALIGNED_DAY_OF_WEEK_IN_YEAR: ChronoField; /** * This represents concept of the count of weeks within * the period of a month where the weeks are aligned to the start of the month. This field * is typically used with `ALIGNED_DAY_OF_WEEK_IN_MONTH`. */ static ALIGNED_WEEK_OF_MONTH: ChronoField; /** * his represents concept of the count of weeks within * the period of a year where the weeks are aligned to the start of the year. This field * is typically used with `ALIGNED_DAY_OF_WEEK_IN_YEAR`. */ static ALIGNED_WEEK_OF_YEAR: ChronoField; /** * This counts the AM/PM within the day, from 0 (AM) to 1 (PM). */ static AMPM_OF_DAY: ChronoField; /** * This counts the hour within the AM/PM, from 1 to 12. * This is the hour that would be observed on a standard 12-hour analog wall clock. */ static CLOCK_HOUR_OF_AMPM: ChronoField; /** * This counts the hour within the AM/PM, from 1 to 24. * This is the hour that would be observed on a 24-hour analog wall clock. */ static CLOCK_HOUR_OF_DAY: ChronoField; /** * This represents the concept of the day within the month. * In the default ISO calendar system, this has values from 1 to 31 in most months. * April, June, September, November have days from 1 to 30, while February has days from * 1 to 28, or 29 in a leap year. */ static DAY_OF_MONTH: ChronoField; /** * This represents the standard concept of the day of the week. * In the default ISO calendar system, this has values from Monday (1) to Sunday (7). * The {@link DayOfWeek} class can be used to interpret the result. */ static DAY_OF_WEEK: ChronoField; /** * This represents the concept of the day within the year. * In the default ISO calendar system, this has values from 1 to 365 in standard years and * 1 to 366 in leap years. */ static DAY_OF_YEAR: ChronoField; /** * This field is the sequential count of days where * 1970-01-01 (ISO) is zero. Note that this uses the local time-line, ignoring offset and * time-zone. */ static EPOCH_DAY: ChronoField; /** * This represents the concept of the era, which is the largest * division of the time-line. This field is typically used with `YEAR_OF_ERA`. * * In the default ISO calendar system, there are two eras defined, 'BCE' and 'CE'. The era * 'CE' is the one currently in use and year-of-era runs from 1 to the maximum value. * The era 'BCE' is the previous era, and the year-of-era runs backwards. */ static ERA: ChronoField; /** * This counts the hour within the AM/PM, from 0 to 11. * This is the hour that would be observed on a standard 12-hour digital clock. */ static HOUR_OF_AMPM: ChronoField; /** * This counts the hour within the day, from 0 to 23. This is * the hour that would be observed on a standard 24-hour digital clock. */ static HOUR_OF_DAY: ChronoField; /** * This represents the concept of the sequential count of * seconds where `1970-01-01T00:00Z` (ISO) is zero. This field may be used with `NANO_OF_DAY` * to represent the fraction of the day. * * An Instant represents an instantaneous point on the time-line. On their own they have * no elements which allow a local date-time to be obtained. Only when paired with an offset * or time-zone can the local date or time be found. This field allows the seconds part of * the instant to be queried. */ static INSTANT_SECONDS: ChronoField; /** * This counts the microsecond within the day, from `0` to * `(24 * 60 * 60 * 1_000_000) - 1`. * * This field is used to represent the micro-of-day handling any fraction of the second. * Implementations of {@link TemporalAccessor} should provide a value for this field if they * can return a value for `SECOND_OF_DAY` filling unknown precision with zero. * * When this field is used for setting a value, it should behave in the same way as * setting `NANO_OF_DAY` with the value multiplied by 1,000. */ static MICRO_OF_DAY: ChronoField; /** * This counts the microsecond within the second, from 0 to 999,999. * * This field is used to represent the micro-of-second handling any fraction of the second. * Implementations of {@link TemporalAccessor} should provide a value for this field if they * can return a value for `SECOND_OF_MINUTE`, `SECOND_OF_DAY` or `INSTANT_SECONDS` filling * unknown precision with zero. */ static MICRO_OF_SECOND: ChronoField; /** * This counts the millisecond within the day, from 0 to * `(24 * 60 * 60 * 1,000) - 1`. * * This field is used to represent the milli-of-day handling any fraction of the second. * Implementations of {@link TemporalAccessor} should provide a value for this field if they * can return a value for `SECOND_OF_DAY` filling unknown precision with zero. * * When this field is used for setting a value, it should behave in the same way as * setting `NANO_OF_DAY` with the value multiplied by 1,000,000. */ static MILLI_OF_DAY: ChronoField; /** * This counts the millisecond within the second, from 0 to * 999. * * This field is used to represent the milli-of-second handling any fraction of the second. * Implementations of {@link TemporalAccessor} should provide a value for this field if they can * return a value for `SECOND_OF_MINUTE`, `SECOND_OF_DAY` or `INSTANT_SECONDS` filling unknown * precision with zero. * * When this field is used for setting a value, it should behave in the same way as * setting `NANO_OF_SECOND` with the value multiplied by 1,000,000. */ static MILLI_OF_SECOND: ChronoField; /** * This counts the minute within the day, from 0 to `(24 * 60) - 1`. */ static MINUTE_OF_DAY: ChronoField; /** * This counts the minute within the hour, from 0 to 59. */ static MINUTE_OF_HOUR: ChronoField; /** * The month-of-year, such as March. This represents the concept * of the month within the year. In the default ISO calendar system, this has values from * January (1) to December (12). */ static MONTH_OF_YEAR: ChronoField; /** * This counts the nanosecond within the day, from 0 to * `(24 * 60 * 60 * 1,000,000,000) - 1`. * * This field is used to represent the nano-of-day handling any fraction of the second. * Implementations of {@link TemporalAccessor} should provide a value for this field if they * can return a value for `SECOND_OF_DAY` filling unknown precision with zero. */ static NANO_OF_DAY: ChronoField; /** * This counts the nanosecond within the second, from 0 * to 999,999,999. * * This field is used to represent the nano-of-second handling any fraction of the second. * Implementations of {@link TemporalAccessor} should provide a value for this field if they * can return a value for `SECOND_OF_MINUTE`, `SECOND_OF_DAY` or `INSTANT_SECONDS` filling * unknown precision with zero. * * When this field is used for setting a value, it should set as much precision as the * object stores, using integer division to remove excess precision. For example, if the * {@link TemporalAccessor} stores time to millisecond precision, then the nano-of-second must * be divided by 1,000,000 before replacing the milli-of-second. */ static NANO_OF_SECOND: ChronoField; /** * This represents the concept of the offset in seconds of * local time from UTC/Greenwich. * * A {@link ZoneOffset} represents the period of time that local time differs from * UTC/Greenwich. This is usually a fixed number of hours and minutes. It is equivalent to * the total amount of the offset in seconds. For example, during the winter Paris has an * offset of +01:00, which is 3600 seconds. */ static OFFSET_SECONDS: ChronoField; /** * The proleptic-month, which counts months sequentially * from year 0. * * The first month in year zero has the value zero. The value increase for later months * and decrease for earlier ones. Note that this uses the local time-line, ignoring offset * and time-zone. */ static PROLEPTIC_MONTH: ChronoField; /** * This counts the second within the day, from 0 to * (24 * 60 * 60) - 1. */ static SECOND_OF_DAY: ChronoField; /** * This counts the second within the minute, from 0 to 59. */ static SECOND_OF_MINUTE: ChronoField; /** * The proleptic year, such as 2012. This represents the concept of * the year, counting sequentially and using negative numbers. The proleptic year is not * interpreted in terms of the era. * * The standard mental model for a date is based on three concepts - year, month and day. * These map onto the `YEAR`, `MONTH_OF_YEAR` and `DAY_OF_MONTH` fields. Note that there is no * reference to eras. The full model for a date requires four concepts - era, year, month and * day. These map onto the `ERA`, `YEAR_OF_ERA`, `MONTH_OF_YEAR` and `DAY_OF_MONTH` fields. * Whether this field or `YEAR_OF_ERA` is used depends on which mental model is being used. */ static YEAR: ChronoField; /** * This represents the concept of the year within the era. This * field is typically used with `ERA`. The standard mental model for a date is based on three * concepts - year, month and day. These map onto the `YEAR`, `MONTH_OF_YEAR` and * `DAY_OF_MONTH` fields. Note that there is no reference to eras. The full model for a date * requires four concepts - era, year, month and day. These map onto the `ERA`, `YEAR_OF_ERA`, * `MONTH_OF_YEAR` and `DAY_OF_MONTH` fields. Whether this field or `YEAR` is used depends on * which mental model is being used. * * In the default ISO calendar system, there are two eras defined, 'BCE' and 'CE'. * The era 'CE' is the one currently in use and year-of-era runs from 1 to the maximum value. * The era 'BCE' is the previous era, and the year-of-era runs backwards. * * For example, subtracting a year each time yield the following: * - year-proleptic 2 = 'CE' year-of-era 2 * - year-proleptic 1 = 'CE' year-of-era 1 * - year-proleptic 0 = 'BCE' year-of-era 1 * - year-proleptic -1 = 'BCE' year-of-era 2 * * Note that the ISO-8601 standard does not actually define eras. Note also that the * ISO eras do not align with the well-known AD/BC eras due to the change between the Julian * and Gregorian calendar systems. */ static YEAR_OF_ERA: ChronoField; private constructor(); isSupportedBy(temporal: TemporalAccessor): boolean; baseUnit(): TemporalUnit; /** Checks that the specified value is valid for this field. */ checkValidValue(value: number): number; /** * Checks that the specified value is valid for this field and * is within the range of a safe integer. */ checkValidIntValue(value: number): number; displayName(): string; equals(other: any): boolean; getFrom(temporal: TemporalAccessor): number; isDateBased(): boolean; isTimeBased(): boolean; name(): string; range(): ValueRange; rangeRefinedBy(temporal: TemporalAccessor): ValueRange; rangeUnit(): TemporalUnit; adjustInto<R extends Temporal>(temporal: R, newValue: number): R; toString(): string; } /** * A standard set of date periods units. * * This set of units provide unit-based access to manipulate a date, time or date-time. * The standard set of units can be extended by implementing TemporalUnit. */ export class ChronoUnit extends TemporalUnit { /** * Unit that represents the concept of a nanosecond, the smallest supported unit * of time. For the ISO calendar system, it is equal to the 1,000,000,000th part of the second unit. */ static NANOS: ChronoUnit; /** * Unit that represents the concept of a microsecond. For the ISO calendar * system, it is equal to the 1,000,000th part of the second unit. */ static MICROS: ChronoUnit; /** * Unit that represents the concept of a millisecond. For the ISO calendar * system, it is equal to the 1000th part of the second unit. */ static MILLIS: ChronoUnit; /** * Unit that represents the concept of a second. For the ISO calendar system, * it is equal to the second in the SI system of units, except around a leap-second. */ static SECONDS: ChronoUnit; /** * Unit that represents the concept of a minute. For the ISO calendar system, * it is equal to 60 seconds. */ static MINUTES: ChronoUnit; /** * Unit that represents the concept of an hour. For the ISO calendar system, * it is equal to 60 minutes. */ static HOURS: ChronoUnit; /** * Unit that represents the concept of half a day, as used in AM/PM. For * the ISO calendar system, it is equal to 12 hours. */ static HALF_DAYS: ChronoUnit; /** * Unit that represents the concept of a day. For the ISO calendar system, it * is the standard day from midnight to midnight. The estimated duration of a day is 24 Hours. */ static DAYS: ChronoUnit; /** * Unit that represents the concept of a week. For the ISO calendar system, * it is equal to 7 Days. */ static WEEKS: ChronoUnit; /** * Unit that represents the concept of a month. For the ISO calendar system, * the length of the month varies by month-of-year. The estimated duration of a month is * one twelfth of 365.2425 Days. */ static MONTHS: ChronoUnit; /** * Unit that represents the concept of a year. For the ISO calendar system, it * is equal to 12 months. The estimated duration of a year is 365.2425 Days. */ static YEARS: ChronoUnit; /** * Unit that represents the concept of a decade. For the ISO calendar system, * it is equal to 10 years. */ static DECADES: ChronoUnit; /** * Unit that represents the concept of a century. For the ISO calendar * system, it is equal to 100 years. */ static CENTURIES: ChronoUnit; /** * Unit that represents the concept of a millennium. For the ISO calendar * system, it is equal to 1,000 years. */ static MILLENNIA: ChronoUnit; /** * Unit that represents the concept of an era. The ISO calendar system doesn't * have eras thus it is impossible to add an era to a date or date-time. The estimated duration * of the era is artificially defined as 1,000,000,000 Years. */ static ERAS: ChronoUnit; /** * Artificial unit that represents the concept of forever. This is primarily * used with {@link TemporalField} to represent unbounded fields such as the year or era. The * estimated duration of the era is artificially defined as the largest duration supported by * {@link Duration}. */ static FOREVER: ChronoUnit; private constructor(); addTo<T extends Temporal>(temporal: T, amount: number): T; between(temporal1: Temporal, temporal2: Temporal): number; /** * Compares this ChronoUnit to the specified {@link TemporalUnit}. * The comparison is based on the total length of the durations. */ compareTo(other: TemporalUnit): number; duration(): Duration; isDateBased(): boolean; isDurationEstimated(): boolean; isSupportedBy(temporal: Temporal): boolean; isTimeBased(): boolean; toString(): string; } /** * Fields and units specific to the ISO-8601 calendar system, * including quarter-of-year and week-based-year. */ export namespace IsoFields { /** * This field allows the day-of-quarter value to be queried and set. The day-of-quarter has * values from 1 to 90 in Q1 of a standard year, from 1 to 91 in Q1 of a leap year, from * 1 to 91 in Q2 and from 1 to 92 in Q3 and Q4. * * The day-of-quarter can only be calculated if the day-of-year, month-of-year and year are available. * * When setting this field, the value is allowed to be partially lenient, taking any value from * 1 to 92. If the quarter has less than 92 days, then day 92, and potentially day 91, is in * the following quarter. */ export const DAY_OF_QUARTER: TemporalField; /** * This field allows the quarter-of-year value to be queried and set. The quarter-of-year has * values from 1 to 4. * * The day-of-quarter can only be calculated if the month-of-year is available. */ export const QUARTER_OF_YEAR: TemporalField; /** * The field that represents the week-of-week-based-year. */ export const WEEK_OF_WEEK_BASED_YEAR: TemporalField; /** * The field that represents the week-based-year. */ export const WEEK_BASED_YEAR: TemporalField; /** * The unit that represents week-based-years for the purpose of addition and subtraction. * * This allows a number of week-based-years to be added to, or subtracted from, a date. * The unit is equal to either 52 or 53 weeks. The estimated duration of a week-based-year is * the same as that of a standard ISO year at 365.2425 Days. * * The rules for addition add the number of week-based-years to the existing value for the * week-based-year field. If the resulting week-based-year only has 52 weeks, then the date * will be in week 1 of the following week-based-year. */ export const WEEK_BASED_YEARS: TemporalUnit; /** * Unit that represents the concept of a quarter-year. For the ISO calendar system, it is equal * to 3 months. The estimated duration of a quarter-year is one quarter of 365.2425 days. */ export const QUARTER_YEARS: TemporalUnit; } export namespace TemporalAdjusters { /** * Returns the day-of-week in month adjuster, which returns a new date in the same month with * the ordinal day-of-week. This is used for expressions like the 'second Tuesday in March'. * * The ISO calendar system behaves as follows: * - The input 2011-12-15 for (1,TUESDAY) will return 2011-12-06. * - The input 2011-12-15 for (2,TUESDAY) will return 2011-12-13. * - The input 2011-12-15 for (3,TUESDAY) will return 2011-12-20. * - The input 2011-12-15 for (4,TUESDAY) will return 2011-12-27. * - The input 2011-12-15 for (5,TUESDAY) will return 2012-01-03. * - The input 2011-12-15 for (-1,TUESDAY) will return 2011-12-27 (last in month). * - The input 2011-12-15 for (-4,TUESDAY) will return 2011-12-06 (3 weeks before last in month). * - The input 2011-12-15 for (-5,TUESDAY) will return 2011-11-29 (4 weeks before last in month). * - The input 2011-12-15 for (0,TUESDAY) will return 2011-11-29 (last in previous month). * * For a positive or zero ordinal, the algorithm is equivalent to finding the first day-of-week * that matches within the month and then adding a number of weeks to it. For a negative * ordinal, the algorithm is equivalent to finding the last day-of-week that matches within the * month and then subtracting a number of weeks to it. The ordinal number of weeks is not * validated and is interpreted leniently according to this algorithm. This definition means * that an ordinal of zero finds the last matching day-of-week in the previous month. * * The behavior is suitable for use with most calendar systems. It uses the `DAY_OF_WEEK` * and `DAY_OF_MONTH` fields and the `DAYS` unit, and assumes a seven day week. */ function dayOfWeekInMonth(ordinal: number, dayOfWeek: DayOfWeek): TemporalAdjuster; /** * Returns the "first day of month" adjuster, which returns a new date set to the first day * of the current month. * * The ISO calendar system behaves as follows: * - The input 2011-01-15 will return 2011-01-01. * - The input 2011-02-15 will return 2011-02-01. * * The behavior is suitable for use with most calendar systems. It is equivalent to: * ``` * temporal.with(DAY_OF_MONTH, 1); * ``` */ function firstDayOfMonth(): TemporalAdjuster; /** * Returns the "first day of next month" adjuster, which returns a new date set to the first * day of the next month. * * The ISO calendar system behaves as follows: * - The input 2011-01-15 will return 2011-02-01. * - The input 2011-02-15 will return 2011-03-01. * * The behavior is suitable for use with most calendar systems. It is equivalent to: * ``` * temporal.with(DAY_OF_MONTH, 1).plus(1, MONTHS); * ``` */ function firstDayOfNextMonth(): TemporalAdjuster; /** * Returns the "first day of next year" adjuster, which returns a new date set to the first * day of the next year. * * The ISO calendar system behaves as follows: * - The input 2011-01-15 will return 2012-01-01. * * The behavior is suitable for use with most calendar systems. It is equivalent to: * ``` * temporal.with(DAY_OF_YEAR, 1).plus(1, YEARS); * ``` */ function firstDayOfNextYear(): TemporalAdjuster; /** * Returns the "first day of year" adjuster, which returns a new date set to the first day * of the current year. * * The ISO calendar system behaves as follows: * - The input 2011-01-15 will return 2011-01-01. * - The input 2011-02-15 will return 2011-01-01. * * The behavior is suitable for use with most calendar systems. It is equivalent to: * ``` * temporal.with(DAY_OF_YEAR, 1); * ``` */ function firstDayOfYear(): TemporalAdjuster; /** * Returns the first in month adjuster, which returns a new date in the same month with the * first matching day-of-week. This is used for expressions like 'first Tuesday in March'. * * The ISO calendar system behaves as follows: * - The input 2011-12-15 for (MONDAY) will return 2011-12-05. * - The input 2011-12-15 for (FRIDAY) will return 2011-12-02. * * The behavior is suitable for use with most calendar systems. It uses the `DAY_OF_WEEK` * and `DAY_OF_MONTH` fields and the `DAYS` unit, and assumes a seven day week. */ function firstInMonth(dayOfWeek: DayOfWeek): TemporalAdjuster; /** * Returns the "last day of month" adjuster, which returns a new date set to the last day of * the current month. * * The ISO calendar system behaves as follows: * - The input 2011-01-15 will return 2011-01-31. * - The input 2011-02-15 will return 2011-02-28. * - The input 2012-02-15 will return 2012-02-29 (leap year). * - The input 2011-04-15 will return 2011-04-30. * * The behavior is suitable for use with most calendar systems. It is equivalent to: * ``` * const lastDay = temporal.range(DAY_OF_MONTH).getMaximum(); * temporal.with(DAY_OF_MONTH, lastDay); * ``` */ function lastDayOfMonth(): TemporalAdjuster; /** * Returns the "last day of year" adjuster, which returns a new date set to the last day of * the current year. * * The ISO calendar system behaves as follows: * - The input 2011-01-15 will return 2011-12-31. * - The input 2011-02-15 will return 2011-12-31. * * The behavior is suitable for use with most calendar systems. It is equivalent to: * ``` * const lastDay = temporal.range(DAY_OF_YEAR).getMaximum(); * temporal.with(DAY_OF_YEAR, lastDay); * ``` */ function lastDayOfYear(): TemporalAdjuster; /** * Returns the last in month adjuster, which returns a new date in the same month with the * last matching day-of-week. This is used for expressions like 'last Tuesday in March'. * * The ISO calendar system behaves as follows: * - The input 2011-12-15 for (MONDAY) will return 2011-12-26. * - The input 2011-12-15 for (FRIDAY) will return 2011-12-30. * * The behavior is suitable for use with most calendar systems. It uses the `DAY_OF_WEEK` * and `DAY_OF_MONTH` fields and the `DAYS` unit, and assumes a seven day week. */ function lastInMonth(dayOfWeek: DayOfWeek): TemporalAdjuster; /** * Returns the next day-of-week adjuster, which adjusts the date to the first occurrence of * the specified day-of-week after the date being adjusted. * * - The ISO calendar system behaves as follows: * - The input 2011-01-15 (a Saturday) for parameter (MONDAY) will return 2011-01-17 (two * days later). * - The input 2011-01-15 (a Saturday) for parameter (WEDNESDAY) will return 2011-01-19 (four * days later). * - The input 2011-01-15 (a Saturday) for parameter (SATURDAY) will return 2011-01-22 (seven * days later). * * The behavior is suitable for use with most calendar systems. It uses the `DAY_OF_WEEK` * field and the `DAYS` unit, and assumes a seven day week. */ function next(dayOfWeek: DayOfWeek): TemporalAdjuster; /** * Returns the next-or-same day-of-week adjuster, which adjusts the date to the first * occurrence of the specified day-of-week after the date being adjusted unless it is already * on that day in which case the same object is returned. * * The ISO calendar system behaves as follows: * - The input 2011-01-15 (a Saturday) for parameter (MONDAY) will return 2011-01-17 (two * days later). * - The input 2011-01-15 (a Saturday) for parameter (WEDNESDAY) will return 2011-01-19 (four * days later). * - The input 2011-01-15 (a Saturday) for parameter (SATURDAY) will return 2011-01-15 (same * as input). * * The behavior is suitable for use with most calendar systems. It uses the `DAY_OF_WEEK` * field and the `DAYS` unit, and assumes a seven day week. */ function nextOrSame(dayOfWeek: DayOfWeek): TemporalAdjuster; /** * Returns the previous day-of-week adjuster, which adjusts the date to the first occurrence * of the specified day-of-week before the date being adjusted. * * The ISO calendar system behaves as follows: * - The input 2011-01-15 (a Saturday) for parameter (MONDAY) will return 2011-01-10 (five * days earlier). * - The input 2011-01-15 (a Saturday) for parameter (WEDNESDAY) will return 2011-01-12 (three * days earlier). * - The input 2011-01-15 (a Saturday) for parameter (SATURDAY) will return 2011-01-08 (seven * days earlier). * * The behavior is suitable for use with most calendar systems. It uses the `DAY_OF_WEEK` field * and the `DAYS` unit, and assumes a seven day week. */ function previous(dayOfWeek: DayOfWeek): TemporalAdjuster; /** * Returns the previous-or-same day-of-week adjuster, which adjusts the date to the first * occurrence of the specified day-of-week before the date being adjusted unless it is already * on that day in which case the same object is returned. * * The ISO calendar system behaves as follows: * - The input 2011-01-15 (a Saturday) for parameter (MONDAY) will return 2011-01-10 (five * days earlier). * - The input 2011-01-15 (a Saturday) for parameter (WEDNESDAY) will return 2011-01-12 (three * days earlier). * - The input 2011-01-15 (a Saturday) for parameter (SATURDAY) will return 2011-01-15 (same * as input). * * The behavior is suitable for use with most calendar systems. It uses the `DAY_OF_WEEK` * field and the `DAYS` unit, and assumes a seven day week. */ function previousOrSame(dayOfWeek: DayOfWeek): TemporalAdjuster; } export namespace TemporalQueries { function chronology(): TemporalQuery<Chronology | null>; function localDate(): TemporalQuery<LocalDate | null>; function localTime(): TemporalQuery<LocalTime | null>; function offset(): TemporalQuery<ZoneOffset | null>; function precision(): TemporalQuery<TemporalUnit | null>; function zone(): TemporalQuery<ZoneId | null>; function zoneId(): TemporalQuery<ZoneId | null>; } // ---------------------------------------------------------------------------- // MAIN // ---------------------------------------------------------------------------- export abstract class Clock { static fixed(fixedInstant: Instant, zoneId: ZoneId): Clock; static offset(baseClock: Clock, offsetDuration: Duration): Clock; static system(zone: ZoneId): Clock; static systemDefaultZone(): Clock; static systemUTC(): Clock; abstract equals(other: any):