@intech-software/chronera 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +3 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/operations/business-days.d.ts +27 -0
- package/dist/operations/business-days.js +93 -0
- package/dist/operations/business-days.js.map +1 -0
- package/dist/operations/time-convenience.d.ts +44 -0
- package/dist/operations/time-convenience.js +162 -0
- package/dist/operations/time-convenience.js.map +1 -0
- package/dist/public-types.d.ts +1 -0
- package/dist/public-types.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export { createChronera } from "./create-chronera.js";
|
|
2
2
|
export { compareInstants, compareLocalDates, sameAbsoluteDate, sameCalendarDate, } from "./operations/compare.js";
|
|
3
3
|
export { getAbsoluteDay, isBefore, isAfter, isEqual, isSameDay, isBetween, isToday, addDays, subtractDays, addMonths, subtractMonths, addYears, subtractYears, diffInDays, startOfMonth, endOfMonth, startOfYear, endOfYear, } from "./operations/convenience.js";
|
|
4
|
+
export { startOfDay, endOfDay, isPast, isFuture, addHours, subtractHours, addMinutes, subtractMinutes, addSeconds, subtractSeconds, } from "./operations/time-convenience.js";
|
|
5
|
+
export { isWeekend, isWeekday, addBusinessDays, subtractBusinessDays, diffInBusinessDays, } from "./operations/business-days.js";
|
|
4
6
|
export { convertCalendarDate } from "./operations/convert-calendar-date.js";
|
|
5
7
|
export { daysInMonth, getCalendarCapabilities, isLeapYear, isValidCalendarDate, } from "./operations/validate.js";
|
|
6
8
|
export { getIsoWeek, formatIsoWeek } from "./operations/iso-week.js";
|
|
@@ -17,4 +19,4 @@ export { localTime } from "./core/local-time.js";
|
|
|
17
19
|
export { localDateTime } from "./core/local-date-time.js";
|
|
18
20
|
export { dateRange } from "./core/range.js";
|
|
19
21
|
export { ChroneraError, ChroneraParseError, ChroneraRangeError, ChroneraUnsupportedError, } from "./errors/index.js";
|
|
20
|
-
export type { BuiltInCalendarId, CalendarPlugin, CalendarCapabilities, CalendarConversionMetadata, CalendarConversionResult, CalendarDate, CalendarId, ChroneraErrorCode, ChroneraConfig, ChroneraInstance, ChroneraIssue, Comparison, ConvertCalendarOptions, DateOrCalendarDate, DateRange, DayOfYearFields, Duration, EraId, FiscalFields, FiscalOptions, FormatDateBaseOptions, FormatDateInput, FormatDateOptions, FormatDateRangeOptions, FormatDateTimeOptions, FormatRelativeOptions, FormatTimeOptions, Instant, IntervalInclusivity, IsoWeekFields, LocalDate, LocalDateTime, LocalTime, LocaleId, MonthCode, NumberingSystemId, PatternFormatOptions, ParseInstantOptions, ParseLocalDateOptions, PresetName, QuarterNumber, ResolvedChroneraOptions, Rfc2822Options, RuntimeCapabilities, SafeParseResult, TimeZoneId, ZonedDateTime, } from "./public-types.js";
|
|
22
|
+
export type { BuiltInCalendarId, CalendarPlugin, CalendarCapabilities, CalendarConversionMetadata, CalendarConversionResult, CalendarDate, CalendarId, ChroneraErrorCode, ChroneraConfig, ChroneraInstance, ChroneraIssue, Comparison, ConvertCalendarOptions, DateOrCalendarDate, DateRange, DayOfYearFields, Duration, EraId, FiscalFields, FiscalOptions, FormatDateBaseOptions, FormatDateInput, FormatDateOptions, FormatDateRangeOptions, FormatDateTimeOptions, FormatRelativeOptions, FormatTimeOptions, Instant, IntervalInclusivity, IsoWeekFields, LocalDate, LocalDateTime, LocalTime, LocaleId, MonthCode, NumberingSystemId, PatternFormatOptions, ParseInstantOptions, ParseLocalDateOptions, PresetName, QuarterNumber, ResolvedChroneraOptions, Rfc2822Options, RuntimeCapabilities, SafeParseResult, TimeZoneId, TimeOrDateTimeOrInstant, ZonedDateTime, } from "./public-types.js";
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export { createChronera } from "./create-chronera.js";
|
|
2
2
|
export { compareInstants, compareLocalDates, sameAbsoluteDate, sameCalendarDate, } from "./operations/compare.js";
|
|
3
3
|
export { getAbsoluteDay, isBefore, isAfter, isEqual, isSameDay, isBetween, isToday, addDays, subtractDays, addMonths, subtractMonths, addYears, subtractYears, diffInDays, startOfMonth, endOfMonth, startOfYear, endOfYear, } from "./operations/convenience.js";
|
|
4
|
+
export { startOfDay, endOfDay, isPast, isFuture, addHours, subtractHours, addMinutes, subtractMinutes, addSeconds, subtractSeconds, } from "./operations/time-convenience.js";
|
|
5
|
+
export { isWeekend, isWeekday, addBusinessDays, subtractBusinessDays, diffInBusinessDays, } from "./operations/business-days.js";
|
|
4
6
|
export { convertCalendarDate } from "./operations/convert-calendar-date.js";
|
|
5
7
|
export { daysInMonth, getCalendarCapabilities, isLeapYear, isValidCalendarDate, } from "./operations/validate.js";
|
|
6
8
|
export { getIsoWeek, formatIsoWeek } from "./operations/iso-week.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EACL,cAAc,EACd,QAAQ,EACR,OAAO,EACP,OAAO,EACP,SAAS,EACT,SAAS,EACT,OAAO,EACP,OAAO,EACP,YAAY,EACZ,SAAS,EACT,cAAc,EACd,QAAQ,EACR,aAAa,EACb,UAAU,EACV,YAAY,EACZ,UAAU,EACV,WAAW,EACX,SAAS,GACV,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uCAAuC,CAAC;AAE5E,OAAO,EACL,WAAW,EACX,uBAAuB,EACvB,UAAU,EACV,mBAAmB,GACpB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAErE,OAAO,EACL,YAAY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,CAAC;AAE5C,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,kBAAkB,EAClB,wBAAwB,GACzB,MAAM,mBAAmB,CAAC","sourcesContent":["export { createChronera } from \"./create-chronera.js\";\n\nexport {\n compareInstants,\n compareLocalDates,\n sameAbsoluteDate,\n sameCalendarDate,\n} from \"./operations/compare.js\";\n\nexport {\n getAbsoluteDay,\n isBefore,\n isAfter,\n isEqual,\n isSameDay,\n isBetween,\n isToday,\n addDays,\n subtractDays,\n addMonths,\n subtractMonths,\n addYears,\n subtractYears,\n diffInDays,\n startOfMonth,\n endOfMonth,\n startOfYear,\n endOfYear,\n} from \"./operations/convenience.js\";\n\nexport { convertCalendarDate } from \"./operations/convert-calendar-date.js\";\n\nexport {\n daysInMonth,\n getCalendarCapabilities,\n isLeapYear,\n isValidCalendarDate,\n} from \"./operations/validate.js\";\n\nexport { getIsoWeek, formatIsoWeek } from \"./operations/iso-week.js\";\n\nexport {\n getDayOfYear,\n getDayOfYearWithRegistry,\n formatOrdinalDate,\n} from \"./operations/day-of-year.js\";\n\nexport {\n toJulianDayNumber,\n toModifiedJulianDay,\n localDateFromJulianDayNumber,\n localDateFromModifiedJulianDay,\n} from \"./operations/julian-day.js\";\n\nexport { getQuarter, getFiscalYear } from \"./operations/fiscal.js\";\n\nexport {\n formatDate,\n formatDateRange,\n formatDateTime,\n formatRelative,\n formatTime,\n formatWithPattern,\n formatRfc2822,\n formatJapaneseOfficialPreset,\n formatJapaneseOfficialWithWeekdayPreset,\n formatTaiwanOfficialPreset,\n formatThaiOfficialPreset,\n formatArabicGregorianPreset,\n formatArabicHijriPreset,\n formatChineseShortPreset,\n formatChineseStandardPreset,\n formatChineseWithWeekdayPreset,\n formatFrenchLongPreset,\n formatFrenchStandardPreset,\n formatFrenchWithWeekdayPreset,\n formatGermanDinStandardPreset,\n formatGermanLongPreset,\n formatGermanWithWeekdayPreset,\n formatJapaneseEraShortPreset,\n formatJapaneseSeirekiPreset,\n formatSpanishLongPreset,\n formatSpanishStandardPreset,\n formatSpanishWithWeekdayPreset,\n formatThaiShortDatePreset,\n formatThaiSlashDatePreset,\n formatUkLongPreset,\n formatUkStandardPreset,\n formatUkWithWeekdayPreset,\n formatUsLongPreset,\n formatUsStandardPreset,\n formatUsWithWeekdayPreset,\n} from \"./format/index.js\";\n\nexport {\n parseInstant,\n parseLocalDate,\n safeParseInstant,\n safeParseLocalDate,\n} from \"./parse/index.js\";\n\nexport {\n instantFromDate,\n instantFromEpochMilliseconds,\n instantFromEpochSeconds,\n} from \"./core/instant.js\";\n\nexport { getRuntimeCapabilities } from \"./runtime/capabilities.js\";\n\nexport { calendarDate } from \"./core/calendar-date.js\";\n\nexport { localDate } from \"./core/local-date.js\";\n\nexport { localTime } from \"./core/local-time.js\";\n\nexport { localDateTime } from \"./core/local-date-time.js\";\n\nexport { dateRange } from \"./core/range.js\";\n\nexport {\n ChroneraError,\n ChroneraParseError,\n ChroneraRangeError,\n ChroneraUnsupportedError,\n} from \"./errors/index.js\";\n\nexport type {\n BuiltInCalendarId,\n CalendarPlugin,\n CalendarCapabilities,\n CalendarConversionMetadata,\n CalendarConversionResult,\n CalendarDate,\n CalendarId,\n ChroneraErrorCode,\n ChroneraConfig,\n ChroneraInstance,\n ChroneraIssue,\n Comparison,\n ConvertCalendarOptions,\n DateOrCalendarDate,\n DateRange,\n DayOfYearFields,\n Duration,\n EraId,\n FiscalFields,\n FiscalOptions,\n FormatDateBaseOptions,\n FormatDateInput,\n FormatDateOptions,\n FormatDateRangeOptions,\n FormatDateTimeOptions,\n FormatRelativeOptions,\n FormatTimeOptions,\n Instant,\n IntervalInclusivity,\n IsoWeekFields,\n LocalDate,\n LocalDateTime,\n LocalTime,\n LocaleId,\n MonthCode,\n NumberingSystemId,\n PatternFormatOptions,\n ParseInstantOptions,\n ParseLocalDateOptions,\n PresetName,\n QuarterNumber,\n ResolvedChroneraOptions,\n Rfc2822Options,\n RuntimeCapabilities,\n SafeParseResult,\n TimeZoneId,\n ZonedDateTime,\n} from \"./public-types.js\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EACL,cAAc,EACd,QAAQ,EACR,OAAO,EACP,OAAO,EACP,SAAS,EACT,SAAS,EACT,OAAO,EACP,OAAO,EACP,YAAY,EACZ,SAAS,EACT,cAAc,EACd,QAAQ,EACR,aAAa,EACb,UAAU,EACV,YAAY,EACZ,UAAU,EACV,WAAW,EACX,SAAS,GACV,MAAM,6BAA6B,CAAC;AAErC,OAAO,EACL,UAAU,EACV,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,aAAa,EACb,UAAU,EACV,eAAe,EACf,UAAU,EACV,eAAe,GAChB,MAAM,kCAAkC,CAAC;AAE1C,OAAO,EACL,SAAS,EACT,SAAS,EACT,eAAe,EACf,oBAAoB,EACpB,kBAAkB,GACnB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uCAAuC,CAAC;AAE5E,OAAO,EACL,WAAW,EACX,uBAAuB,EACvB,UAAU,EACV,mBAAmB,GACpB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAErE,OAAO,EACL,YAAY,EACZ,wBAAwB,EACxB,iBAAiB,GAClB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,4BAA4B,EAC5B,8BAA8B,GAC/B,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEnE,OAAO,EACL,UAAU,EACV,eAAe,EACf,cAAc,EACd,cAAc,EACd,UAAU,EACV,iBAAiB,EACjB,aAAa,EACb,4BAA4B,EAC5B,uCAAuC,EACvC,0BAA0B,EAC1B,wBAAwB,EACxB,2BAA2B,EAC3B,uBAAuB,EACvB,wBAAwB,EACxB,2BAA2B,EAC3B,8BAA8B,EAC9B,sBAAsB,EACtB,0BAA0B,EAC1B,6BAA6B,EAC7B,6BAA6B,EAC7B,sBAAsB,EACtB,6BAA6B,EAC7B,4BAA4B,EAC5B,2BAA2B,EAC3B,uBAAuB,EACvB,2BAA2B,EAC3B,8BAA8B,EAC9B,yBAAyB,EACzB,yBAAyB,EACzB,kBAAkB,EAClB,sBAAsB,EACtB,yBAAyB,EACzB,kBAAkB,EAClB,sBAAsB,EACtB,yBAAyB,GAC1B,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACL,YAAY,EACZ,cAAc,EACd,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACL,eAAe,EACf,4BAA4B,EAC5B,uBAAuB,GACxB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAEnE,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE1D,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,kBAAkB,EAClB,wBAAwB,GACzB,MAAM,mBAAmB,CAAC","sourcesContent":["export { createChronera } from \"./create-chronera.js\";\n\nexport {\n compareInstants,\n compareLocalDates,\n sameAbsoluteDate,\n sameCalendarDate,\n} from \"./operations/compare.js\";\n\nexport {\n getAbsoluteDay,\n isBefore,\n isAfter,\n isEqual,\n isSameDay,\n isBetween,\n isToday,\n addDays,\n subtractDays,\n addMonths,\n subtractMonths,\n addYears,\n subtractYears,\n diffInDays,\n startOfMonth,\n endOfMonth,\n startOfYear,\n endOfYear,\n} from \"./operations/convenience.js\";\n\nexport {\n startOfDay,\n endOfDay,\n isPast,\n isFuture,\n addHours,\n subtractHours,\n addMinutes,\n subtractMinutes,\n addSeconds,\n subtractSeconds,\n} from \"./operations/time-convenience.js\";\n\nexport {\n isWeekend,\n isWeekday,\n addBusinessDays,\n subtractBusinessDays,\n diffInBusinessDays,\n} from \"./operations/business-days.js\";\n\nexport { convertCalendarDate } from \"./operations/convert-calendar-date.js\";\n\nexport {\n daysInMonth,\n getCalendarCapabilities,\n isLeapYear,\n isValidCalendarDate,\n} from \"./operations/validate.js\";\n\nexport { getIsoWeek, formatIsoWeek } from \"./operations/iso-week.js\";\n\nexport {\n getDayOfYear,\n getDayOfYearWithRegistry,\n formatOrdinalDate,\n} from \"./operations/day-of-year.js\";\n\nexport {\n toJulianDayNumber,\n toModifiedJulianDay,\n localDateFromJulianDayNumber,\n localDateFromModifiedJulianDay,\n} from \"./operations/julian-day.js\";\n\nexport { getQuarter, getFiscalYear } from \"./operations/fiscal.js\";\n\nexport {\n formatDate,\n formatDateRange,\n formatDateTime,\n formatRelative,\n formatTime,\n formatWithPattern,\n formatRfc2822,\n formatJapaneseOfficialPreset,\n formatJapaneseOfficialWithWeekdayPreset,\n formatTaiwanOfficialPreset,\n formatThaiOfficialPreset,\n formatArabicGregorianPreset,\n formatArabicHijriPreset,\n formatChineseShortPreset,\n formatChineseStandardPreset,\n formatChineseWithWeekdayPreset,\n formatFrenchLongPreset,\n formatFrenchStandardPreset,\n formatFrenchWithWeekdayPreset,\n formatGermanDinStandardPreset,\n formatGermanLongPreset,\n formatGermanWithWeekdayPreset,\n formatJapaneseEraShortPreset,\n formatJapaneseSeirekiPreset,\n formatSpanishLongPreset,\n formatSpanishStandardPreset,\n formatSpanishWithWeekdayPreset,\n formatThaiShortDatePreset,\n formatThaiSlashDatePreset,\n formatUkLongPreset,\n formatUkStandardPreset,\n formatUkWithWeekdayPreset,\n formatUsLongPreset,\n formatUsStandardPreset,\n formatUsWithWeekdayPreset,\n} from \"./format/index.js\";\n\nexport {\n parseInstant,\n parseLocalDate,\n safeParseInstant,\n safeParseLocalDate,\n} from \"./parse/index.js\";\n\nexport {\n instantFromDate,\n instantFromEpochMilliseconds,\n instantFromEpochSeconds,\n} from \"./core/instant.js\";\n\nexport { getRuntimeCapabilities } from \"./runtime/capabilities.js\";\n\nexport { calendarDate } from \"./core/calendar-date.js\";\n\nexport { localDate } from \"./core/local-date.js\";\n\nexport { localTime } from \"./core/local-time.js\";\n\nexport { localDateTime } from \"./core/local-date-time.js\";\n\nexport { dateRange } from \"./core/range.js\";\n\nexport {\n ChroneraError,\n ChroneraParseError,\n ChroneraRangeError,\n ChroneraUnsupportedError,\n} from \"./errors/index.js\";\n\nexport type {\n BuiltInCalendarId,\n CalendarPlugin,\n CalendarCapabilities,\n CalendarConversionMetadata,\n CalendarConversionResult,\n CalendarDate,\n CalendarId,\n ChroneraErrorCode,\n ChroneraConfig,\n ChroneraInstance,\n ChroneraIssue,\n Comparison,\n ConvertCalendarOptions,\n DateOrCalendarDate,\n DateRange,\n DayOfYearFields,\n Duration,\n EraId,\n FiscalFields,\n FiscalOptions,\n FormatDateBaseOptions,\n FormatDateInput,\n FormatDateOptions,\n FormatDateRangeOptions,\n FormatDateTimeOptions,\n FormatRelativeOptions,\n FormatTimeOptions,\n Instant,\n IntervalInclusivity,\n IsoWeekFields,\n LocalDate,\n LocalDateTime,\n LocalTime,\n LocaleId,\n MonthCode,\n NumberingSystemId,\n PatternFormatOptions,\n ParseInstantOptions,\n ParseLocalDateOptions,\n PresetName,\n QuarterNumber,\n ResolvedChroneraOptions,\n Rfc2822Options,\n RuntimeCapabilities,\n SafeParseResult,\n TimeZoneId,\n TimeOrDateTimeOrInstant,\n ZonedDateTime,\n} from \"./public-types.js\";\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { DateOrCalendarDate } from "../public-types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Returns true if the specified date falls on a weekend (Saturday or Sunday).
|
|
4
|
+
* Works across all calendars (Gregorian, Thai Buddhist, Japanese, Hijri, etc.).
|
|
5
|
+
*/
|
|
6
|
+
export declare function isWeekend(date: DateOrCalendarDate): boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Returns true if the specified date falls on a weekday (Monday through Friday).
|
|
9
|
+
* Works across all calendars (Gregorian, Thai Buddhist, Japanese, Hijri, etc.).
|
|
10
|
+
*/
|
|
11
|
+
export declare function isWeekday(date: DateOrCalendarDate): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Adds business days to a LocalDate or CalendarDate, skipping Saturdays and Sundays.
|
|
14
|
+
* Supports positive, negative, and zero day additions.
|
|
15
|
+
* Uses O(1) mathematical week advancement for large intervals while preserving exact calendar semantics.
|
|
16
|
+
*/
|
|
17
|
+
export declare function addBusinessDays<T extends DateOrCalendarDate>(date: T, amount: number): T;
|
|
18
|
+
/**
|
|
19
|
+
* Subtracts business days from a LocalDate or CalendarDate, skipping weekends.
|
|
20
|
+
*/
|
|
21
|
+
export declare function subtractBusinessDays<T extends DateOrCalendarDate>(date: T, amount: number): T;
|
|
22
|
+
/**
|
|
23
|
+
* Returns the signed count of business days between two dates (left - right).
|
|
24
|
+
* Positive if left is after right, negative if left is before right, 0 if identical.
|
|
25
|
+
* Works across all calendar systems with O(1) mathematical week acceleration.
|
|
26
|
+
*/
|
|
27
|
+
export declare function diffInBusinessDays(left: DateOrCalendarDate, right: DateOrCalendarDate): number;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { getIsoDayOfWeek } from "../core/iso-week.js";
|
|
2
|
+
import { ChroneraError } from "../errors/errors.js";
|
|
3
|
+
import { addDays, getAbsoluteDay } from "./convenience.js";
|
|
4
|
+
/**
|
|
5
|
+
* Returns true if the specified date falls on a weekend (Saturday or Sunday).
|
|
6
|
+
* Works across all calendars (Gregorian, Thai Buddhist, Japanese, Hijri, etc.).
|
|
7
|
+
*/
|
|
8
|
+
export function isWeekend(date) {
|
|
9
|
+
const abs = getAbsoluteDay(date);
|
|
10
|
+
const dow = getIsoDayOfWeek(abs);
|
|
11
|
+
return dow === 6 || dow === 7;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Returns true if the specified date falls on a weekday (Monday through Friday).
|
|
15
|
+
* Works across all calendars (Gregorian, Thai Buddhist, Japanese, Hijri, etc.).
|
|
16
|
+
*/
|
|
17
|
+
export function isWeekday(date) {
|
|
18
|
+
return !isWeekend(date);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Adds business days to a LocalDate or CalendarDate, skipping Saturdays and Sundays.
|
|
22
|
+
* Supports positive, negative, and zero day additions.
|
|
23
|
+
* Uses O(1) mathematical week advancement for large intervals while preserving exact calendar semantics.
|
|
24
|
+
*/
|
|
25
|
+
export function addBusinessDays(date, amount) {
|
|
26
|
+
if (!Number.isFinite(amount)) {
|
|
27
|
+
throw new ChroneraError("CHRONERA_OUT_OF_RANGE", "Amount must be a finite integer.");
|
|
28
|
+
}
|
|
29
|
+
const intAmount = Math.trunc(amount);
|
|
30
|
+
if (intAmount === 0) {
|
|
31
|
+
return date;
|
|
32
|
+
}
|
|
33
|
+
const startAbs = getAbsoluteDay(date);
|
|
34
|
+
let currentAbs = startAbs;
|
|
35
|
+
let remaining = intAmount;
|
|
36
|
+
const step = remaining > 0 ? 1 : -1;
|
|
37
|
+
while (remaining !== 0) {
|
|
38
|
+
const currentDow = getIsoDayOfWeek(currentAbs);
|
|
39
|
+
if (currentDow !== 6 && currentDow !== 7 && Math.abs(remaining) >= 5) {
|
|
40
|
+
const fullWeeks = Math.trunc(remaining / 5);
|
|
41
|
+
currentAbs += fullWeeks * 7;
|
|
42
|
+
remaining %= 5;
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
currentAbs += step;
|
|
46
|
+
const dow = getIsoDayOfWeek(currentAbs);
|
|
47
|
+
if (dow !== 6 && dow !== 7) {
|
|
48
|
+
remaining -= step;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const deltaDays = currentAbs - startAbs;
|
|
53
|
+
return addDays(date, deltaDays);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Subtracts business days from a LocalDate or CalendarDate, skipping weekends.
|
|
57
|
+
*/
|
|
58
|
+
export function subtractBusinessDays(date, amount) {
|
|
59
|
+
return addBusinessDays(date, -amount);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Returns the signed count of business days between two dates (left - right).
|
|
63
|
+
* Positive if left is after right, negative if left is before right, 0 if identical.
|
|
64
|
+
* Works across all calendar systems with O(1) mathematical week acceleration.
|
|
65
|
+
*/
|
|
66
|
+
export function diffInBusinessDays(left, right) {
|
|
67
|
+
const absLeft = getAbsoluteDay(left);
|
|
68
|
+
const absRight = getAbsoluteDay(right);
|
|
69
|
+
if (absLeft === absRight) {
|
|
70
|
+
return 0;
|
|
71
|
+
}
|
|
72
|
+
if (absLeft < absRight) {
|
|
73
|
+
return -diffInBusinessDays(right, left);
|
|
74
|
+
}
|
|
75
|
+
let count = 0;
|
|
76
|
+
let current = absRight;
|
|
77
|
+
// O(1) acceleration: any consecutive 7 calendar days contains exactly 5 business days
|
|
78
|
+
const fullWeeks = Math.floor((absLeft - current) / 7);
|
|
79
|
+
if (fullWeeks > 0) {
|
|
80
|
+
count += fullWeeks * 5;
|
|
81
|
+
current += fullWeeks * 7;
|
|
82
|
+
}
|
|
83
|
+
// Step through remainder (at most 6 days)
|
|
84
|
+
while (current < absLeft) {
|
|
85
|
+
current++;
|
|
86
|
+
const dow = getIsoDayOfWeek(current);
|
|
87
|
+
if (dow !== 6 && dow !== 7) {
|
|
88
|
+
count++;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return count;
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=business-days.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"business-days.js","sourceRoot":"","sources":["../../src/operations/business-days.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAI3D;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAC,IAAwB;IAChD,MAAM,GAAG,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC;IACjC,MAAM,GAAG,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC;IACjC,OAAO,GAAG,KAAK,CAAC,IAAI,GAAG,KAAK,CAAC,CAAC;AAChC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAC,IAAwB;IAChD,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAC7B,IAAO,EACP,MAAc;IAEd,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QAC7B,MAAM,IAAI,aAAa,CACrB,uBAAuB,EACvB,kCAAkC,CACnC,CAAC;IACJ,CAAC;IAED,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACrC,IAAI,SAAS,KAAK,CAAC,EAAE,CAAC;QACpB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,QAAQ,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC;IACtC,IAAI,UAAU,GAAG,QAAQ,CAAC;IAC1B,IAAI,SAAS,GAAG,SAAS,CAAC;IAC1B,MAAM,IAAI,GAAG,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAEpC,OAAO,SAAS,KAAK,CAAC,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AC;IACd,IAAI,OAAO,GAAG,QAAQ,CAAC;IAEvB,sFAAsF;IACtF,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;IACtD,IAAI,SAAS,GAAG,CAAC,EAAE,CAAC;QAClB,KAAK,IAAI,SAAS,GAAG,CAAC,CAAC;QACvB,OAAO,IAAI,SAAS,GAAG,CAAC,CAAC;IAC3B,CAAC;IAED,0CAA0C;IAC1C,OAAO,OAAO,GAAG,OAAO,EAAE,CAAC;QACzB,OAAO,EAAE,CAAC;QACV,MAAM,GAAG,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC;QACrC,IAAI,GAAG,KAAK,CAAC,IAAI,GAAG,KAAK,CAAC,EAAE,CAAC;YAC3B,KAAK,EAAE,CAAC;QACV,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import { getIsoDayOfWeek } from \"../core/iso-week.js\";\nimport { ChroneraError } from \"../errors/errors.js\";\nimport { addDays, getAbsoluteDay } from \"./convenience.js\";\n\nimport type { DateOrCalendarDate } from \"../public-types.js\";\n\n/**\n * Returns true if the specified date falls on a weekend (Saturday or Sunday).\n * Works across all calendars (Gregorian, Thai Buddhist, Japanese, Hijri, etc.).\n */\nexport function isWeekend(date: DateOrCalendarDate): boolean {\n const abs = getAbsoluteDay(date);\n const dow = getIsoDayOfWeek(abs);\n return dow === 6 || dow === 7;\n}\n\n/**\n * Returns true if the specified date falls on a weekday (Monday through Friday).\n * Works across all calendars (Gregorian, Thai Buddhist, Japanese, Hijri, etc.).\n */\nexport function isWeekday(date: DateOrCalendarDate): boolean {\n return !isWeekend(date);\n}\n\n/**\n * Adds business days to a LocalDate or CalendarDate, skipping Saturdays and Sundays.\n * Supports positive, negative, and zero day additions.\n * Uses O(1) mathematical week advancement for large intervals while preserving exact calendar semantics.\n */\nexport function addBusinessDays<T extends DateOrCalendarDate>(\n date: T,\n amount: number,\n): T {\n if (!Number.isFinite(amount)) {\n throw new ChroneraError(\n \"CHRONERA_OUT_OF_RANGE\",\n \"Amount must be a finite integer.\",\n );\n }\n\n const intAmount = Math.trunc(amount);\n if (intAmount === 0) {\n return date;\n }\n\n const startAbs = getAbsoluteDay(date);\n let currentAbs = startAbs;\n let remaining = intAmount;\n const step = remaining > 0 ? 1 : -1;\n\n while (remaining !== 0) {\n const currentDow = getIsoDayOfWeek(currentAbs);\n if (currentDow !== 6 && currentDow !== 7 && Math.abs(remaining) >= 5) {\n const fullWeeks = Math.trunc(remaining / 5);\n currentAbs += fullWeeks * 7;\n remaining %= 5;\n } else {\n currentAbs += step;\n const dow = getIsoDayOfWeek(currentAbs);\n if (dow !== 6 && dow !== 7) {\n remaining -= step;\n }\n }\n }\n\n const deltaDays = currentAbs - startAbs;\n return addDays(date, deltaDays);\n}\n\n/**\n * Subtracts business days from a LocalDate or CalendarDate, skipping weekends.\n */\nexport function subtractBusinessDays<T extends DateOrCalendarDate>(\n date: T,\n amount: number,\n): T {\n return addBusinessDays(date, -amount);\n}\n\n/**\n * Returns the signed count of business days between two dates (left - right).\n * Positive if left is after right, negative if left is before right, 0 if identical.\n * Works across all calendar systems with O(1) mathematical week acceleration.\n */\nexport function diffInBusinessDays(\n left: DateOrCalendarDate,\n right: DateOrCalendarDate,\n): number {\n const absLeft = getAbsoluteDay(left);\n const absRight = getAbsoluteDay(right);\n\n if (absLeft === absRight) {\n return 0;\n }\n\n if (absLeft < absRight) {\n return -diffInBusinessDays(right, left);\n }\n\n let count = 0;\n let current = absRight;\n\n // O(1) acceleration: any consecutive 7 calendar days contains exactly 5 business days\n const fullWeeks = Math.floor((absLeft - current) / 7);\n if (fullWeeks > 0) {\n count += fullWeeks * 5;\n current += fullWeeks * 7;\n }\n\n // Step through remainder (at most 6 days)\n while (current < absLeft) {\n current++;\n const dow = getIsoDayOfWeek(current);\n if (dow !== 6 && dow !== 7) {\n count++;\n }\n }\n\n return count;\n}\n"]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { Instant, LocalDate, LocalDateTime, TimeOrDateTimeOrInstant } from "../public-types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Returns the start of the day (00:00:00.000) as a LocalDateTime.
|
|
4
|
+
* Accepts either a LocalDate or an existing LocalDateTime.
|
|
5
|
+
*/
|
|
6
|
+
export declare function startOfDay(input: LocalDate | LocalDateTime): LocalDateTime;
|
|
7
|
+
/**
|
|
8
|
+
* Returns the end of the day (23:59:59.999) as a LocalDateTime.
|
|
9
|
+
* Accepts either a LocalDate or an existing LocalDateTime.
|
|
10
|
+
*/
|
|
11
|
+
export declare function endOfDay(input: LocalDate | LocalDateTime): LocalDateTime;
|
|
12
|
+
/**
|
|
13
|
+
* Returns true if the specified Instant, Date, or epoch millisecond timestamp is in the past.
|
|
14
|
+
*/
|
|
15
|
+
export declare function isPast(target: Instant | Date | number): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Returns true if the specified Instant, Date, or epoch millisecond timestamp is in the future.
|
|
18
|
+
*/
|
|
19
|
+
export declare function isFuture(target: Instant | Date | number): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Adds hours to a LocalTime, LocalDateTime, or Instant.
|
|
22
|
+
* Accurately shifts calendar date when LocalDateTime rolls past midnight.
|
|
23
|
+
*/
|
|
24
|
+
export declare function addHours<T extends TimeOrDateTimeOrInstant>(target: T, amount: number): T;
|
|
25
|
+
/**
|
|
26
|
+
* Subtracts hours from a LocalTime, LocalDateTime, or Instant.
|
|
27
|
+
*/
|
|
28
|
+
export declare function subtractHours<T extends TimeOrDateTimeOrInstant>(target: T, amount: number): T;
|
|
29
|
+
/**
|
|
30
|
+
* Adds minutes to a LocalTime, LocalDateTime, or Instant.
|
|
31
|
+
*/
|
|
32
|
+
export declare function addMinutes<T extends TimeOrDateTimeOrInstant>(target: T, amount: number): T;
|
|
33
|
+
/**
|
|
34
|
+
* Subtracts minutes from a LocalTime, LocalDateTime, or Instant.
|
|
35
|
+
*/
|
|
36
|
+
export declare function subtractMinutes<T extends TimeOrDateTimeOrInstant>(target: T, amount: number): T;
|
|
37
|
+
/**
|
|
38
|
+
* Adds seconds to a LocalTime, LocalDateTime, or Instant.
|
|
39
|
+
*/
|
|
40
|
+
export declare function addSeconds<T extends TimeOrDateTimeOrInstant>(target: T, amount: number): T;
|
|
41
|
+
/**
|
|
42
|
+
* Subtracts seconds from a LocalTime, LocalDateTime, or Instant.
|
|
43
|
+
*/
|
|
44
|
+
export declare function subtractSeconds<T extends TimeOrDateTimeOrInstant>(target: T, amount: number): T;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { absoluteDayFromGregorianFields, gregorianFieldsFromAbsoluteDay, } from "../core/absolute-day.js";
|
|
2
|
+
import { ChroneraError } from "../errors/errors.js";
|
|
3
|
+
/**
|
|
4
|
+
* Returns the start of the day (00:00:00.000) as a LocalDateTime.
|
|
5
|
+
* Accepts either a LocalDate or an existing LocalDateTime.
|
|
6
|
+
*/
|
|
7
|
+
export function startOfDay(input) {
|
|
8
|
+
const date = input.kind === "local-date-time" ? input.date : input;
|
|
9
|
+
return {
|
|
10
|
+
kind: "local-date-time",
|
|
11
|
+
date,
|
|
12
|
+
time: {
|
|
13
|
+
kind: "local-time",
|
|
14
|
+
hour: 0,
|
|
15
|
+
minute: 0,
|
|
16
|
+
second: 0,
|
|
17
|
+
millisecond: 0,
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Returns the end of the day (23:59:59.999) as a LocalDateTime.
|
|
23
|
+
* Accepts either a LocalDate or an existing LocalDateTime.
|
|
24
|
+
*/
|
|
25
|
+
export function endOfDay(input) {
|
|
26
|
+
const date = input.kind === "local-date-time" ? input.date : input;
|
|
27
|
+
return {
|
|
28
|
+
kind: "local-date-time",
|
|
29
|
+
date,
|
|
30
|
+
time: {
|
|
31
|
+
kind: "local-time",
|
|
32
|
+
hour: 23,
|
|
33
|
+
minute: 59,
|
|
34
|
+
second: 59,
|
|
35
|
+
millisecond: 999,
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Returns true if the specified Instant, Date, or epoch millisecond timestamp is in the past.
|
|
41
|
+
*/
|
|
42
|
+
export function isPast(target) {
|
|
43
|
+
const epochMs = typeof target === "number"
|
|
44
|
+
? target
|
|
45
|
+
: target instanceof Date
|
|
46
|
+
? target.getTime()
|
|
47
|
+
: target.epochMilliseconds;
|
|
48
|
+
return epochMs < Date.now();
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Returns true if the specified Instant, Date, or epoch millisecond timestamp is in the future.
|
|
52
|
+
*/
|
|
53
|
+
export function isFuture(target) {
|
|
54
|
+
const epochMs = typeof target === "number"
|
|
55
|
+
? target
|
|
56
|
+
: target instanceof Date
|
|
57
|
+
? target.getTime()
|
|
58
|
+
: target.epochMilliseconds;
|
|
59
|
+
return epochMs > Date.now();
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Helper to add millisecond offset to LocalTime, LocalDateTime, or Instant.
|
|
63
|
+
*/
|
|
64
|
+
function addMillisecondsInternal(target, deltaMs) {
|
|
65
|
+
if (target.kind === "instant") {
|
|
66
|
+
return {
|
|
67
|
+
kind: "instant",
|
|
68
|
+
epochMilliseconds: target.epochMilliseconds + deltaMs,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
if (target.kind === "local-time") {
|
|
72
|
+
const totalMs = target.hour * 3_600_000 +
|
|
73
|
+
target.minute * 60_000 +
|
|
74
|
+
target.second * 1_000 +
|
|
75
|
+
target.millisecond +
|
|
76
|
+
deltaMs;
|
|
77
|
+
const dayMs = 86_400_000;
|
|
78
|
+
const normalizedMs = ((totalMs % dayMs) + dayMs) % dayMs;
|
|
79
|
+
const hour = Math.floor(normalizedMs / 3_600_000);
|
|
80
|
+
const minute = Math.floor((normalizedMs % 3_600_000) / 60_000);
|
|
81
|
+
const second = Math.floor((normalizedMs % 60_000) / 1_000);
|
|
82
|
+
const millisecond = normalizedMs % 1_000;
|
|
83
|
+
return {
|
|
84
|
+
kind: "local-time",
|
|
85
|
+
hour,
|
|
86
|
+
minute,
|
|
87
|
+
second,
|
|
88
|
+
millisecond,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
if (target.kind === "local-date-time") {
|
|
92
|
+
const currentAbsDay = absoluteDayFromGregorianFields(target.date.year, target.date.month, target.date.day);
|
|
93
|
+
const currentDayMs = target.time.hour * 3_600_000 +
|
|
94
|
+
target.time.minute * 60_000 +
|
|
95
|
+
target.time.second * 1_000 +
|
|
96
|
+
target.time.millisecond;
|
|
97
|
+
const totalMs = currentDayMs + deltaMs;
|
|
98
|
+
const dayShift = Math.floor(totalMs / 86_400_000);
|
|
99
|
+
const timeMs = ((totalMs % 86_400_000) + 86_400_000) % 86_400_000;
|
|
100
|
+
const newAbsDay = currentAbsDay + dayShift;
|
|
101
|
+
const newDateFields = gregorianFieldsFromAbsoluteDay(newAbsDay);
|
|
102
|
+
const hour = Math.floor(timeMs / 3_600_000);
|
|
103
|
+
const minute = Math.floor((timeMs % 3_600_000) / 60_000);
|
|
104
|
+
const second = Math.floor((timeMs % 60_000) / 1_000);
|
|
105
|
+
const millisecond = timeMs % 1_000;
|
|
106
|
+
return {
|
|
107
|
+
kind: "local-date-time",
|
|
108
|
+
date: {
|
|
109
|
+
kind: "local-date",
|
|
110
|
+
year: newDateFields.year,
|
|
111
|
+
month: newDateFields.month,
|
|
112
|
+
day: newDateFields.day,
|
|
113
|
+
},
|
|
114
|
+
time: {
|
|
115
|
+
kind: "local-time",
|
|
116
|
+
hour,
|
|
117
|
+
minute,
|
|
118
|
+
second,
|
|
119
|
+
millisecond,
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
throw new ChroneraError("CHRONERA_INVALID_TIME", "Invalid input for time arithmetic.");
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Adds hours to a LocalTime, LocalDateTime, or Instant.
|
|
127
|
+
* Accurately shifts calendar date when LocalDateTime rolls past midnight.
|
|
128
|
+
*/
|
|
129
|
+
export function addHours(target, amount) {
|
|
130
|
+
return addMillisecondsInternal(target, amount * 3_600_000);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Subtracts hours from a LocalTime, LocalDateTime, or Instant.
|
|
134
|
+
*/
|
|
135
|
+
export function subtractHours(target, amount) {
|
|
136
|
+
return addHours(target, -amount);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Adds minutes to a LocalTime, LocalDateTime, or Instant.
|
|
140
|
+
*/
|
|
141
|
+
export function addMinutes(target, amount) {
|
|
142
|
+
return addMillisecondsInternal(target, amount * 60_000);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Subtracts minutes from a LocalTime, LocalDateTime, or Instant.
|
|
146
|
+
*/
|
|
147
|
+
export function subtractMinutes(target, amount) {
|
|
148
|
+
return addMinutes(target, -amount);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Adds seconds to a LocalTime, LocalDateTime, or Instant.
|
|
152
|
+
*/
|
|
153
|
+
export function addSeconds(target, amount) {
|
|
154
|
+
return addMillisecondsInternal(target, amount * 1_000);
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Subtracts seconds from a LocalTime, LocalDateTime, or Instant.
|
|
158
|
+
*/
|
|
159
|
+
export function subtractSeconds(target, amount) {
|
|
160
|
+
return addSeconds(target, -amount);
|
|
161
|
+
}
|
|
162
|
+
//# sourceMappingURL=time-convenience.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"time-convenience.js","sourceRoot":"","sources":["../../src/operations/time-convenience.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,8BAA8B,EAC9B,8BAA8B,GAC/B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AASp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BACJ,IAAI,EAAE,YAAY;gBAClB,IAAI;gBACJ,MAAM;gBACN,MAAM;gBACN,WAAW;aACZ;SACG,CAAC;IACT,CAAC;IAED,MAAM,IAAI,aAAa,CACrB,uBAAuB,EACvB,oCAAoC,CACrC,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,QAAQ,CACtB,MAAS,EACT,MAAc;IAEd,OAAO,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;AAC7D,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAC3B,MAAS,EACT,MAAc;IAEd,OAAO,QAAQ,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,CAAC;AACnC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CACxB,MAAS,EACT,MAAc;IAEd,OAAO,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC;AAC1D,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAC7B,MAAS,EACT,MAAc;IAEd,OAAO,UAAU,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,CAAC;AACrC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CACxB,MAAS,EACT,MAAc;IAEd,OAAO,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG,KAAK,CAAC,CAAC;AACzD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAC7B,MAAS,EACT,MAAc;IAEd,OAAO,UAAU,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,CAAC;AACrC,CAAC","sourcesContent":["import {\n absoluteDayFromGregorianFields,\n gregorianFieldsFromAbsoluteDay,\n} from \"../core/absolute-day.js\";\nimport { ChroneraError } from \"../errors/errors.js\";\n\nimport type {\n Instant,\n LocalDate,\n LocalDateTime,\n TimeOrDateTimeOrInstant,\n} from \"../public-types.js\";\n\n/**\n * Returns the start of the day (00:00:00.000) as a LocalDateTime.\n * Accepts either a LocalDate or an existing LocalDateTime.\n */\nexport function startOfDay(input: LocalDate | LocalDateTime): LocalDateTime {\n const date = input.kind === \"local-date-time\" ? input.date : input;\n return {\n kind: \"local-date-time\",\n date,\n time: {\n kind: \"local-time\",\n hour: 0,\n minute: 0,\n second: 0,\n millisecond: 0,\n },\n };\n}\n\n/**\n * Returns the end of the day (23:59:59.999) as a LocalDateTime.\n * Accepts either a LocalDate or an existing LocalDateTime.\n */\nexport function endOfDay(input: LocalDate | LocalDateTime): LocalDateTime {\n const date = input.kind === \"local-date-time\" ? input.date : input;\n return {\n kind: \"local-date-time\",\n date,\n time: {\n kind: \"local-time\",\n hour: 23,\n minute: 59,\n second: 59,\n millisecond: 999,\n },\n };\n}\n\n/**\n * Returns true if the specified Instant, Date, or epoch millisecond timestamp is in the past.\n */\nexport function isPast(target: Instant | Date | number): boolean {\n const epochMs =\n typeof target === \"number\"\n ? target\n : target instanceof Date\n ? target.getTime()\n : target.epochMilliseconds;\n return epochMs < Date.now();\n}\n\n/**\n * Returns true if the specified Instant, Date, or epoch millisecond timestamp is in the future.\n */\nexport function isFuture(target: Instant | Date | number): boolean {\n const epochMs =\n typeof target === \"number\"\n ? target\n : target instanceof Date\n ? target.getTime()\n : target.epochMilliseconds;\n return epochMs > Date.now();\n}\n\n/**\n * Helper to add millisecond offset to LocalTime, LocalDateTime, or Instant.\n */\nfunction addMillisecondsInternal<T extends TimeOrDateTimeOrInstant>(\n target: T,\n deltaMs: number,\n): T {\n if (target.kind === \"instant\") {\n return {\n kind: \"instant\",\n epochMilliseconds: target.epochMilliseconds + deltaMs,\n } as T;\n }\n\n if (target.kind === \"local-time\") {\n const totalMs =\n target.hour * 3_600_000 +\n target.minute * 60_000 +\n target.second * 1_000 +\n target.millisecond +\n deltaMs;\n const dayMs = 86_400_000;\n const normalizedMs = ((totalMs % dayMs) + dayMs) % dayMs;\n\n const hour = Math.floor(normalizedMs / 3_600_000);\n const minute = Math.floor((normalizedMs % 3_600_000) / 60_000);\n const second = Math.floor((normalizedMs % 60_000) / 1_000);\n const millisecond = normalizedMs % 1_000;\n\n return {\n kind: \"local-time\",\n hour,\n minute,\n second,\n millisecond,\n } as T;\n }\n\n if (target.kind === \"local-date-time\") {\n const currentAbsDay = absoluteDayFromGregorianFields(\n target.date.year,\n target.date.month,\n target.date.day,\n );\n const currentDayMs =\n target.time.hour * 3_600_000 +\n target.time.minute * 60_000 +\n target.time.second * 1_000 +\n target.time.millisecond;\n\n const totalMs = currentDayMs + deltaMs;\n const dayShift = Math.floor(totalMs / 86_400_000);\n const timeMs = ((totalMs % 86_400_000) + 86_400_000) % 86_400_000;\n\n const newAbsDay = currentAbsDay + dayShift;\n const newDateFields = gregorianFieldsFromAbsoluteDay(newAbsDay);\n\n const hour = Math.floor(timeMs / 3_600_000);\n const minute = Math.floor((timeMs % 3_600_000) / 60_000);\n const second = Math.floor((timeMs % 60_000) / 1_000);\n const millisecond = timeMs % 1_000;\n\n return {\n kind: \"local-date-time\",\n date: {\n kind: \"local-date\",\n year: newDateFields.year,\n month: newDateFields.month,\n day: newDateFields.day,\n },\n time: {\n kind: \"local-time\",\n hour,\n minute,\n second,\n millisecond,\n },\n } as T;\n }\n\n throw new ChroneraError(\n \"CHRONERA_INVALID_TIME\",\n \"Invalid input for time arithmetic.\",\n );\n}\n\n/**\n * Adds hours to a LocalTime, LocalDateTime, or Instant.\n * Accurately shifts calendar date when LocalDateTime rolls past midnight.\n */\nexport function addHours<T extends TimeOrDateTimeOrInstant>(\n target: T,\n amount: number,\n): T {\n return addMillisecondsInternal(target, amount * 3_600_000);\n}\n\n/**\n * Subtracts hours from a LocalTime, LocalDateTime, or Instant.\n */\nexport function subtractHours<T extends TimeOrDateTimeOrInstant>(\n target: T,\n amount: number,\n): T {\n return addHours(target, -amount);\n}\n\n/**\n * Adds minutes to a LocalTime, LocalDateTime, or Instant.\n */\nexport function addMinutes<T extends TimeOrDateTimeOrInstant>(\n target: T,\n amount: number,\n): T {\n return addMillisecondsInternal(target, amount * 60_000);\n}\n\n/**\n * Subtracts minutes from a LocalTime, LocalDateTime, or Instant.\n */\nexport function subtractMinutes<T extends TimeOrDateTimeOrInstant>(\n target: T,\n amount: number,\n): T {\n return addMinutes(target, -amount);\n}\n\n/**\n * Adds seconds to a LocalTime, LocalDateTime, or Instant.\n */\nexport function addSeconds<T extends TimeOrDateTimeOrInstant>(\n target: T,\n amount: number,\n): T {\n return addMillisecondsInternal(target, amount * 1_000);\n}\n\n/**\n * Subtracts seconds from a LocalTime, LocalDateTime, or Instant.\n */\nexport function subtractSeconds<T extends TimeOrDateTimeOrInstant>(\n target: T,\n amount: number,\n): T {\n return addSeconds(target, -amount);\n}\n"]}
|
package/dist/public-types.d.ts
CHANGED
|
@@ -52,6 +52,7 @@ export interface ZonedDateTime {
|
|
|
52
52
|
}
|
|
53
53
|
export type FormatDateInput = LocalDate | CalendarDate | Instant | Date;
|
|
54
54
|
export type DateOrCalendarDate = LocalDate | CalendarDate;
|
|
55
|
+
export type TimeOrDateTimeOrInstant = LocalTime | LocalDateTime | Instant;
|
|
55
56
|
export type IntervalInclusivity = "()" | "[]" | "[)" | "(]";
|
|
56
57
|
export interface Duration {
|
|
57
58
|
readonly years?: number;
|
package/dist/public-types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"public-types.js","sourceRoot":"","sources":["../src/public-types.ts"],"names":[],"mappings":"","sourcesContent":["import type { DayOfYearFields } from \"./core/day-of-year.js\";\nimport type {\n FiscalFields,\n FiscalOptions,\n QuarterNumber,\n} from \"./core/fiscal.js\";\nimport type { ChroneraErrorCode } from \"./errors/error-codes.js\";\nimport type { PresetName } from \"./format/presets/types.js\";\nimport type { Rfc2822Options } from \"./format/rfc2822.js\";\n\nexport type {\n ChroneraErrorCode,\n DayOfYearFields,\n FiscalFields,\n FiscalOptions,\n PresetName,\n QuarterNumber,\n Rfc2822Options,\n};\n\nexport type BuiltInCalendarId =\n | \"iso8601\"\n | \"gregory\"\n | \"buddhist\"\n | \"islamic\"\n | \"islamic-civil\"\n | \"islamic-tbla\"\n | \"islamic-umalqura\"\n | \"persian\"\n | \"hebrew\"\n | \"japanese\"\n | \"roc\"\n | \"indian\"\n | \"coptic\"\n | \"ethiopic\"\n | \"chinese\"\n | \"dangi\";\n\ntype ExtensibleIdentifier = string & Record<never, never>;\n\nexport type CalendarId = BuiltInCalendarId | ExtensibleIdentifier;\n\nexport type LocaleId = string;\nexport type TimeZoneId = string;\nexport type NumberingSystemId = string;\nexport type EraId = string;\nexport type MonthCode = `M${string}`;\n\nexport interface Instant {\n readonly kind: \"instant\";\n readonly epochMilliseconds: number;\n}\n\nexport interface LocalDate {\n readonly kind: \"local-date\";\n readonly year: number;\n readonly month: number;\n readonly day: number;\n}\n\nexport interface LocalTime {\n readonly kind: \"local-time\";\n readonly hour: number;\n readonly minute: number;\n readonly second: number;\n readonly millisecond: number;\n}\n\nexport interface LocalDateTime {\n readonly kind: \"local-date-time\";\n readonly date: LocalDate;\n readonly time: LocalTime;\n}\n\nexport interface CalendarDate {\n readonly kind: \"calendar-date\";\n readonly calendar: CalendarId;\n readonly era?: EraId;\n readonly eraYear?: number;\n readonly year: number;\n readonly monthCode: MonthCode;\n readonly month?: number;\n readonly day: number;\n}\n\nexport interface ZonedDateTime {\n readonly kind: \"zoned-date-time\";\n readonly instant: Instant;\n readonly timeZone: TimeZoneId;\n readonly calendar: CalendarId;\n}\n\nexport type FormatDateInput = LocalDate | CalendarDate | Instant | Date;\nexport type DateOrCalendarDate = LocalDate | CalendarDate;\nexport type IntervalInclusivity = \"()\" | \"[]\" | \"[)\" | \"(]\";\n\nexport interface Duration {\n readonly years?: number;\n readonly months?: number;\n readonly weeks?: number;\n readonly days?: number;\n readonly hours?: number;\n readonly minutes?: number;\n readonly seconds?: number;\n readonly milliseconds?: number;\n}\n\nexport interface DateRange<TDate> {\n readonly start: TDate;\n readonly end: TDate;\n readonly startInclusive: boolean;\n readonly endInclusive: boolean;\n}\n\nexport interface CalendarConversionMetadata {\n readonly requestedCalendar: CalendarId;\n readonly resolvedCalendar: CalendarId;\n readonly engine: \"chronera\" | \"runtime-intl\" | \"custom\";\n readonly algorithm: string;\n readonly deterministic: boolean;\n readonly dataVersion?: string;\n readonly validFrom?: LocalDate;\n readonly validTo?: LocalDate;\n}\n\nexport interface CalendarConversionResult {\n readonly value: CalendarDate;\n readonly metadata: CalendarConversionMetadata;\n}\n\nexport interface ChroneraIssue {\n readonly code: ChroneraErrorCode;\n readonly message: string;\n readonly path?: readonly (string | number)[];\n}\n\nexport type SafeParseResult<T> =\n | {\n readonly success: true;\n readonly value: T;\n }\n | {\n readonly success: false;\n readonly error: ChroneraIssue;\n };\n\nexport type Comparison = -1 | 0 | 1;\n\nexport interface CalendarPlugin {\n readonly id: CalendarId;\n readonly algorithm: string;\n readonly deterministic: boolean;\n readonly validFrom: LocalDate;\n readonly validTo: LocalDate;\n toIsoDate(date: CalendarDate): LocalDate;\n fromIsoDate(date: LocalDate): CalendarDate;\n validate(date: CalendarDate): readonly ChroneraIssue[];\n}\n\nexport interface ChroneraConfig {\n readonly locale?: LocaleId;\n readonly calendar?: CalendarId;\n readonly numberingSystem?: NumberingSystemId;\n readonly timeZone?: TimeZoneId;\n readonly calendars?: readonly CalendarPlugin[];\n readonly formatterCacheSize?: number;\n}\n\nexport interface ResolvedChroneraOptions {\n readonly locale: LocaleId;\n readonly calendar: CalendarId;\n readonly numberingSystem?: NumberingSystemId;\n readonly timeZone: TimeZoneId;\n readonly formatterCacheSize: number;\n}\n\nexport interface FormatDateBaseOptions {\n readonly locale?: LocaleId;\n readonly calendar?: CalendarId;\n readonly numberingSystem?: NumberingSystemId;\n readonly timeZone?: TimeZoneId;\n readonly fallback?: \"error\";\n}\n\nexport type FormatDateOptions = FormatDateBaseOptions &\n (\n | {\n readonly style?: \"numeric\" | \"short\" | \"medium\" | \"long\" | \"full\";\n readonly preset?: never;\n }\n | {\n readonly style?: never;\n readonly preset: PresetName;\n }\n );\n\nexport interface FormatTimeOptions {\n readonly locale?: LocaleId;\n readonly numberingSystem?: NumberingSystemId;\n readonly timeZone?: TimeZoneId;\n readonly style?: \"short\" | \"medium\" | \"long\" | \"full\";\n readonly hourCycle?: \"h11\" | \"h12\" | \"h23\" | \"h24\";\n}\n\nexport interface FormatDateTimeOptions extends FormatDateBaseOptions {\n readonly dateStyle?: \"short\" | \"medium\" | \"long\" | \"full\";\n readonly timeStyle?: \"short\" | \"medium\" | \"long\" | \"full\";\n readonly hourCycle?: \"h11\" | \"h12\" | \"h23\" | \"h24\";\n}\n\nexport type FormatDateRangeOptions = FormatDateOptions & {\n readonly collapse?: \"auto\" | \"none\";\n};\n\nexport interface FormatRelativeOptions {\n readonly relativeTo: Instant | LocalDate;\n readonly locale?: LocaleId;\n readonly numeric?: \"always\" | \"auto\";\n readonly unit?:\n \"second\" | \"minute\" | \"hour\" | \"day\" | \"week\" | \"month\" | \"year\";\n readonly timeZone?: TimeZoneId;\n}\n\nexport interface PatternFormatOptions {\n readonly locale?: LocaleId;\n readonly calendar?: CalendarId;\n readonly numberingSystem?: NumberingSystemId;\n readonly timeZone?: TimeZoneId;\n}\n\nexport interface ParseLocalDateOptions {\n readonly pattern?: string;\n readonly locale?: LocaleId;\n readonly calendar?: \"gregory\" | \"iso8601\";\n readonly numberingSystem?: NumberingSystemId;\n}\n\nexport interface ParseInstantOptions {\n readonly excessFractionalSeconds?: \"reject\" | \"truncate\" | \"round\";\n}\n\nexport interface ConvertCalendarOptions {\n readonly fallback?: \"error\";\n}\n\nexport interface CalendarCapabilities {\n readonly calendar: CalendarId;\n readonly maturity:\n \"stable\" | \"experimental\" | \"runtime-dependent\" | \"planned\" | \"unsupported\";\n readonly canFormat: boolean;\n readonly canParse: boolean;\n readonly canConvertFromAbsoluteDate: boolean;\n readonly canConvertToAbsoluteDate: boolean;\n readonly canValidate: boolean;\n readonly canAddYears: boolean;\n readonly canAddMonths: boolean;\n readonly deterministic: boolean;\n readonly algorithm?: string;\n readonly dataVersion?: string;\n readonly validFrom?: LocalDate;\n readonly validTo?: LocalDate;\n}\n\nexport interface RuntimeCapabilities {\n readonly hasDateTimeFormat: boolean;\n readonly hasFormatToParts: boolean;\n readonly hasFormatRange: boolean;\n readonly hasRelativeTimeFormat: boolean;\n readonly hasLocale: boolean;\n readonly hasSupportedValuesOf: boolean;\n readonly hasTemporal: boolean;\n readonly calendars: Readonly<Record<string, boolean>>;\n readonly timeZones: Readonly<Record<string, boolean>>;\n}\n\nexport interface ChroneraInstance {\n formatDate(\n input: FormatDateInput,\n options?: Readonly<FormatDateOptions>,\n ): string;\n parseLocalDate(\n input: string,\n options?: Readonly<ParseLocalDateOptions>,\n ): LocalDate;\n convertCalendarDate(\n source: CalendarDate,\n targetCalendar: CalendarId,\n options?: Readonly<ConvertCalendarOptions>,\n ): CalendarConversionResult;\n resolvedOptions(): ResolvedChroneraOptions;\n}\n\nexport type { IsoWeekFields } from \"./core/iso-week.js\";\n"]}
|
|
1
|
+
{"version":3,"file":"public-types.js","sourceRoot":"","sources":["../src/public-types.ts"],"names":[],"mappings":"","sourcesContent":["import type { DayOfYearFields } from \"./core/day-of-year.js\";\nimport type {\n FiscalFields,\n FiscalOptions,\n QuarterNumber,\n} from \"./core/fiscal.js\";\nimport type { ChroneraErrorCode } from \"./errors/error-codes.js\";\nimport type { PresetName } from \"./format/presets/types.js\";\nimport type { Rfc2822Options } from \"./format/rfc2822.js\";\n\nexport type {\n ChroneraErrorCode,\n DayOfYearFields,\n FiscalFields,\n FiscalOptions,\n PresetName,\n QuarterNumber,\n Rfc2822Options,\n};\n\nexport type BuiltInCalendarId =\n | \"iso8601\"\n | \"gregory\"\n | \"buddhist\"\n | \"islamic\"\n | \"islamic-civil\"\n | \"islamic-tbla\"\n | \"islamic-umalqura\"\n | \"persian\"\n | \"hebrew\"\n | \"japanese\"\n | \"roc\"\n | \"indian\"\n | \"coptic\"\n | \"ethiopic\"\n | \"chinese\"\n | \"dangi\";\n\ntype ExtensibleIdentifier = string & Record<never, never>;\n\nexport type CalendarId = BuiltInCalendarId | ExtensibleIdentifier;\n\nexport type LocaleId = string;\nexport type TimeZoneId = string;\nexport type NumberingSystemId = string;\nexport type EraId = string;\nexport type MonthCode = `M${string}`;\n\nexport interface Instant {\n readonly kind: \"instant\";\n readonly epochMilliseconds: number;\n}\n\nexport interface LocalDate {\n readonly kind: \"local-date\";\n readonly year: number;\n readonly month: number;\n readonly day: number;\n}\n\nexport interface LocalTime {\n readonly kind: \"local-time\";\n readonly hour: number;\n readonly minute: number;\n readonly second: number;\n readonly millisecond: number;\n}\n\nexport interface LocalDateTime {\n readonly kind: \"local-date-time\";\n readonly date: LocalDate;\n readonly time: LocalTime;\n}\n\nexport interface CalendarDate {\n readonly kind: \"calendar-date\";\n readonly calendar: CalendarId;\n readonly era?: EraId;\n readonly eraYear?: number;\n readonly year: number;\n readonly monthCode: MonthCode;\n readonly month?: number;\n readonly day: number;\n}\n\nexport interface ZonedDateTime {\n readonly kind: \"zoned-date-time\";\n readonly instant: Instant;\n readonly timeZone: TimeZoneId;\n readonly calendar: CalendarId;\n}\n\nexport type FormatDateInput = LocalDate | CalendarDate | Instant | Date;\nexport type DateOrCalendarDate = LocalDate | CalendarDate;\nexport type TimeOrDateTimeOrInstant = LocalTime | LocalDateTime | Instant;\nexport type IntervalInclusivity = \"()\" | \"[]\" | \"[)\" | \"(]\";\n\nexport interface Duration {\n readonly years?: number;\n readonly months?: number;\n readonly weeks?: number;\n readonly days?: number;\n readonly hours?: number;\n readonly minutes?: number;\n readonly seconds?: number;\n readonly milliseconds?: number;\n}\n\nexport interface DateRange<TDate> {\n readonly start: TDate;\n readonly end: TDate;\n readonly startInclusive: boolean;\n readonly endInclusive: boolean;\n}\n\nexport interface CalendarConversionMetadata {\n readonly requestedCalendar: CalendarId;\n readonly resolvedCalendar: CalendarId;\n readonly engine: \"chronera\" | \"runtime-intl\" | \"custom\";\n readonly algorithm: string;\n readonly deterministic: boolean;\n readonly dataVersion?: string;\n readonly validFrom?: LocalDate;\n readonly validTo?: LocalDate;\n}\n\nexport interface CalendarConversionResult {\n readonly value: CalendarDate;\n readonly metadata: CalendarConversionMetadata;\n}\n\nexport interface ChroneraIssue {\n readonly code: ChroneraErrorCode;\n readonly message: string;\n readonly path?: readonly (string | number)[];\n}\n\nexport type SafeParseResult<T> =\n | {\n readonly success: true;\n readonly value: T;\n }\n | {\n readonly success: false;\n readonly error: ChroneraIssue;\n };\n\nexport type Comparison = -1 | 0 | 1;\n\nexport interface CalendarPlugin {\n readonly id: CalendarId;\n readonly algorithm: string;\n readonly deterministic: boolean;\n readonly validFrom: LocalDate;\n readonly validTo: LocalDate;\n toIsoDate(date: CalendarDate): LocalDate;\n fromIsoDate(date: LocalDate): CalendarDate;\n validate(date: CalendarDate): readonly ChroneraIssue[];\n}\n\nexport interface ChroneraConfig {\n readonly locale?: LocaleId;\n readonly calendar?: CalendarId;\n readonly numberingSystem?: NumberingSystemId;\n readonly timeZone?: TimeZoneId;\n readonly calendars?: readonly CalendarPlugin[];\n readonly formatterCacheSize?: number;\n}\n\nexport interface ResolvedChroneraOptions {\n readonly locale: LocaleId;\n readonly calendar: CalendarId;\n readonly numberingSystem?: NumberingSystemId;\n readonly timeZone: TimeZoneId;\n readonly formatterCacheSize: number;\n}\n\nexport interface FormatDateBaseOptions {\n readonly locale?: LocaleId;\n readonly calendar?: CalendarId;\n readonly numberingSystem?: NumberingSystemId;\n readonly timeZone?: TimeZoneId;\n readonly fallback?: \"error\";\n}\n\nexport type FormatDateOptions = FormatDateBaseOptions &\n (\n | {\n readonly style?: \"numeric\" | \"short\" | \"medium\" | \"long\" | \"full\";\n readonly preset?: never;\n }\n | {\n readonly style?: never;\n readonly preset: PresetName;\n }\n );\n\nexport interface FormatTimeOptions {\n readonly locale?: LocaleId;\n readonly numberingSystem?: NumberingSystemId;\n readonly timeZone?: TimeZoneId;\n readonly style?: \"short\" | \"medium\" | \"long\" | \"full\";\n readonly hourCycle?: \"h11\" | \"h12\" | \"h23\" | \"h24\";\n}\n\nexport interface FormatDateTimeOptions extends FormatDateBaseOptions {\n readonly dateStyle?: \"short\" | \"medium\" | \"long\" | \"full\";\n readonly timeStyle?: \"short\" | \"medium\" | \"long\" | \"full\";\n readonly hourCycle?: \"h11\" | \"h12\" | \"h23\" | \"h24\";\n}\n\nexport type FormatDateRangeOptions = FormatDateOptions & {\n readonly collapse?: \"auto\" | \"none\";\n};\n\nexport interface FormatRelativeOptions {\n readonly relativeTo: Instant | LocalDate;\n readonly locale?: LocaleId;\n readonly numeric?: \"always\" | \"auto\";\n readonly unit?:\n \"second\" | \"minute\" | \"hour\" | \"day\" | \"week\" | \"month\" | \"year\";\n readonly timeZone?: TimeZoneId;\n}\n\nexport interface PatternFormatOptions {\n readonly locale?: LocaleId;\n readonly calendar?: CalendarId;\n readonly numberingSystem?: NumberingSystemId;\n readonly timeZone?: TimeZoneId;\n}\n\nexport interface ParseLocalDateOptions {\n readonly pattern?: string;\n readonly locale?: LocaleId;\n readonly calendar?: \"gregory\" | \"iso8601\";\n readonly numberingSystem?: NumberingSystemId;\n}\n\nexport interface ParseInstantOptions {\n readonly excessFractionalSeconds?: \"reject\" | \"truncate\" | \"round\";\n}\n\nexport interface ConvertCalendarOptions {\n readonly fallback?: \"error\";\n}\n\nexport interface CalendarCapabilities {\n readonly calendar: CalendarId;\n readonly maturity:\n \"stable\" | \"experimental\" | \"runtime-dependent\" | \"planned\" | \"unsupported\";\n readonly canFormat: boolean;\n readonly canParse: boolean;\n readonly canConvertFromAbsoluteDate: boolean;\n readonly canConvertToAbsoluteDate: boolean;\n readonly canValidate: boolean;\n readonly canAddYears: boolean;\n readonly canAddMonths: boolean;\n readonly deterministic: boolean;\n readonly algorithm?: string;\n readonly dataVersion?: string;\n readonly validFrom?: LocalDate;\n readonly validTo?: LocalDate;\n}\n\nexport interface RuntimeCapabilities {\n readonly hasDateTimeFormat: boolean;\n readonly hasFormatToParts: boolean;\n readonly hasFormatRange: boolean;\n readonly hasRelativeTimeFormat: boolean;\n readonly hasLocale: boolean;\n readonly hasSupportedValuesOf: boolean;\n readonly hasTemporal: boolean;\n readonly calendars: Readonly<Record<string, boolean>>;\n readonly timeZones: Readonly<Record<string, boolean>>;\n}\n\nexport interface ChroneraInstance {\n formatDate(\n input: FormatDateInput,\n options?: Readonly<FormatDateOptions>,\n ): string;\n parseLocalDate(\n input: string,\n options?: Readonly<ParseLocalDateOptions>,\n ): LocalDate;\n convertCalendarDate(\n source: CalendarDate,\n targetCalendar: CalendarId,\n options?: Readonly<ConvertCalendarOptions>,\n ): CalendarConversionResult;\n resolvedOptions(): ResolvedChroneraOptions;\n}\n\nexport type { IsoWeekFields } from \"./core/iso-week.js\";\n"]}
|
package/package.json
CHANGED