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OAAO,GAAG,MAAM;IAIjC,eAAe;IAMf,WAAW;IAIX,WAAW;IAIX,WAAW;IAIX,QAAQ;IAIR,MAAM;IAIN,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM;IAY9B,MAAM,CAAC,gBAAgB,CAAC,YAAY,EAAE,MAAM,EAAE,WAAW,GAAE,MAAU;IAMrE,MAAM,CAAC,eAAe,CAAC,WAAW,EAAE,MAAM;IAI1C,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK;IAIvB,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,OAAO;IAKjC,CAAC,SAAS,CAAC,IAAI,CAAC;IAMhB,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,OAAO;CAIxC","file":"Instant.d.ts","sourcesContent":["/*!\r\n   Copyright 2019 Ron Buckton\r\n\r\n   Licensed under the Apache License, Version 2.0 (the \"License\");\r\n   you may not use this file except in compliance with the License.\r\n   You may obtain a copy of the License at\r\n\r\n       http://www.apache.org/licenses/LICENSE-2.0\r\n\r\n   Unless required by applicable law or agreed to in writing, software\r\n   distributed under the License is distributed on an \"AS IS\" BASIS,\r\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n   See the License for the specific language governing permissions and\r\n   limitations under the License.\r\n*/\r\nimport { R } from 'retemplate';\r\nimport { isInt, compareBigInts, normalizeString, INSTANT_HASH_SEED } from './internal/core';\r\nimport { getDatePart, getDate, DatePart } from './internal/date';\r\nimport { getTimePart, getTime, TimePart } from './internal/time';\r\nimport { getInstantPart, getInstant, getDateOfInstant, getTimeOfInstant, InstantPart, truncateInstant } from './internal/instant';\r\nimport { instantDiff, instantPlus } from './internal/math';\r\nimport { TICKS } from './internal/symbols';\r\nimport { NANOS_OF_EPOCH } from './internal/types';\r\nimport { CALENDAR_DATETIME_EXTENDED } from './internal/patterns';\r\nimport { Components, TimeDelta, InstantUnit, TimeUnit, Temporal } from './types';\r\nimport { Zone, ZoneOffset } from './Zone';\r\nimport { Clock } from './Clock';\r\nimport { CivilDateTime } from './CivilDateTime';\r\nimport { CivilDate } from './CivilDate';\r\nimport { CivilTime } from './CivilTime';\r\nimport { OffsetDateTime } from './OffsetDateTime';\r\nimport { ZonedDateTime } from './ZonedDateTime';\r\nimport { Duration } from './Duration';\r\nimport { Comparable, Equatable, Equaler } from '@esfx/equatable';\r\n\r\nconst instantRegExp = new RegExp(R`^${CALENDAR_DATETIME_EXTENDED}Z$`);\r\n\r\nexport class Instant implements Temporal<Instant>, Equatable, Comparable {\r\n    static readonly EPOCH = new Instant(0n);\r\n\r\n    /* @internal */ private [TICKS]: NANOS_OF_EPOCH;\r\n\r\n    constructor(ns: bigint) {\r\n        this[TICKS] = ns as NANOS_OF_EPOCH;\r\n    }\r\n\r\n    get milliseconds() { return getInstantPart(this[TICKS], InstantPart.milliseconds); }\r\n    get nanoseconds() { return getInstantPart(this[TICKS], InstantPart.nanoseconds); }\r\n\r\n    plus(deltas: Components<TimeDelta> = {}) {\r\n        const { hours = 0, minutes = 0, seconds = 0, milliseconds = 0, nanoseconds = 0 } = deltas;\r\n        if (!isInt(hours)) throw new RangeError(`The value ${hours} is not valid for 'hours' as it is not an integer.`);\r\n        if (!isInt(minutes)) throw new RangeError(`The value ${minutes} is not valid for 'minutes' as it is not an integer.`);\r\n        if (!isInt(seconds)) throw new RangeError(`The value ${seconds} is not valid for 'seconds' as it is not an integer.`);\r\n        if (!isInt(milliseconds)) throw new RangeError(`The value ${milliseconds} is not valid for 'milliseconds' as it is not an integer.`);\r\n        if (!isInt(nanoseconds)) throw new RangeError(`The value ${nanoseconds} is not valid for 'nanoseconds' as it is not an integer.`);\r\n        return new Instant(instantPlus(this[TICKS], hours, minutes, seconds, milliseconds, nanoseconds));\r\n    }\r\n\r\n    minus(deltas: Components<TimeDelta> = {}) {\r\n        const { hours = 0, minutes = 0, seconds = 0, milliseconds = 0, nanoseconds = 0 } = deltas;\r\n        if (!isInt(hours)) throw new RangeError(`The value ${hours} is not valid for 'hours' as it is not an integer.`);\r\n        if (!isInt(minutes)) throw new RangeError(`The value ${minutes} is not valid for 'minutes' as it is not an integer.`);\r\n        if (!isInt(seconds)) throw new RangeError(`The value ${seconds} is not valid for 'seconds' as it is not an integer.`);\r\n        if (!isInt(milliseconds)) throw new RangeError(`The value ${milliseconds} is not valid for 'milliseconds' as it is not an integer.`);\r\n        if (!isInt(nanoseconds)) throw new RangeError(`The value ${nanoseconds} is not valid for 'nanoseconds' as it is not an integer.`);\r\n        return new Instant(instantPlus(this[TICKS], -hours, -minutes, -seconds, -milliseconds, -nanoseconds));\r\n    }\r\n\r\n    truncate(unit: TimeUnit) {\r\n        return Instant.fromNanoseconds(truncateInstant(this[TICKS], unit));\r\n    }\r\n\r\n    with(components: Components<InstantUnit> = {}) {\r\n        const { milliseconds = this.milliseconds, nanoseconds = this.nanoseconds } = components;\r\n        return Instant.fromMilliseconds(milliseconds, nanoseconds);\r\n    }\r\n\r\n    withOffset(offset: ZoneOffset) {\r\n        return OffsetDateTime.fromInstant(offset, this);\r\n    }\r\n\r\n    withZone(zone: Zone | string) {\r\n        return new ZonedDateTime(this, zone);\r\n    }\r\n\r\n    until(other: Instant): Duration {\r\n        if (!(other instanceof Instant)) throw new TypeError();\r\n        return new Duration(instantDiff(this[TICKS], other[TICKS]));\r\n    }\r\n\r\n    since(other: Instant) {\r\n        if (!(other instanceof Instant)) throw new TypeError();\r\n        return other.until(this);\r\n    }\r\n\r\n    equals(other: Instant) {\r\n        return other !== null\r\n            && other !== undefined\r\n            && this[TICKS] === other[TICKS];\r\n    }\r\n\r\n    compareTo(other: Instant): number {\r\n        return compareBigInts(this[TICKS], other[TICKS]);\r\n    }\r\n\r\n    toCivilDateTime() {\r\n        const { year, month, day } = getDatePart(getDateOfInstant(this[TICKS]), DatePart.all);\r\n        const { hour, minute, second, millisecond, nanosecond } = getTimePart(getTimeOfInstant(this[TICKS]), TimePart.all);\r\n        return new CivilDateTime(year, month, day, hour, minute, second, millisecond, nanosecond);\r\n    }\r\n\r\n    toCivilDate() {\r\n        return CivilDate.fromDayOfEpoch(getDateOfInstant(this[TICKS]));\r\n    }\r\n\r\n    toCivilTime() {\r\n        return CivilTime.fromNanoseconds(getTimeOfInstant(this[TICKS]));\r\n    }\r\n\r\n    toISOString() {\r\n        return `${this.toCivilDateTime().toCalendarDateTimeString()}Z`;\r\n    }\r\n\r\n    toString() {\r\n        return this.toISOString();\r\n    }\r\n\r\n    toJSON() {\r\n        return this.toISOString();\r\n    }\r\n\r\n    static fromString(text: string) {\r\n        const match = instantRegExp.exec(normalizeString(text));\r\n        if (match) {\r\n            const { year, month, day, hour, minute, second, millisecond = \"\", nanosecond = \"\" } = match.groups!;\r\n            return new Instant(getInstant(\r\n                getDate(+year, +month, +day),\r\n                getTime(+hour, +minute, +second, +millisecond.padEnd(3, \"0\"), +nanosecond.padEnd(6, \"0\"))));\r\n        }\r\n\r\n        throw new SyntaxError(`Invalid instant string '${text}'`);\r\n    }\r\n\r\n    static fromMilliseconds(milliseconds: number, nanoseconds: number = 0) {\r\n        if (!isInt(milliseconds)) throw new RangeError(`The value ${milliseconds} is not valid for the number of milliseconds.`);\r\n        if (!isInt(nanoseconds)) throw new RangeError(`The value ${nanoseconds} is not valid for the number of nanoseconds.`);\r\n        return new Instant(getTime(0, 0, 0, milliseconds, nanoseconds));\r\n    }\r\n\r\n    static fromNanoseconds(nanoseconds: bigint) {\r\n        return new Instant(nanoseconds);\r\n    }\r\n\r\n    static now(clock: Clock) {\r\n        return clock.currentInstant();\r\n    }\r\n\r\n    [Equatable.equals](other: unknown) {\r\n        return other instanceof Instant\r\n            && this.equals(other);\r\n    }\r\n\r\n    [Equatable.hash]() {\r\n        let hc = INSTANT_HASH_SEED;\r\n        hc = ((hc << 7) | (hc >>> 25)) ^ Equaler.defaultEqualer.hash(this[TICKS]);\r\n        return hc;\r\n    }\r\n\r\n    [Comparable.compareTo](other: unknown) {\r\n        if (!(other instanceof Instant)) throw new TypeError();\r\n        return this.compareTo(other);\r\n    }\r\n}\r\n\r\nObject.defineProperty(Instant.prototype, Symbol.toStringTag, {\r\n    writable: true,\r\n    configurable: true,\r\n    value: \"Instant\"\r\n});\r\n"],"sourceRoot":""}