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AK,EAAE,SAAS;IAMvB,SAAS,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM;IAInC;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,SAAI,EAAE,WAAW,SAAI,EAAE,UAAU,SAAI;IAIzF;;OAEG;IACH,MAAM,CAAC,gBAAgB,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,SAAI;IAM5D;;OAEG;IACH,MAAM,CAAC,eAAe,CAAC,WAAW,EAAE,MAAM,GAAG,SAAS;IAKtD,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM;IAW9B,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK;IAMvB,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":"CivilTime.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, CIVILTIME_HASH_SEED } from './internal/core';\r\nimport { getTime, getTimePart, TimePart, NANOSECONDS_PER_DAY } from './internal/time';\r\nimport { timeDiff, timePlus } from './internal/math';\r\nimport { TIME } from './internal/symbols';\r\nimport { NANOS_OF_DAY } from './internal/types';\r\nimport { TIME_EXTENDED, TIME_BASIC } from './internal/patterns';\r\nimport { D6, D3, D2 } from \"./internal/formats\";\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 { CivilDateTime } from './CivilDateTime';\r\nimport { OffsetTime } from './OffsetTime';\r\nimport { Duration } from './Duration';\r\nimport { Equatable, Comparable, Equaler } from '@esfx/equatable';\r\n\r\nconst timeExtendedRegExp = new RegExp(R`^${TIME_EXTENDED}$`);\r\nconst timeBasicRegExp = new RegExp(R`^${TIME_BASIC}$`);\r\n\r\nexport class CivilTime implements Temporal<CivilTime>, Equatable, Comparable {\r\n    static readonly START_OF_DAY = new CivilTime(0, 0);\r\n    static readonly END_OF_DAY = new CivilTime(24, 0);\r\n\r\n    /* @internal */ private [TIME]: NANOS_OF_DAY;\r\n\r\n    constructor(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[TIME] = getTime(hour, minute, second, millisecond, nanosecond);\r\n    }\r\n\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        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 CivilTime.fromNanoseconds(timePlus(this[TIME], 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 CivilTime.fromNanoseconds(timePlus(this[TIME], -hours, -minutes, -seconds, -milliseconds, -nanoseconds));\r\n    }\r\n\r\n    with(components: Components<TimeUnit> = {}) {\r\n        const {\r\n            hour = this.hour,\r\n            minute = this.minute,\r\n            second = this.second,\r\n            millisecond = this.millisecond,\r\n            nanosecond = this.nanosecond\r\n        } = components;\r\n        return new CivilTime(hour, minute, second, millisecond, nanosecond);\r\n    }\r\n\r\n    withDate(date: CivilDate) {\r\n        if (!(date instanceof CivilDate)) throw new TypeError(\"CivilDate expected: date\");\r\n        return CivilDateTime.from(date, this);\r\n    }\r\n\r\n    withOffset(offset: ZoneOffset) {\r\n        if (!(offset instanceof ZoneOffset)) throw new TypeError(\"ZoneOffset expected: offset\");\r\n        return new OffsetTime(offset, this.hour, this.minute, this.second, this.millisecond, this.nanosecond);\r\n    }\r\n\r\n    until(other: CivilTime): Duration {\r\n        if (!(other instanceof CivilTime)) throw new TypeError(\"CivilTime expected: other\");\r\n        return new Duration(timeDiff(this[TIME], other[TIME]));\r\n    }\r\n\r\n    since(other: CivilTime): Duration {\r\n        if (!(other instanceof CivilTime)) throw new TypeError(\"CivilTime expected: other\");\r\n        return other.until(this);\r\n    }\r\n\r\n    toString() {\r\n        return `${D2(this.hour)}:${D2(this.minute)}:${D2(this.second)}.${D3(this.millisecond)}${D6(this.nanosecond)}`;\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    equals(other: CivilTime) {\r\n        return other !== null\r\n            && other !== undefined\r\n            && this[TIME] === other[TIME];\r\n    }\r\n\r\n    compareTo(other: CivilTime): number {\r\n        return compareBigInts(this[TIME], other[TIME]);\r\n    }\r\n\r\n    /**\r\n     * Creates a CivilTime from the provided time components.\r\n     */\r\n    static fromTime(hour: number, minute: number, second = 0, millisecond = 0, nanosecond = 0) {\r\n        return new CivilTime(hour, minute, second, millisecond, nanosecond);\r\n    }\r\n\r\n    /**\r\n     * Creates a CivilTime from the number of milliseconds since the start of the day.\r\n     */\r\n    static fromMilliseconds(milliseconds: number, nanosecond = 0) {\r\n        if (!isInt(milliseconds) || milliseconds < 0) throw new RangeError(`The value ${milliseconds} is not valid for the number of milliseconds.`);\r\n        if (!isInt(nanosecond) || nanosecond < 0 || nanosecond > 1e6) throw new RangeError(`The value ${nanosecond} is not a valid nanosecond.`);\r\n        return CivilTime.fromNanoseconds(getTime(0, 0, 0, milliseconds, nanosecond));\r\n    }\r\n\r\n    /**\r\n     * Creates a CivilTime from the number of nanoseconds since the start of the day.\r\n     */\r\n    static fromNanoseconds(nanoseconds: bigint): CivilTime {\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(CivilTime.prototype, { [TIME]: { value: nanoseconds } });\r\n    }\r\n\r\n    static fromString(text: string) {\r\n        const normalText = normalizeString(text);\r\n        const match = timeExtendedRegExp.exec(normalText) || timeBasicRegExp.exec(normalText);\r\n        if (match) {\r\n            const { hour, minute, second, millisecond = \"\", nanosecond = \"\" } = match.groups!;\r\n            return new CivilTime(+hour, +minute, +second, +millisecond.padEnd(3, \"0\"), +nanosecond.padEnd(6, \"0\"));\r\n        }\r\n\r\n        throw new Error(`Invalid time string '${text}'.`);\r\n    }\r\n\r\n    static now(clock: Clock) {\r\n        return clock.currentInstant().withZone(clock.zone).toCivilTime();\r\n    }\r\n\r\n\r\n\r\n    [Equatable.equals](other: unknown) {\r\n        return other instanceof CivilTime\r\n            && this.equals(other);\r\n    }\r\n\r\n    [Equatable.hash]() {\r\n        let hc = CIVILTIME_HASH_SEED;\r\n        hc = ((hc << 7) | (hc >>> 25)) ^ Equaler.defaultEqualer.hash(this[TIME]);\r\n        return hc;\r\n    }\r\n\r\n    [Comparable.compareTo](other: unknown) {\r\n        if (!(other instanceof CivilTime)) throw new TypeError();\r\n        return this.compareTo(other);\r\n    }\r\n}\r\n\r\nObject.defineProperty(CivilTime.prototype, Symbol.toStringTag, {\r\n    writable: true,\r\n    configurable: true,\r\n    value: \"CivilTime\"\r\n});"],"sourceRoot":""}