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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":"CivilDateTime.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, compareNumbers, compareBigInts, normalizeString, CIVILDATETIME_HASH_SEED } from './internal/core';\r\nimport { getDaysInMonth, getDate, getDatePart, getWeeksInYear, getCalendarDateFromWeekDate, getDaysInYear, getCalendarDateFromOrdinalDate, DatePart } from './internal/date';\r\nimport { getTime, getTimePart, TimePart, NANOSECONDS_PER_DAY } from './internal/time';\r\nimport { getInstant, getDateOfInstant, getTimeOfInstant } from './internal/instant';\r\nimport { dateTimeDiff, dateTimePlus } from './internal/math';\r\nimport { DATE, TIME } from './internal/symbols';\r\nimport { EPOCH_DAYS, NANOS_OF_DAY } from './internal/types';\r\nimport { DATETIME_EXTENDED, DATETIME_BASIC } from './internal/patterns';\r\nimport { Temporal, Components, DateDelta, TimeDelta, DateUnit, TimeUnit } from './types';\r\nimport { Zone, ZoneOffset } from './Zone';\r\nimport { Clock } from './Clock';\r\nimport { CivilDate } from './CivilDate';\r\nimport { CivilTime } from './CivilTime';\r\nimport { OffsetDateTime } from './OffsetDateTime';\r\nimport { Instant } from './Instant';\r\nimport { Duration } from './Duration';\r\nimport { Equatable, Comparable, Equaler } from '@esfx/equatable';\r\n\r\nconst dateTimeExtendedRegExp = new RegExp(R`^${DATETIME_EXTENDED}$`);\r\nconst dateTimeBasicRegExp = new RegExp(R`^${DATETIME_BASIC}$`);\r\n\r\nexport class CivilDateTime implements Temporal<CivilDateTime>, Equatable, Comparable {\r\n    /* @internal */ private [DATE]: EPOCH_DAYS;\r\n    /* @internal */ private [TIME]: NANOS_OF_DAY;\r\n\r\n    constructor(year: number, month: number, day: number, hour: number, minute: number, second: number = 0, millisecond: number = 0, nanosecond: number = 0) {\r\n        if (!isInt(year)) throw new RangeError(`The value ${year} is not a valid year.`);\r\n        if (!isInt(month) || month < 1 || month > 12) throw new RangeError(`The value ${month} is not a valid month.`);\r\n        if (!isInt(day) || day < 1 || day > getDaysInMonth(year, month)) throw new RangeError(`The value ${day} is not a valid day.`);\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[DATE] = getDate(year, month, day);\r\n        this[TIME] = getTime(hour, minute, second, millisecond, nanosecond);\r\n    }\r\n\r\n    get year() { return getDatePart(this[DATE], DatePart.year); }\r\n    get month() { return getDatePart(this[DATE], DatePart.month); }\r\n    get day() { return getDatePart(this[DATE], DatePart.day); }\r\n    get dayOfYear() { return getDatePart(this[DATE], DatePart.dayOfYear); }\r\n    get dayOfWeek() { return getDatePart(this[DATE], DatePart.dayOfWeek); }\r\n    get weekOfYear() { return getDatePart(this[DATE], DatePart.weekOfYear); }\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<DateDelta | TimeDelta> = {}) {\r\n        const { years = 0, months = 0, days = 0, hours = 0, minutes = 0, seconds = 0, milliseconds = 0, nanoseconds = 0 } = deltas;\r\n        if (!isInt(years)) throw new RangeError(`The value ${years} is not valid for 'years' as it is not an integer.`);\r\n        if (!isInt(months)) throw new RangeError(`The value ${months} is not valid for 'months' as it is not an integer.`);\r\n        if (!isInt(days)) throw new RangeError(`The value ${days} is not valid for 'days' as it is not an integer.`);\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        const instant = dateTimePlus(this[DATE], this[TIME], years, months, days, hours, minutes, seconds, milliseconds, nanoseconds);\r\n        return CivilDateTime.fromDayOfEpoch(getDateOfInstant(instant), getTimeOfInstant(instant));\r\n    }\r\n\r\n    minus(deltas: Components<DateDelta | TimeDelta> = {}) {\r\n        const { years = 0, months = 0, days = 0, hours = 0, minutes = 0, seconds = 0, milliseconds = 0, nanoseconds = 0 } = deltas;\r\n        if (!isInt(years)) throw new RangeError(`The value ${years} is not valid for 'years' as it is not an integer.`);\r\n        if (!isInt(months)) throw new RangeError(`The value ${months} is not valid for 'months' as it is not an integer.`);\r\n        if (!isInt(days)) throw new RangeError(`The value ${days} is not valid for 'days' as it is not an integer.`);\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        const instant = dateTimePlus(this[DATE], this[TIME], -years, -months, -days, -hours, -minutes, -seconds, -milliseconds, -nanoseconds);\r\n        return CivilDateTime.fromDayOfEpoch(getDateOfInstant(instant), getTimeOfInstant(instant));\r\n    }\r\n\r\n    with(components: Components<DateUnit | TimeUnit> = {}) {\r\n        const {\r\n            year = this.year,\r\n            month = this.month,\r\n            day = this.day,\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 CivilDateTime(year, month, day, hour, minute, second, millisecond, nanosecond);\r\n    }\r\n\r\n    withOffset(offset: ZoneOffset) {\r\n        return new OffsetDateTime(\r\n            offset,\r\n            this.year,\r\n            this.month,\r\n            this.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    withZone(zone: Zone | string) {\r\n        return this\r\n            .toInstant()\r\n            .withZone(Zone.UTC)\r\n            .withZoneSameLocal(zone);\r\n    }\r\n\r\n    until(other: CivilDateTime) {\r\n        if (!(other instanceof CivilDateTime)) throw new TypeError(\"CivilDateTime expected: other\");\r\n        return new Duration(dateTimeDiff(this[DATE], this[TIME], other[DATE], other[TIME]));\r\n    }\r\n\r\n    since(other: CivilDateTime) {\r\n        if (!(other instanceof CivilDateTime)) throw new TypeError(\"CivilDateTime expected: other\");\r\n        return other.until(this);\r\n    }\r\n\r\n    toCivilDate() {\r\n        return CivilDate.fromDayOfEpoch(this[DATE]);\r\n    }\r\n\r\n    toCivilTime() {\r\n        return CivilTime.fromNanoseconds(this[TIME]);\r\n    }\r\n\r\n    toInstant() {\r\n        return new Instant(getInstant(this[DATE], this[TIME]));\r\n    }\r\n\r\n    toCalendarDateTimeString() {\r\n        return `${this.toCivilDate().toCalendarDateString()}T${this.toCivilTime().toString()}`;\r\n    }\r\n\r\n    toWeekDateTimeString() {\r\n        return `${this.toCivilDate().toWeekDateString()}T${this.toCivilTime().toString()}`;\r\n    }\r\n\r\n    toOrdinalDateTimeString() {\r\n        return `${this.toCivilDate().toOrdinalDateString()}T${this.toCivilTime().toString()}`;\r\n    }\r\n\r\n    toString() {\r\n        return this.toCalendarDateTimeString();\r\n    }\r\n\r\n    toISOString() {\r\n        return this.toCalendarDateTimeString();\r\n    }\r\n\r\n    toJSON() {\r\n        return this.toCalendarDateTimeString();\r\n    }\r\n\r\n    equals(other: CivilDateTime) {\r\n        return other !== null\r\n            && other !== undefined\r\n            && this[DATE] === other[DATE]\r\n            && this[TIME] === other[TIME];\r\n    }\r\n\r\n    compareTo(other: CivilDateTime): number {\r\n        return compareNumbers(this[DATE], other[DATE])\r\n            || compareBigInts(this[TIME], other[TIME]);\r\n    }\r\n\r\n    static from(date: CivilDate, time: CivilTime): CivilDateTime {\r\n        return CivilDateTime.fromDayOfEpoch(date[DATE], time[TIME]);\r\n    }\r\n\r\n    static fromDayOfEpoch(days: number, nanoseconds = 0n): CivilDateTime {\r\n        if (!isInt(days)) throw new RangeError(`The value ${days} is not valid for the number of days.`);\r\n        if (nanoseconds < 0 || nanoseconds > NANOSECONDS_PER_DAY) throw new RangeError(`The value ${nanoseconds} is not valid for the number of nanoseconds since the start of the day.`);\r\n        return Object.create(CivilDateTime.prototype, {\r\n            [DATE]: { value: days },\r\n            [TIME]: { value: nanoseconds }\r\n        });\r\n    }\r\n\r\n    static fromCalendarDateTime(year: number, month: number, day: number, hour: number, minute: number, second: number = 0, millisecond: number = 0, nanosecond: number = 0) {\r\n        return new CivilDateTime(year, month, day, hour, minute, second, millisecond, nanosecond);\r\n    }\r\n\r\n    static fromWeekDateTime(year: number, weekOfYear: number, dayOfWeek: number, hour: number, minute: number, second: number = 0, millisecond: number = 0, nanosecond: number = 0) {\r\n        if (!isInt(year)) throw new RangeError(`The value ${year} is not a valid year.`);\r\n        if (!isInt(weekOfYear) || weekOfYear < 1 || weekOfYear > getWeeksInYear(year)) throw new RangeError(`The value ${weekOfYear} is not a valid week for the year ${year}.`);\r\n        if (!isInt(dayOfWeek) || dayOfWeek < 1 || dayOfWeek > 7) throw new RangeError(`The value ${dayOfWeek} is not a valid day of the week.`);\r\n        const components = getCalendarDateFromWeekDate(year, weekOfYear, dayOfWeek);\r\n        return CivilDateTime.fromCalendarDateTime(\r\n            components.year,\r\n            components.month,\r\n            components.day,\r\n            hour,\r\n            minute,\r\n            second,\r\n            millisecond,\r\n            nanosecond);\r\n    }\r\n\r\n    static fromOrdinalDateTime(year: number, dayOfYear: number, hour: number, minute: number, second: number = 0, millisecond: number = 0, nanosecond: number = 0) {\r\n        if (!isInt(year)) throw new RangeError(`The value ${year} is not a valid year.`);\r\n        if (!isInt(dayOfYear) || dayOfYear < 1 || dayOfYear > getDaysInYear(year)) throw new RangeError(`The value ${dayOfYear} is not a valid day for the year ${year}.`);\r\n        const components = getCalendarDateFromOrdinalDate(year, dayOfYear);\r\n        return CivilDateTime.fromCalendarDateTime(\r\n            components.year,\r\n            components.month,\r\n            components.day,\r\n            hour,\r\n            minute,\r\n            second,\r\n            millisecond,\r\n            nanosecond);\r\n    }\r\n\r\n    static fromString(text: string) {\r\n        const normalText = normalizeString(text);\r\n        const match = dateTimeExtendedRegExp.exec(normalText) || dateTimeBasicRegExp.exec(normalText);\r\n        if (match) {\r\n            const { year, month, day, weekOfYear, dayOfWeek, dayOfYear, hour, minute, second, millisecond = \"\", nanosecond = \"\" } = match.groups!;\r\n            if (year && month && day) return CivilDateTime.fromCalendarDateTime(+year, +month, +day, +hour, +minute, +second, +millisecond.padEnd(3, \"0\"), +nanosecond.padEnd(6, \"0\"));\r\n            if (year && weekOfYear && dayOfWeek) return CivilDateTime.fromWeekDateTime(+year, +weekOfYear, +dayOfWeek, +hour, +minute, +second, +millisecond.padEnd(3, \"0\"), +nanosecond.padEnd(6, \"0\"));\r\n            if (year && dayOfYear) return CivilDateTime.fromOrdinalDateTime(+year, +dayOfYear, +hour, +minute, +second, +millisecond.padEnd(3, \"0\"), +nanosecond.padEnd(6, \"0\"));\r\n        }\r\n\r\n        throw new SyntaxError(`Invalid date-time string '${text}'`);\r\n    }\r\n\r\n    static now(clock: Clock) {\r\n        return clock.currentInstant().withZone(clock.zone).toCivilDateTime();\r\n    }\r\n\r\n    [Equatable.equals](other: unknown) {\r\n        return other instanceof CivilDateTime\r\n            && this.equals(other);\r\n    }\r\n\r\n    [Equatable.hash]() {\r\n        let hc = CIVILDATETIME_HASH_SEED;\r\n        hc = ((hc << 7) | (hc >>> 25)) ^ Equaler.defaultEqualer.hash(this[DATE]);\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 CivilDateTime)) throw new TypeError();\r\n        return this.compareTo(other);\r\n    }\r\n}\r\n\r\nObject.defineProperty(CivilDateTime.prototype, Symbol.toStringTag, {\r\n    writable: true,\r\n    configurable: true,\r\n    value: \"CivilDateTime\"\r\n});"],"sourceRoot":""}