chronos-ts
Version:
A comprehensive TypeScript library for date and time manipulation, inspired by Carbon PHP. Features immutable API, intervals, periods, timezones, and i18n support.
151 lines (150 loc) • 12.8 kB
JavaScript
;
/**
* Chronos v2 - A comprehensive TypeScript library for date and time manipulation
*
* @description
* Chronos is a powerful, modern TypeScript library for handling dates, times,
* intervals, periods, and timezones. Inspired by Carbon PHP, it provides an
* intuitive and fluent API for all your time-related needs.
*
* @example
* ```typescript
* import { Chronos, ChronosInterval, ChronosPeriod, ChronosTimezone } from 'chronos-ts';
*
* // Create dates
* const now = Chronos.now();
* const birthday = Chronos.create(1990, 5, 15);
*
* // Manipulate
* const nextWeek = now.addWeeks(1);
* const endOfMonth = now.endOf('month');
*
* // Compare
* if (now.isAfter(birthday)) {
* console.log('Birthday has passed');
* }
*
* // Format
* console.log(now.format('MMMM D, YYYY')); // "January 15, 2024"
*
* // Intervals
* const duration = ChronosInterval.hours(5).addMinutes(30);
* console.log(duration.forHumans()); // "5 hours 30 minutes"
*
* // Periods
* const week = ChronosPeriod.currentWeek();
* for (const day of week) {
* console.log(day.format('dddd'));
* }
*
* // Timezones
* const tz = ChronosTimezone.create('America/New_York');
* console.log(tz.getOffsetString()); // "-05:00"
* ```
*
* @packageDocumentation
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.durationToISO = exports.parseISODuration = exports.diffInUnits = exports.addUnits = exports.subtractDuration = exports.addDuration = exports.endOf = exports.startOf = exports.getQuarter = exports.getISOWeekYear = exports.getISOWeek = exports.getDayOfYear = exports.getDaysInYear = exports.getDaysInMonth = exports.getMillisecondsPerUnit = exports.pluralizeUnit = exports.normalizeUnit = exports.isValidDate = exports.isLeapYear = exports.isISODuration = exports.isDuration = exports.isChronosLike = exports.isValidDateInput = exports.isDate = exports.AVERAGE_DAYS_PER_YEAR = exports.AVERAGE_DAYS_PER_MONTH = exports.DAYS_PER_LEAP_YEAR = exports.DAYS_PER_YEAR = exports.MONTHS_PER_YEAR = exports.DAYS_PER_WEEK = exports.HOURS_PER_DAY = exports.MINUTES_PER_HOUR = exports.SECONDS_PER_MINUTE = exports.MILLISECONDS_PER_YEAR = exports.MILLISECONDS_PER_MONTH = exports.MILLISECONDS_PER_WEEK = exports.MILLISECONDS_PER_DAY = exports.MILLISECONDS_PER_HOUR = exports.MILLISECONDS_PER_MINUTE = exports.MILLISECONDS_PER_SECOND = exports.PeriodBoundary = exports.Month = exports.DayOfWeek = exports.Timezones = exports.TIMEZONES = exports.ChronosTimezone = exports.ChronosPeriodCollection = exports.ChronosPeriod = exports.ChronosInterval = exports.Chronos = void 0;
exports.default = exports.ru = exports.ar = exports.it = exports.pt = exports.zh = exports.ja = exports.de = exports.fr = exports.es = exports.en = exports.defaultLocale = exports.getAvailableLocales = exports.registerLocale = exports.getLocale = exports.padStart = exports.ordinalSuffix = exports.clamp = exports.cloneDate = exports.isSameAt = exports.compareAtGranularity = void 0;
// ============================================================================
// Core Classes
// ============================================================================
var core_1 = require("./core");
Object.defineProperty(exports, "Chronos", { enumerable: true, get: function () { return core_1.Chronos; } });
Object.defineProperty(exports, "ChronosInterval", { enumerable: true, get: function () { return core_1.ChronosInterval; } });
Object.defineProperty(exports, "ChronosPeriod", { enumerable: true, get: function () { return core_1.ChronosPeriod; } });
Object.defineProperty(exports, "ChronosPeriodCollection", { enumerable: true, get: function () { return core_1.ChronosPeriodCollection; } });
Object.defineProperty(exports, "ChronosTimezone", { enumerable: true, get: function () { return core_1.ChronosTimezone; } });
Object.defineProperty(exports, "TIMEZONES", { enumerable: true, get: function () { return core_1.TIMEZONES; } });
Object.defineProperty(exports, "Timezones", { enumerable: true, get: function () { return core_1.Timezones; } });
// ============================================================================
// Types
// ============================================================================
var types_1 = require("./types");
// Enums
Object.defineProperty(exports, "DayOfWeek", { enumerable: true, get: function () { return types_1.DayOfWeek; } });
Object.defineProperty(exports, "Month", { enumerable: true, get: function () { return types_1.Month; } });
Object.defineProperty(exports, "PeriodBoundary", { enumerable: true, get: function () { return types_1.PeriodBoundary; } });
// Constants
Object.defineProperty(exports, "MILLISECONDS_PER_SECOND", { enumerable: true, get: function () { return types_1.MILLISECONDS_PER_SECOND; } });
Object.defineProperty(exports, "MILLISECONDS_PER_MINUTE", { enumerable: true, get: function () { return types_1.MILLISECONDS_PER_MINUTE; } });
Object.defineProperty(exports, "MILLISECONDS_PER_HOUR", { enumerable: true, get: function () { return types_1.MILLISECONDS_PER_HOUR; } });
Object.defineProperty(exports, "MILLISECONDS_PER_DAY", { enumerable: true, get: function () { return types_1.MILLISECONDS_PER_DAY; } });
Object.defineProperty(exports, "MILLISECONDS_PER_WEEK", { enumerable: true, get: function () { return types_1.MILLISECONDS_PER_WEEK; } });
Object.defineProperty(exports, "MILLISECONDS_PER_MONTH", { enumerable: true, get: function () { return types_1.MILLISECONDS_PER_MONTH; } });
Object.defineProperty(exports, "MILLISECONDS_PER_YEAR", { enumerable: true, get: function () { return types_1.MILLISECONDS_PER_YEAR; } });
Object.defineProperty(exports, "SECONDS_PER_MINUTE", { enumerable: true, get: function () { return types_1.SECONDS_PER_MINUTE; } });
Object.defineProperty(exports, "MINUTES_PER_HOUR", { enumerable: true, get: function () { return types_1.MINUTES_PER_HOUR; } });
Object.defineProperty(exports, "HOURS_PER_DAY", { enumerable: true, get: function () { return types_1.HOURS_PER_DAY; } });
Object.defineProperty(exports, "DAYS_PER_WEEK", { enumerable: true, get: function () { return types_1.DAYS_PER_WEEK; } });
Object.defineProperty(exports, "MONTHS_PER_YEAR", { enumerable: true, get: function () { return types_1.MONTHS_PER_YEAR; } });
Object.defineProperty(exports, "DAYS_PER_YEAR", { enumerable: true, get: function () { return types_1.DAYS_PER_YEAR; } });
Object.defineProperty(exports, "DAYS_PER_LEAP_YEAR", { enumerable: true, get: function () { return types_1.DAYS_PER_LEAP_YEAR; } });
Object.defineProperty(exports, "AVERAGE_DAYS_PER_MONTH", { enumerable: true, get: function () { return types_1.AVERAGE_DAYS_PER_MONTH; } });
Object.defineProperty(exports, "AVERAGE_DAYS_PER_YEAR", { enumerable: true, get: function () { return types_1.AVERAGE_DAYS_PER_YEAR; } });
// ============================================================================
// Utilities
// ============================================================================
var utils_1 = require("./utils");
// Type Guards
Object.defineProperty(exports, "isDate", { enumerable: true, get: function () { return utils_1.isDate; } });
Object.defineProperty(exports, "isValidDateInput", { enumerable: true, get: function () { return utils_1.isValidDateInput; } });
Object.defineProperty(exports, "isChronosLike", { enumerable: true, get: function () { return utils_1.isChronosLike; } });
Object.defineProperty(exports, "isDuration", { enumerable: true, get: function () { return utils_1.isDuration; } });
Object.defineProperty(exports, "isISODuration", { enumerable: true, get: function () { return utils_1.isISODuration; } });
Object.defineProperty(exports, "isLeapYear", { enumerable: true, get: function () { return utils_1.isLeapYear; } });
Object.defineProperty(exports, "isValidDate", { enumerable: true, get: function () { return utils_1.isValidDate; } });
// Unit Utilities
Object.defineProperty(exports, "normalizeUnit", { enumerable: true, get: function () { return utils_1.normalizeUnit; } });
Object.defineProperty(exports, "pluralizeUnit", { enumerable: true, get: function () { return utils_1.pluralizeUnit; } });
Object.defineProperty(exports, "getMillisecondsPerUnit", { enumerable: true, get: function () { return utils_1.getMillisecondsPerUnit; } });
// Date Utilities
Object.defineProperty(exports, "getDaysInMonth", { enumerable: true, get: function () { return utils_1.getDaysInMonth; } });
Object.defineProperty(exports, "getDaysInYear", { enumerable: true, get: function () { return utils_1.getDaysInYear; } });
Object.defineProperty(exports, "getDayOfYear", { enumerable: true, get: function () { return utils_1.getDayOfYear; } });
Object.defineProperty(exports, "getISOWeek", { enumerable: true, get: function () { return utils_1.getISOWeek; } });
Object.defineProperty(exports, "getISOWeekYear", { enumerable: true, get: function () { return utils_1.getISOWeekYear; } });
Object.defineProperty(exports, "getQuarter", { enumerable: true, get: function () { return utils_1.getQuarter; } });
Object.defineProperty(exports, "startOf", { enumerable: true, get: function () { return utils_1.startOf; } });
Object.defineProperty(exports, "endOf", { enumerable: true, get: function () { return utils_1.endOf; } });
// Arithmetic
Object.defineProperty(exports, "addDuration", { enumerable: true, get: function () { return utils_1.addDuration; } });
Object.defineProperty(exports, "subtractDuration", { enumerable: true, get: function () { return utils_1.subtractDuration; } });
Object.defineProperty(exports, "addUnits", { enumerable: true, get: function () { return utils_1.addUnits; } });
Object.defineProperty(exports, "diffInUnits", { enumerable: true, get: function () { return utils_1.diffInUnits; } });
// Parsing
Object.defineProperty(exports, "parseISODuration", { enumerable: true, get: function () { return utils_1.parseISODuration; } });
Object.defineProperty(exports, "durationToISO", { enumerable: true, get: function () { return utils_1.durationToISO; } });
// Comparison
Object.defineProperty(exports, "compareAtGranularity", { enumerable: true, get: function () { return utils_1.compareAtGranularity; } });
Object.defineProperty(exports, "isSameAt", { enumerable: true, get: function () { return utils_1.isSameAt; } });
// Helpers
Object.defineProperty(exports, "cloneDate", { enumerable: true, get: function () { return utils_1.cloneDate; } });
Object.defineProperty(exports, "clamp", { enumerable: true, get: function () { return utils_1.clamp; } });
Object.defineProperty(exports, "ordinalSuffix", { enumerable: true, get: function () { return utils_1.ordinalSuffix; } });
Object.defineProperty(exports, "padStart", { enumerable: true, get: function () { return utils_1.padStart; } });
// ============================================================================
// Locales
// ============================================================================
var locales_1 = require("./locales");
Object.defineProperty(exports, "getLocale", { enumerable: true, get: function () { return locales_1.getLocale; } });
Object.defineProperty(exports, "registerLocale", { enumerable: true, get: function () { return locales_1.registerLocale; } });
Object.defineProperty(exports, "getAvailableLocales", { enumerable: true, get: function () { return locales_1.getAvailableLocales; } });
Object.defineProperty(exports, "defaultLocale", { enumerable: true, get: function () { return locales_1.defaultLocale; } });
Object.defineProperty(exports, "en", { enumerable: true, get: function () { return locales_1.en; } });
Object.defineProperty(exports, "es", { enumerable: true, get: function () { return locales_1.es; } });
Object.defineProperty(exports, "fr", { enumerable: true, get: function () { return locales_1.fr; } });
Object.defineProperty(exports, "de", { enumerable: true, get: function () { return locales_1.de; } });
Object.defineProperty(exports, "ja", { enumerable: true, get: function () { return locales_1.ja; } });
Object.defineProperty(exports, "zh", { enumerable: true, get: function () { return locales_1.zh; } });
Object.defineProperty(exports, "pt", { enumerable: true, get: function () { return locales_1.pt; } });
Object.defineProperty(exports, "it", { enumerable: true, get: function () { return locales_1.it; } });
Object.defineProperty(exports, "ar", { enumerable: true, get: function () { return locales_1.ar; } });
Object.defineProperty(exports, "ru", { enumerable: true, get: function () { return locales_1.ru; } });
// ============================================================================
// Default Export
// ============================================================================
// Export Chronos as default for convenience
var core_2 = require("./core");
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return core_2.Chronos; } });