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UAAU,GAAG,QAAQ;IAKlC,WAAW;IAIX,MAAM,CAAC,KAAK,EAAE,UAAU;IAOxB,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM;IAIpC,QAAQ;IAIR,WAAW;IAIX,MAAM;IAIN,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS;IAI/C;;OAEG;IACH,MAAM,CAAC,eAAe,CAAC,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,GAAG,UAAU;IAQ3E,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO;IAMvD,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM;IAY9B,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK;IAMvB,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,OAAO;IAKjC,CAAC,SAAS,CAAC,IAAI,CAAC;IAOhB,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,OAAO;CAIxC","file":"OffsetTime.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, OFFSETTIME_HASH_SEED } from './internal/core';\r\nimport { getTime, getTimePart, TimePart, NANOSECONDS_PER_DAY } from './internal/time';\r\nimport { getTimeOfInstant, adjustInstant, getInstant } from './internal/instant';\r\nimport { TIME, OFFSET, TICKS } from './internal/symbols';\r\nimport { NANOS_OF_DAY } from './internal/types';\r\nimport { OFFSET_TIME_EXTENDED, OFFSET_TIME_BASIC } from './internal/patterns';\r\nimport { Temporal, Components, TimeDelta, TimeUnit } from './types';\r\nimport { ZoneOffset } from './Zone';\r\nimport { Clock } from './Clock';\r\nimport { CivilDate } from './CivilDate';\r\nimport { CivilTime } from './CivilTime';\r\nimport { ZonedDateTime } from './ZonedDateTime';\r\nimport { Instant } from './Instant';\r\nimport { Duration } from './Duration';\r\nimport { Equatable, Comparable, Equaler } from '@esfx/equatable';\r\n\r\nconst offsetTimeExtendedRegExp = new RegExp(R`^${OFFSET_TIME_EXTENDED}$`);\r\nconst offsetTimeBasicRegExp = new RegExp(R`^${OFFSET_TIME_BASIC}$`);\r\n\r\nexport class OffsetTime implements Temporal<OffsetTime>, Equatable, Comparable {\r\n    /* @internal */ private [OFFSET]: ZoneOffset;\r\n    /* @internal */ private [TIME]: NANOS_OF_DAY;\r\n\r\n    constructor(offset: ZoneOffset, hour: number, minute: number, second: number = 0, millisecond: number = 0, nanosecond: number = 0) {\r\n        if (!isInt(hour) || hour < 0 || hour > 24) throw new RangeError(`The value ${hour} is not a valid hour.`);\r\n        if (!isInt(minute) || minute < 0 || minute > 59) throw new RangeError(`The value ${minute} is not a valid minute.`);\r\n        if (!isInt(second) || second < 0 || second > 59) throw new RangeError(`The value ${second} is not a valid second.`);\r\n        if (!isInt(millisecond) || millisecond < 0 || millisecond > 1e3) throw new RangeError(`The value ${millisecond} is not a valid millisecond.`);\r\n        if (!isInt(nanosecond) || nanosecond < 0 || nanosecond > 1e6) throw new RangeError(`The value ${nanosecond} is not a valid nanosecond.`);\r\n        if (hour === 24 && minute !== 0) throw new RangeError(`The value ${minute} is not a valid minute of hour ${hour}.`);\r\n        if (hour === 24 && second !== 0) throw new RangeError(`The value ${second} is not a valid second of hour ${hour}.`);\r\n        if (hour === 24 && millisecond !== 0) throw new RangeError(`The value ${millisecond} is not a valid second of hour ${millisecond}.`);\r\n        if (hour === 24 && nanosecond !== 0) throw new RangeError(`The value ${nanosecond} is not a valid second of hour ${nanosecond}.`);\r\n        this[OFFSET] = offset;\r\n        this[TIME] = getTime(hour, minute, second, millisecond, nanosecond);\r\n    }\r\n\r\n    get offset() { return this[OFFSET]; }\r\n    get offsetSeconds() { return this.offset.offsetSeconds; }\r\n    get offsetString() { return this.offset.offsetString; }\r\n    get hour() { return this[TIME] === NANOSECONDS_PER_DAY ? 24 : getTimePart(this[TIME], TimePart.hour); }\r\n    get minute() { return getTimePart(this[TIME], TimePart.minute); }\r\n    get second() { return getTimePart(this[TIME], TimePart.second); }\r\n    get millisecond() { return getTimePart(this[TIME], TimePart.millisecond); }\r\n    get nanosecond() { return getTimePart(this[TIME], TimePart.nanosecond); }\r\n\r\n    plus(deltas?: Components<TimeDelta>) {\r\n        return this\r\n            .toCivilTime()\r\n            .plus(deltas)\r\n            .withOffset(this.offset);\r\n    }\r\n\r\n    minus(deltas?: Components<TimeDelta>) {\r\n        return this\r\n            .toCivilTime()\r\n            .minus(deltas)\r\n            .withOffset(this.offset);\r\n    }\r\n\r\n    with(components?: Components<TimeUnit>) {\r\n        return this\r\n            .toCivilTime()\r\n            .with(components)\r\n            .withOffset(this.offset);\r\n    }\r\n\r\n    withOffsetSameInstant(offset: ZoneOffset) {\r\n        let time = this[TIME]; // Local to this.offset\r\n        time = adjustTime(time, -this.offsetSeconds); // UTC\r\n        time = adjustTime(time, offset.offsetSeconds); // Local to offset\r\n        return OffsetTime.fromNanoseconds(offset, time);\r\n    }\r\n\r\n    withOffsetSameLocal(offset: ZoneOffset) {\r\n        return OffsetTime.fromNanoseconds(offset, this[TIME]);\r\n    }\r\n\r\n    withDate(date: CivilDate) {\r\n        if (!(date instanceof CivilDate)) throw new TypeError(\"CivilDate expected: date\");\r\n        return ZonedDateTime.fromCalendarDateTime(\r\n            this.offset,\r\n            date.year,\r\n            date.month,\r\n            date.day,\r\n            this.hour,\r\n            this.minute,\r\n            this.second,\r\n            this.millisecond,\r\n            this.nanosecond);\r\n    }\r\n\r\n    until(other: OffsetTime): Duration {\r\n        if (!(other instanceof OffsetTime)) throw new TypeError(\"OffsetTime expected: other\");\r\n        return Duration.fromNanoseconds(other[TIME] - this[TIME]);\r\n    }\r\n\r\n    since(other: OffsetTime): Duration {\r\n        if (!(other instanceof OffsetTime)) throw new TypeError(\"OffsetTime expected: other\");\r\n        return other.until(this);\r\n    }\r\n\r\n    toCivilTime() {\r\n        return new CivilTime(this.hour, this.minute, this.second, this.millisecond, this.nanosecond);\r\n    }\r\n\r\n    equals(other: OffsetTime) {\r\n        return other !== null\r\n            && other !== undefined\r\n            && this[TIME] === other[TIME]\r\n            && this[OFFSET].equals(other[OFFSET]);\r\n    }\r\n\r\n    compareTo(other: OffsetTime): number {\r\n        return compareBigInts(this[TIME], other[TIME]);\r\n    }\r\n\r\n    toString() {\r\n        return `${this.toCivilTime()}${this.offsetString}`;\r\n    }\r\n\r\n    toISOString() {\r\n        return this.toString();\r\n    }\r\n\r\n    toJSON() {\r\n        return this.toString();\r\n    }\r\n\r\n    static from(offset: ZoneOffset, time: CivilTime) {\r\n        return OffsetTime.fromNanoseconds(offset, time[TIME]);\r\n    }\r\n\r\n    /**\r\n     * Creates a OffseTime from the number of nanoseconds since the start of the local day.\r\n     */\r\n    static fromNanoseconds(offset: ZoneOffset, nanoseconds: bigint): OffsetTime {\r\n        if (nanoseconds < 0 || nanoseconds >= NANOSECONDS_PER_DAY) throw new RangeError(`The value ${nanoseconds} is not a valid number of nanoseconds`);\r\n        return Object.create(OffsetTime.prototype, {\r\n            [OFFSET]: { value: offset },\r\n            [TIME]: { value: nanoseconds }\r\n        });\r\n    }\r\n\r\n    static fromInstant(offset: ZoneOffset, instant: Instant) {\r\n        let time = getTimeOfInstant(instant[TICKS]); // UTC\r\n        time = adjustTime(time, offset.offsetSeconds); // Local\r\n        return OffsetTime.fromNanoseconds(offset, time);\r\n    }\r\n\r\n    static fromString(text: string) {\r\n        const normalText = normalizeString(text);\r\n        const match = offsetTimeExtendedRegExp.exec(normalText) || offsetTimeBasicRegExp.exec(normalText);\r\n        if (match) {\r\n            const { hour, minute, second, millisecond = \"\", nanosecond = \"\", offset } = match.groups!;\r\n            const zone = ZoneOffset.fromString(offset);\r\n            return new OffsetTime(zone, +hour, +minute, +second, +millisecond.padEnd(3, \"0\"), +nanosecond.padEnd(6, \"0\"));\r\n        }\r\n\r\n        throw new Error(`Invalid offset time string '${text}'.`);\r\n    }\r\n\r\n    static now(clock: Clock) {\r\n        const instant = clock.currentInstant();\r\n        const offset = clock.zone.getOffset(instant);\r\n        return OffsetTime.fromInstant(offset, instant);\r\n    }\r\n\r\n    [Equatable.equals](other: unknown) {\r\n        return other instanceof OffsetTime\r\n            && this.equals(other);\r\n    }\r\n\r\n    [Equatable.hash]() {\r\n        let hc = OFFSETTIME_HASH_SEED;\r\n        hc = ((hc << 7) | (hc >>> 25)) ^ Equaler.defaultEqualer.hash(this[TIME]);\r\n        hc = ((hc << 7) | (hc >>> 25)) ^ this[OFFSET][Equatable.hash]();\r\n        return hc;\r\n    }\r\n\r\n    [Comparable.compareTo](other: unknown) {\r\n        if (!(other instanceof OffsetTime)) throw new TypeError();\r\n        return this.compareTo(other);\r\n    }\r\n}\r\n\r\nObject.defineProperty(OffsetTime.prototype, Symbol.toStringTag, {\r\n    writable: true,\r\n    configurable: true,\r\n    value: \"OffsetTime\"\r\n});\r\n\r\nfunction adjustTime(time: NANOS_OF_DAY, offsetSeconds: number) {\r\n    return getTimeOfInstant(adjustInstant(getInstant(0n, time), offsetSeconds));\r\n}\r\n"],"sourceRoot":""}