Favivon - Correção

This commit is contained in:
2026-05-30 19:59:39 -03:00
parent 76ddaa815d
commit d7dfd221f0
32859 changed files with 5459654 additions and 404 deletions
+44
View File
@@ -0,0 +1,44 @@
import type { Locale } from "date-fns";
import React from "react";
import { DateLib, type DateLibOptions } from "../index.js";
import type { DayPickerProps } from "../types/props.js";
/**
* Render the Ethiopic calendar.
*
* Defaults:
*
* - `locale`: `am-ET` (Amharic) via an Intl-backed date-fns locale
* - `numerals`: `geez` (Ethiopic digits)
*
* Notes:
*
* - Weekday names are taken from `Intl.DateTimeFormat(locale.code)`.
* - Month names are Amharic by default; they switch to Latin transliteration when
* `locale.code` starts with `en` or when `numerals` is `latn`.
* - Time tokens like `hh:mm a` are formatted via `Intl.DateTimeFormat` using the
* provided `locale`.
*
* @see https://daypicker.dev/docs/localization#ethiopic-calendar
*/
export declare function DayPicker(props: DayPickerProps & {
/**
* The locale to use in the calendar.
*
* @default `am-ET`
*/
locale?: Locale;
/**
* The numeral system to use when formatting dates.
*
* - `latn`: Latin (Western Arabic)
* - `geez`: Ge'ez (Ethiopic numerals)
*
* @defaultValue `geez` (Ethiopic numerals)
* @see https://daypicker.dev/docs/translation#numeral-systems
*/
numerals?: DayPickerProps["numerals"];
}): React.JSX.Element;
/** Returns the date library used in the calendar. */
export declare const getDateLib: (options?: DateLibOptions) => DateLib;
export { amET } from "../locale/am-ET.js";
export { enUS } from "../locale/en-US.js";
+77
View File
@@ -0,0 +1,77 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.enUS = exports.amET = exports.getDateLib = void 0;
exports.DayPicker = DayPicker;
const react_1 = __importDefault(require("react"));
const index_js_1 = require("../index.js");
const am_ET_js_1 = __importDefault(require("../locale/am-ET.js"));
const ethiopicDateLib = __importStar(require("./lib/index.js"));
/**
* Render the Ethiopic calendar.
*
* Defaults:
*
* - `locale`: `am-ET` (Amharic) via an Intl-backed date-fns locale
* - `numerals`: `geez` (Ethiopic digits)
*
* Notes:
*
* - Weekday names are taken from `Intl.DateTimeFormat(locale.code)`.
* - Month names are Amharic by default; they switch to Latin transliteration when
* `locale.code` starts with `en` or when `numerals` is `latn`.
* - Time tokens like `hh:mm a` are formatted via `Intl.DateTimeFormat` using the
* provided `locale`.
*
* @see https://daypicker.dev/docs/localization#ethiopic-calendar
*/
function DayPicker(props) {
return (react_1.default.createElement(index_js_1.DayPicker, { ...props, locale: props.locale ?? am_ET_js_1.default, numerals: props.numerals ?? "geez",
// Pass overrides, not a DateLib instance
dateLib: ethiopicDateLib }));
}
/** Returns the date library used in the calendar. */
const getDateLib = (options) => {
return new index_js_1.DateLib(options, ethiopicDateLib);
};
exports.getDateLib = getDateLib;
// Export a minimal Amharic (Ethiopia) date-fns locale that uses Intl
var am_ET_js_2 = require("../locale/am-ET.js");
Object.defineProperty(exports, "amET", { enumerable: true, get: function () { return am_ET_js_2.amET; } });
var en_US_js_1 = require("../locale/en-US.js");
Object.defineProperty(exports, "enUS", { enumerable: true, get: function () { return en_US_js_1.enUS; } });
+9
View File
@@ -0,0 +1,9 @@
/**
* Adds the specified number of months to the given Ethiopian date. Handles
* month overflow and year boundaries correctly.
*
* @param date - The starting gregorian date
* @param amount - The number of months to add (can be negative)
* @returns A new gregorian date with the months added
*/
export declare function addMonths(date: Date, amount: number): Date;
+27
View File
@@ -0,0 +1,27 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.addMonths = addMonths;
const daysInMonth_js_1 = require("../utils/daysInMonth.js");
const index_js_1 = require("../utils/index.js");
/**
* Adds the specified number of months to the given Ethiopian date. Handles
* month overflow and year boundaries correctly.
*
* @param date - The starting gregorian date
* @param amount - The number of months to add (can be negative)
* @returns A new gregorian date with the months added
*/
function addMonths(date, amount) {
const { year, month, day } = (0, index_js_1.toEthiopicDate)(date);
let newMonth = month + amount;
const yearAdjustment = Math.floor((newMonth - 1) / 13);
newMonth = ((newMonth - 1) % 13) + 1;
if (newMonth < 1) {
newMonth += 13;
}
const newYear = year + yearAdjustment;
// Adjust day if it exceeds the month length
const monthLength = (0, daysInMonth_js_1.daysInMonth)(newMonth, newYear);
const newDay = Math.min(day, monthLength);
return (0, index_js_1.toGregorianDate)({ year: newYear, month: newMonth, day: newDay });
}
+9
View File
@@ -0,0 +1,9 @@
/**
* Adds the specified number of years to the given Ethiopian date. Handles leap
* year transitions for Pagume month.
*
* @param date - The starting gregorian date
* @param amount - The number of years to add (can be negative)
* @returns A new gregorian date with the years added
*/
export declare function addYears(date: Date, amount: number): Date;
+26
View File
@@ -0,0 +1,26 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.addYears = addYears;
const index_js_1 = require("../utils/index.js");
/**
* Adds the specified number of years to the given Ethiopian date. Handles leap
* year transitions for Pagume month.
*
* @param date - The starting gregorian date
* @param amount - The number of years to add (can be negative)
* @returns A new gregorian date with the years added
*/
function addYears(date, amount) {
const etDate = (0, index_js_1.toEthiopicDate)(date);
const day = (0, index_js_1.isEthiopicLeapYear)(etDate.year) &&
etDate.month === 13 &&
etDate.day === 6 &&
amount % 4 !== 0
? 5
: etDate.day;
return (0, index_js_1.toGregorianDate)({
month: etDate.month,
day: day,
year: etDate.year + amount,
});
}
@@ -0,0 +1,8 @@
/**
* Difference in calendar months
*
* @param {Date} dateLeft - The later date
* @param {Date} dateRight - The earlier date
* @returns {number} The number of calendar months between the two dates
*/
export declare function differenceInCalendarMonths(dateLeft: Date, dateRight: Date): number;
@@ -0,0 +1,17 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.differenceInCalendarMonths = differenceInCalendarMonths;
const index_js_1 = require("../utils/index.js");
/**
* Difference in calendar months
*
* @param {Date} dateLeft - The later date
* @param {Date} dateRight - The earlier date
* @returns {number} The number of calendar months between the two dates
*/
function differenceInCalendarMonths(dateLeft, dateRight) {
const ethiopicLeft = (0, index_js_1.toEthiopicDate)(dateLeft);
const ethiopicRight = (0, index_js_1.toEthiopicDate)(dateRight);
return ((ethiopicLeft.year - ethiopicRight.year) * 13 +
(ethiopicLeft.month - ethiopicRight.month));
}
@@ -0,0 +1,11 @@
import type { Interval } from "date-fns";
/**
* Each month of an interval
*
* @param {Object} interval - The interval object
* @param {Date} interval.start - The start date of the interval
* @param {Date} interval.end - The end date of the interval
* @returns {Date[]} An array of dates representing the start of each month in
* the interval
*/
export declare function eachMonthOfInterval(interval: Interval): Date[];
@@ -0,0 +1,30 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.eachMonthOfInterval = eachMonthOfInterval;
const index_js_1 = require("../utils/index.js");
/**
* Each month of an interval
*
* @param {Object} interval - The interval object
* @param {Date} interval.start - The start date of the interval
* @param {Date} interval.end - The end date of the interval
* @returns {Date[]} An array of dates representing the start of each month in
* the interval
*/
function eachMonthOfInterval(interval) {
const start = (0, index_js_1.toEthiopicDate)(new Date(interval.start));
const end = (0, index_js_1.toEthiopicDate)(new Date(interval.end));
const dates = [];
let currentYear = start.year;
let currentMonth = start.month;
while (currentYear < end.year ||
(currentYear === end.year && currentMonth <= end.month)) {
dates.push((0, index_js_1.toGregorianDate)({ year: currentYear, month: currentMonth, day: 1 }));
currentMonth++;
if (currentMonth > 13) {
currentMonth = 1;
currentYear++;
}
}
return dates;
}
@@ -0,0 +1,7 @@
import type { Interval } from "date-fns";
/**
* Returns the start of each Ethiopic year included in the given interval.
*
* @param interval The interval whose years should be returned.
*/
export declare function eachYearOfInterval(interval: Interval): Date[];
@@ -0,0 +1,21 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.eachYearOfInterval = eachYearOfInterval;
const index_js_1 = require("../utils/index.js");
/**
* Returns the start of each Ethiopic year included in the given interval.
*
* @param interval The interval whose years should be returned.
*/
function eachYearOfInterval(interval) {
const start = (0, index_js_1.toEthiopicDate)(new Date(interval.start));
const end = (0, index_js_1.toEthiopicDate)(new Date(interval.end));
if (end.year < start.year) {
return [];
}
const years = [];
for (let year = start.year; year <= end.year; year += 1) {
years.push((0, index_js_1.toGregorianDate)({ year, month: 1, day: 1 }));
}
return years;
}
+8
View File
@@ -0,0 +1,8 @@
/**
* Returns the last day of the Ethiopian month for the given date.
*
* @param date - The gregorian date to get the end of month for
* @returns A new gregorian date representing the last day of the Ethiopian
* month
*/
export declare function endOfMonth(date: Date): Date;
+17
View File
@@ -0,0 +1,17 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.endOfMonth = endOfMonth;
const daysInMonth_js_1 = require("../utils/daysInMonth.js");
const index_js_1 = require("../utils/index.js");
/**
* Returns the last day of the Ethiopian month for the given date.
*
* @param date - The gregorian date to get the end of month for
* @returns A new gregorian date representing the last day of the Ethiopian
* month
*/
function endOfMonth(date) {
const { year, month } = (0, index_js_1.toEthiopicDate)(date);
const day = (0, daysInMonth_js_1.daysInMonth)(month, year);
return (0, index_js_1.toGregorianDate)({ year, month, day: day });
}
+9
View File
@@ -0,0 +1,9 @@
import { type EndOfWeekOptions } from "date-fns";
/**
* End of week
*
* @param {Date} date - The original date
* @param {EndOfWeekOptions} [options] - The options object
* @returns {Date} The end of the week
*/
export declare function endOfWeek(date: Date, options?: EndOfWeekOptions): Date;
+16
View File
@@ -0,0 +1,16 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.endOfWeek = endOfWeek;
const date_fns_1 = require("date-fns");
/**
* End of week
*
* @param {Date} date - The original date
* @param {EndOfWeekOptions} [options] - The options object
* @returns {Date} The end of the week
*/
function endOfWeek(date, options) {
const weekStartsOn = options?.weekStartsOn ?? 0; // Default to Monday (1)
const endOfWeek = (0, date_fns_1.endOfWeek)(date, { weekStartsOn });
return endOfWeek;
}
+7
View File
@@ -0,0 +1,7 @@
/**
* End of year
*
* @param {Date} date - The original date
* @returns {Date} The end of the year
*/
export declare function endOfYear(date: Date): Date;
+15
View File
@@ -0,0 +1,15 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.endOfYear = endOfYear;
const index_js_1 = require("../utils/index.js");
/**
* End of year
*
* @param {Date} date - The original date
* @returns {Date} The end of the year
*/
function endOfYear(date) {
const { year } = (0, index_js_1.toEthiopicDate)(date);
const day = (0, index_js_1.isEthiopicLeapYear)(year) ? 6 : 5;
return (0, index_js_1.toGregorianDate)({ year, month: 13, day });
}
+22
View File
@@ -0,0 +1,22 @@
import type { FormatOptions as DateFnsFormatOptions } from "date-fns";
/** Options for formatting dates in the Ethiopian calendar */
export type FormatOptions = DateFnsFormatOptions;
/**
* Format an Ethiopic calendar date using a subset of date-fns tokens.
*
* Behavior specifics for Ethiopic mode:
*
* - Weekday names ("cccc", "cccccc") come from `Intl.DateTimeFormat` using
* `options.locale?.code` (default: `am-ET`). Narrow form is a single letter.
* - Month names ("LLLL") are Amharic by default and switch to Latin
* transliteration when the locale code starts with `en` or when
* `options.numerals === 'latn'`.
* - Time parts such as `hh:mm a` are delegated to `Intl.DateTimeFormat` with the
* given locale.
* - Digits are converted to Ethiopic (Geez) when `options.numerals === 'geez'`.
*/
export declare function format(date: Date, formatStr: string, options?: DateFnsFormatOptions): string;
export declare const ethMonths: string[];
export declare const ethMonthsLatin: string[];
export declare const shortDays: string[];
export declare const longDays: string[];
+135
View File
@@ -0,0 +1,135 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.longDays = exports.shortDays = exports.ethMonthsLatin = exports.ethMonths = void 0;
exports.format = format;
const index_js_1 = require("../utils/index.js");
const formatNumber_js_1 = require("./formatNumber.js");
function getEtDayName(day, short = true, localeCode = "am-ET") {
try {
const dtf = new Intl.DateTimeFormat(localeCode, {
// Ethiopic calendar expects single-letter for "cccccc" -> use narrow
weekday: short ? "narrow" : "long",
});
return dtf.format(day);
}
catch {
const dayOfWeek = day.getDay();
return short ? exports.shortDays[dayOfWeek] : exports.longDays[dayOfWeek];
}
}
function getEtMonthName(m, latin = false) {
if (m > 0 && m <= 13) {
return latin ? exports.ethMonthsLatin[m - 1] : exports.ethMonths[m - 1];
}
return "";
}
function formatEthiopianDate(dateObj, formatStr, numerals, localeCode) {
const etDate = dateObj ? (0, index_js_1.toEthiopicDate)(dateObj) : undefined;
if (!etDate)
return "";
const useLatin = (localeCode?.startsWith("en") ?? false) || numerals === "latn";
const yearTokenMatch = formatStr.match(/^(\s*)(y+)(\s*)$/);
if (yearTokenMatch) {
const [, leading = "", yearToken, trailing = ""] = yearTokenMatch;
const year = etDate.year.toString();
let formattedYear;
if (yearToken.length === 1) {
formattedYear = year;
}
else if (yearToken.length === 2) {
formattedYear = year.slice(-2).padStart(2, "0");
}
else {
formattedYear = year.padStart(yearToken.length, "0");
}
return `${leading}${formattedYear}${trailing}`;
}
switch (formatStr) {
case "LLLL yyyy":
case "LLLL y":
return `${getEtMonthName(etDate.month, useLatin)} ${etDate.year}`;
case "LLLL":
return getEtMonthName(etDate.month, useLatin);
case "yyyy-MM-dd":
return `${etDate.year}-${etDate.month
.toString()
.padStart(2, "0")}-${etDate.day.toString().padStart(2, "0")}`;
case "yyyy-MM":
return `${etDate.year}-${etDate.month.toString().padStart(2, "0")}`;
case "d":
return etDate.day.toString();
case "PPP":
return ` ${getEtMonthName(etDate.month, useLatin)} ${etDate.day}, ${etDate.year}`;
case "PPPP":
if (!dateObj)
return "";
return `${getEtDayName(dateObj, false, localeCode)}, ${getEtMonthName(etDate.month, useLatin)} ${etDate.day}, ${etDate.year}`;
case "cccc":
return dateObj ? getEtDayName(dateObj, false, localeCode) : "";
case "cccccc":
return dateObj ? getEtDayName(dateObj, true, localeCode) : "";
default:
return `${etDate.day}/${etDate.month}/${etDate.year}`;
}
}
/**
* Format an Ethiopic calendar date using a subset of date-fns tokens.
*
* Behavior specifics for Ethiopic mode:
*
* - Weekday names ("cccc", "cccccc") come from `Intl.DateTimeFormat` using
* `options.locale?.code` (default: `am-ET`). Narrow form is a single letter.
* - Month names ("LLLL") are Amharic by default and switch to Latin
* transliteration when the locale code starts with `en` or when
* `options.numerals === 'latn'`.
* - Time parts such as `hh:mm a` are delegated to `Intl.DateTimeFormat` with the
* given locale.
* - Digits are converted to Ethiopic (Geez) when `options.numerals === 'geez'`.
*/
function format(date, formatStr, options) {
const extendedOptions = options;
if (formatStr.includes("hh:mm") || formatStr.includes("a")) {
return new Intl.DateTimeFormat(extendedOptions?.locale?.code ?? "en-US", {
hour: "numeric",
minute: "numeric",
hour12: formatStr.includes("a"),
}).format(date);
}
const formatted = formatEthiopianDate(date, formatStr, extendedOptions?.numerals, extendedOptions?.locale?.code ?? "am-ET");
if (extendedOptions?.numerals && extendedOptions.numerals === "geez") {
return formatted.replace(/\d+/g, (match) => (0, formatNumber_js_1.formatNumber)(parseInt(match, 10), "geez"));
}
return formatted;
}
exports.ethMonths = [
"መስከረም",
"ጥቅምት",
"ህዳር",
"ታህሳስ",
"ጥር",
"የካቲት",
"መጋቢት",
"ሚያዚያ",
"ግንቦት",
"ሰኔ",
"ሐምሌ",
"ነሀሴ",
"ጳጉሜ",
];
exports.ethMonthsLatin = [
"Meskerem",
"Tikimt",
"Hidar",
"Tahsas",
"Tir",
"Yekatit",
"Megabit",
"Miyazya",
"Ginbot",
"Sene",
"Hamle",
"Nehase",
"Pagumen",
];
exports.shortDays = ["እ", "ሰ", "ማ", "ረ", "ሐ", "ዓ", "ቅ"];
exports.longDays = ["እሁድ", "ሰኞ", "ማክሰኞ", "ረቡዕ", "ሐሙስ", "ዓርብ", "ቅዳሜ"];
+19
View File
@@ -0,0 +1,19 @@
/**
* Formats a number using either Latin or Ethiopic (Geez) numerals
*
* @example
* ```ts
* formatNumber(123) // '123'
* formatNumber(123, 'geez') // '፻፳፫'
* formatNumber(2023, 'geez') // '፳፻፳፫'
* ```;
*
* @param value - The number to format
* @param numerals - The numeral system to use:
*
* - 'latn': Latin numerals (1, 2, 3...)
* - 'geez': Ethiopic numerals (፩, ፪, ፫...)
*
* @returns The formatted number string
*/
export declare function formatNumber(value: number, numerals?: string): string;
+32
View File
@@ -0,0 +1,32 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatNumber = formatNumber;
const toGeezNumerals_js_1 = require("../utils/toGeezNumerals.js");
/**
* Formats a number using either Latin or Ethiopic (Geez) numerals
*
* @example
* ```ts
* formatNumber(123) // '123'
* formatNumber(123, 'geez') // '፻፳፫'
* formatNumber(2023, 'geez') // '፳፻፳፫'
* ```;
*
* @param value - The number to format
* @param numerals - The numeral system to use:
*
* - 'latn': Latin numerals (1, 2, 3...)
* - 'geez': Ethiopic numerals (፩, ፪, ፫...)
*
* @returns The formatted number string
*/
function formatNumber(value, numerals = "latn") {
if (numerals === "geez") {
return (0, toGeezNumerals_js_1.toGeezNumerals)(value);
}
// Use Intl.NumberFormat for other numeral systems
const formatter = new Intl.NumberFormat("en-US", {
numberingSystem: numerals,
});
return formatter.format(value);
}
+7
View File
@@ -0,0 +1,7 @@
/**
* Get month
*
* @param {Date} date - The original date
* @returns {number} The zero-based month index
*/
export declare function getMonth(date: Date): number;
+14
View File
@@ -0,0 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getMonth = getMonth;
const index_js_1 = require("../utils/index.js");
/**
* Get month
*
* @param {Date} date - The original date
* @returns {number} The zero-based month index
*/
function getMonth(date) {
const { month } = (0, index_js_1.toEthiopicDate)(date);
return month - 1; // Return zero-based month index
}
+9
View File
@@ -0,0 +1,9 @@
import { type GetWeekOptions } from "date-fns";
/**
* Get week number for Ethiopian calendar
*
* @param {Date} date - The original date
* @param {GetWeekOptions} [options] - The options object
* @returns {number} The week number
*/
export declare function getWeek(date: Date, options?: GetWeekOptions): number;
+44
View File
@@ -0,0 +1,44 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getWeek = getWeek;
const date_fns_1 = require("date-fns");
const index_js_1 = require("../utils/index.js");
const startOfWeek_js_1 = require("./startOfWeek.js");
/**
* Get week number for Ethiopian calendar
*
* @param {Date} date - The original date
* @param {GetWeekOptions} [options] - The options object
* @returns {number} The week number
*/
function getWeek(date, options) {
const weekStartsOn = options?.weekStartsOn ?? 1; // Default to Monday (1)
const etDate = (0, index_js_1.toEthiopicDate)(date);
const currentWeekStart = (0, startOfWeek_js_1.startOfWeek)(date, { weekStartsOn });
// Get the first day of the current year
const firstDayOfYear = (0, index_js_1.toGregorianDate)({
year: etDate.year,
month: 1,
day: 1,
});
const firstWeekStart = (0, startOfWeek_js_1.startOfWeek)(firstDayOfYear, { weekStartsOn });
// If date is before the first week of its year
if (date < firstWeekStart) {
return (0, date_fns_1.getWeek)(date, { weekStartsOn, firstWeekContainsDate: 1 });
}
// If date falls into the first week of the NEXT Ethiopic year, return 1
const nextYearFirstDay = (0, index_js_1.toGregorianDate)({
year: etDate.year + 1,
month: 1,
day: 1,
});
const nextYearFirstWeekStart = (0, startOfWeek_js_1.startOfWeek)(nextYearFirstDay, {
weekStartsOn,
});
if (date >= nextYearFirstWeekStart) {
return 1;
}
// Calculate week number based on days since first week
const daysSinceFirstWeek = (0, date_fns_1.differenceInDays)(currentWeekStart, firstWeekStart);
return Math.floor(daysSinceFirstWeek / 7) + 1;
}
+7
View File
@@ -0,0 +1,7 @@
/**
* Get year
*
* @param {Date} date - The original date
* @returns {number} The year
*/
export declare function getYear(date: Date): number;
+14
View File
@@ -0,0 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getYear = getYear;
const index_js_1 = require("../utils/index.js");
/**
* Get year
*
* @param {Date} date - The original date
* @returns {number} The year
*/
function getYear(date) {
const { year } = (0, index_js_1.toEthiopicDate)(date);
return year;
}
+22
View File
@@ -0,0 +1,22 @@
export * from "./addMonths.js";
export * from "./addYears.js";
export * from "./differenceInCalendarMonths.js";
export * from "./eachMonthOfInterval.js";
export * from "./eachYearOfInterval.js";
export * from "./endOfMonth.js";
export * from "./endOfWeek.js";
export * from "./endOfYear.js";
export * from "./format.js";
export * from "./formatNumber.js";
export * from "./getMonth.js";
export * from "./getWeek.js";
export * from "./getYear.js";
export * from "./isSameMonth.js";
export * from "./isSameYear.js";
export * from "./newDate.js";
export * from "./setMonth.js";
export * from "./setYear.js";
export * from "./startOfDay.js";
export * from "./startOfMonth.js";
export * from "./startOfWeek.js";
export * from "./startOfYear.js";
+38
View File
@@ -0,0 +1,38 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./addMonths.js"), exports);
__exportStar(require("./addYears.js"), exports);
__exportStar(require("./differenceInCalendarMonths.js"), exports);
__exportStar(require("./eachMonthOfInterval.js"), exports);
__exportStar(require("./eachYearOfInterval.js"), exports);
__exportStar(require("./endOfMonth.js"), exports);
__exportStar(require("./endOfWeek.js"), exports);
__exportStar(require("./endOfYear.js"), exports);
__exportStar(require("./format.js"), exports);
__exportStar(require("./formatNumber.js"), exports);
__exportStar(require("./getMonth.js"), exports);
__exportStar(require("./getWeek.js"), exports);
__exportStar(require("./getYear.js"), exports);
__exportStar(require("./isSameMonth.js"), exports);
__exportStar(require("./isSameYear.js"), exports);
__exportStar(require("./newDate.js"), exports);
__exportStar(require("./setMonth.js"), exports);
__exportStar(require("./setYear.js"), exports);
__exportStar(require("./startOfDay.js"), exports);
__exportStar(require("./startOfMonth.js"), exports);
__exportStar(require("./startOfWeek.js"), exports);
__exportStar(require("./startOfYear.js"), exports);
+8
View File
@@ -0,0 +1,8 @@
/**
* Is same month
*
* @param {Date} dateLeft - The first date
* @param {Date} dateRight - The second date
* @returns {boolean} True if the two dates are in the same month
*/
export declare function isSameMonth(dateLeft: Date, dateRight: Date): boolean;
+16
View File
@@ -0,0 +1,16 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isSameMonth = isSameMonth;
const index_js_1 = require("../utils/index.js");
/**
* Is same month
*
* @param {Date} dateLeft - The first date
* @param {Date} dateRight - The second date
* @returns {boolean} True if the two dates are in the same month
*/
function isSameMonth(dateLeft, dateRight) {
const left = (0, index_js_1.toEthiopicDate)(dateLeft);
const right = (0, index_js_1.toEthiopicDate)(dateRight);
return left.year === right.year && left.month === right.month;
}
+8
View File
@@ -0,0 +1,8 @@
/**
* Checks if two dates fall in the same Ethiopian year.
*
* @param dateLeft - The first gregorian date to compare
* @param dateRight - The second gregorian date to compare
* @returns True if the dates are in the same Ethiopian year
*/
export declare function isSameYear(dateLeft: Date, dateRight: Date): boolean;
+16
View File
@@ -0,0 +1,16 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isSameYear = isSameYear;
const index_js_1 = require("../utils/index.js");
/**
* Checks if two dates fall in the same Ethiopian year.
*
* @param dateLeft - The first gregorian date to compare
* @param dateRight - The second gregorian date to compare
* @returns True if the dates are in the same Ethiopian year
*/
function isSameYear(dateLeft, dateRight) {
const left = (0, index_js_1.toEthiopicDate)(dateLeft);
const right = (0, index_js_1.toEthiopicDate)(dateRight);
return left.year === right.year;
}
+9
View File
@@ -0,0 +1,9 @@
/**
* Creates a new Ethiopic date
*
* @param {number} year - The year of the Ethiopic date
* @param {number} monthIndex - The zero-based month index of the Ethiopic date
* @param {number} date - The day of the month of the Ethiopic date
* @returns {Date} The corresponding Gregorian date
*/
export declare function newDate(year: number, monthIndex: number, date: number): Date;
+25
View File
@@ -0,0 +1,25 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.newDate = newDate;
const index_js_1 = require("../utils/index.js");
const isEthiopicDateValid_js_1 = require("../utils/isEthiopicDateValid.js");
/**
* Creates a new Ethiopic date
*
* @param {number} year - The year of the Ethiopic date
* @param {number} monthIndex - The zero-based month index of the Ethiopic date
* @param {number} date - The day of the month of the Ethiopic date
* @returns {Date} The corresponding Gregorian date
*/
function newDate(year, monthIndex, date) {
// Convert from 0-based month index to 1-based Ethiopic month
const month = monthIndex + 1;
if (!(0, isEthiopicDateValid_js_1.isEthiopicDateValid)({ year, month, day: date })) {
throw new Error("Invalid Ethiopic date");
}
return (0, index_js_1.toGregorianDate)({
year: year,
month: month,
day: date,
});
}
+8
View File
@@ -0,0 +1,8 @@
/**
* Set month
*
* @param {Date} date - The original date
* @param {number} month - The zero-based month index
* @returns {Date} The new date with the month set
*/
export declare function setMonth(date: Date, month: number): Date;
+17
View File
@@ -0,0 +1,17 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.setMonth = setMonth;
const index_js_1 = require("../utils/index.js");
/**
* Set month
*
* @param {Date} date - The original date
* @param {number} month - The zero-based month index
* @returns {Date} The new date with the month set
*/
function setMonth(date, month) {
const { year, day } = (0, index_js_1.toEthiopicDate)(date);
const targetMonth = month + 1; // Convert from zero-based index
const safeDay = Math.min(day, (0, index_js_1.daysInMonth)(targetMonth, year));
return (0, index_js_1.toGregorianDate)({ year, month: targetMonth, day: safeDay });
}
+8
View File
@@ -0,0 +1,8 @@
/**
* Set year
*
* @param {Date} date - The original date
* @param {number} year - The year to set
* @returns {Date} The new date with the year set
*/
export declare function setYear(date: Date, year: number): Date;
+19
View File
@@ -0,0 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.setYear = setYear;
const daysInMonth_js_1 = require("../utils/daysInMonth.js");
const index_js_1 = require("../utils/index.js");
/**
* Set year
*
* @param {Date} date - The original date
* @param {number} year - The year to set
* @returns {Date} The new date with the year set
*/
function setYear(date, year) {
const { month, day } = (0, index_js_1.toEthiopicDate)(date);
// Check if the day is valid in the new year (handles leap year changes)
const maxDays = (0, daysInMonth_js_1.daysInMonth)(month, year);
const newDay = Math.min(day, maxDays);
return (0, index_js_1.toGregorianDate)({ year, month, day: newDay });
}
+7
View File
@@ -0,0 +1,7 @@
/**
* Start of day
*
* @param {Date} date - The original date
* @returns {Date} The start of the day
*/
export declare function startOfDay(date: Date): Date;
+14
View File
@@ -0,0 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.startOfDay = startOfDay;
const index_js_1 = require("../utils/index.js");
/**
* Start of day
*
* @param {Date} date - The original date
* @returns {Date} The start of the day
*/
function startOfDay(date) {
const { year, month, day } = (0, index_js_1.toEthiopicDate)(date);
return (0, index_js_1.toGregorianDate)({ year, month, day });
}
@@ -0,0 +1,7 @@
/**
* Start of month
*
* @param {Date} date - The original date
* @returns {Date} The start of the month
*/
export declare function startOfMonth(date: Date): Date;
+14
View File
@@ -0,0 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.startOfMonth = startOfMonth;
const index_js_1 = require("../utils/index.js");
/**
* Start of month
*
* @param {Date} date - The original date
* @returns {Date} The start of the month
*/
function startOfMonth(date) {
const { year, month } = (0, index_js_1.toEthiopicDate)(date);
return (0, index_js_1.toGregorianDate)({ year, month, day: 1 });
}
+9
View File
@@ -0,0 +1,9 @@
import { type StartOfWeekOptions } from "date-fns";
/**
* Start of week
*
* @param {Date} date - The original date
* @param {StartOfWeekOptions} [options] - The options object
* @returns {Date} The start of the week
*/
export declare function startOfWeek(date: Date, options?: StartOfWeekOptions): Date;
+15
View File
@@ -0,0 +1,15 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.startOfWeek = startOfWeek;
const date_fns_1 = require("date-fns");
/**
* Start of week
*
* @param {Date} date - The original date
* @param {StartOfWeekOptions} [options] - The options object
* @returns {Date} The start of the week
*/
function startOfWeek(date, options) {
const weekStartsOn = options?.weekStartsOn ?? 1; // Default to Monday (1)
return (0, date_fns_1.startOfWeek)(date, { weekStartsOn: weekStartsOn });
}
+7
View File
@@ -0,0 +1,7 @@
/**
* Start of year
*
* @param {Date} date - The original date
* @returns {Date} The start of the year
*/
export declare function startOfYear(date: Date): Date;
+14
View File
@@ -0,0 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.startOfYear = startOfYear;
const index_js_1 = require("../utils/index.js");
/**
* Start of year
*
* @param {Date} date - The original date
* @returns {Date} The start of the year
*/
function startOfYear(date) {
const { year } = (0, index_js_1.toEthiopicDate)(date);
return (0, index_js_1.toGregorianDate)({ year, month: 1, day: 1 });
}
@@ -0,0 +1,17 @@
/**
* Represents a date in the Ethiopic calendar system.
*
* The Ethiopic calendar has:
*
* - 13 months
* - 12 months of 30 days each
* - A 13th month (Pagume) of 5 or 6 days
*/
export interface EthiopicDate {
/** The Ethiopic year */
year: number;
/** The month number (1-13) */
month: number;
/** The day of the month (1-30, or 1-5/6 for month 13) */
day: number;
}
@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
+13
View File
@@ -0,0 +1,13 @@
/**
* Returns the number of days in the specified month of the Ethiopic calendar.
*
* In the Ethiopic calendar:
*
* - Months 1-12 have 30 days each
* - Month 13 (Pagume) has 5 days in regular years, 6 days in leap years
*
* @param month - The month number (1-13)
* @param year - The Ethiopic year
* @returns The number of days in the specified month
*/
export declare function daysInMonth(month: number, year: number): number;
+22
View File
@@ -0,0 +1,22 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.daysInMonth = daysInMonth;
const isEthiopicLeapYear_js_1 = require("./isEthiopicLeapYear.js");
/**
* Returns the number of days in the specified month of the Ethiopic calendar.
*
* In the Ethiopic calendar:
*
* - Months 1-12 have 30 days each
* - Month 13 (Pagume) has 5 days in regular years, 6 days in leap years
*
* @param month - The month number (1-13)
* @param year - The Ethiopic year
* @returns The number of days in the specified month
*/
function daysInMonth(month, year) {
if (month === 13) {
return (0, isEthiopicLeapYear_js_1.isEthiopicLeapYear)(year) ? 6 : 5;
}
return 30;
}
+6
View File
@@ -0,0 +1,6 @@
export * from "./daysInMonth.js";
export * from "./EthiopicDate.js";
export * from "./isEthiopicLeapYear.js";
export * from "./toEthiopicDate.js";
export * from "./toGeezNumerals.js";
export * from "./toGregorianDate.js";
+22
View File
@@ -0,0 +1,22 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./daysInMonth.js"), exports);
__exportStar(require("./EthiopicDate.js"), exports);
__exportStar(require("./isEthiopicLeapYear.js"), exports);
__exportStar(require("./toEthiopicDate.js"), exports);
__exportStar(require("./toGeezNumerals.js"), exports);
__exportStar(require("./toGregorianDate.js"), exports);
@@ -0,0 +1,2 @@
import type { EthiopicDate } from "./EthiopicDate.js";
export declare function isEthiopicDateValid(date: EthiopicDate): boolean;
@@ -0,0 +1,15 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isEthiopicDateValid = isEthiopicDateValid;
const daysInMonth_js_1 = require("./daysInMonth.js");
function isEthiopicDateValid(date) {
if (date.month < 1)
return false;
if (date.day < 1)
return false;
if (date.month > 13)
return false;
if (date.day > (0, daysInMonth_js_1.daysInMonth)(date.month, date.year))
return false;
return true;
}
@@ -0,0 +1,7 @@
/**
* Checks if a given Ethiopic year is a leap year.
*
* @param year - The Ethiopic year.
* @returns True if the year is a leap year; otherwise, false.
*/
export declare function isEthiopicLeapYear(year: number): boolean;
@@ -0,0 +1,12 @@
"use strict";
/**
* Checks if a given Ethiopic year is a leap year.
*
* @param year - The Ethiopic year.
* @returns True if the year is a leap year; otherwise, false.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.isEthiopicLeapYear = isEthiopicLeapYear;
function isEthiopicLeapYear(year) {
return year % 4 === 3;
}
@@ -0,0 +1,17 @@
import type { EthiopicDate } from "./EthiopicDate.js";
/**
* Calculates the number of days between January 1, 0001 and the given date.
*
* @param date - A JavaScript Date object to calculate days from
* @returns The number of days since January 1, 0001. Returns 0 if the input is
* not a valid Date.
*/
export declare function getDayNoGregorian(date: Date): number;
/**
* Converts a Gregorian date to an Ethiopic date.
*
* @param gregorianDate - A JavaScript Date object representing the Gregorian
* date.
* @returns An EthiopicDate object.
*/
export declare function toEthiopicDate(gregorianDate: Date): EthiopicDate;
@@ -0,0 +1,54 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getDayNoGregorian = getDayNoGregorian;
exports.toEthiopicDate = toEthiopicDate;
const date_fns_1 = require("date-fns");
/**
* Calculates the number of days between January 1, 0001 and the given date.
*
* @param date - A JavaScript Date object to calculate days from
* @returns The number of days since January 1, 0001. Returns 0 if the input is
* not a valid Date.
*/
function getDayNoGregorian(date) {
if (!(date instanceof Date)) {
return 0;
}
// Create the start date as January 1, 0001 in the LOCAL timezone.
const adStart = new Date(0);
adStart.setFullYear(1, 0, 1);
adStart.setHours(0, 0, 0, 0);
// Calculate the number of days between the two dates, then add 1.
const dayNumber = (0, date_fns_1.differenceInCalendarDays)(date, adStart) + 1;
return dayNumber;
}
function createEthiopicDate(dn) {
const num = Math.floor(dn / 1461);
const num2 = dn % 1461;
const num3 = Math.floor(num2 / 365);
const num4 = num2 % 365;
if (num2 !== 1460) {
return {
year: num * 4 + num3,
month: Math.floor(num4 / 30) + 1,
day: (num4 % 30) + 1,
};
}
else {
return {
year: num * 4 + num3 - 1,
month: 13,
day: 6,
};
}
}
/**
* Converts a Gregorian date to an Ethiopic date.
*
* @param gregorianDate - A JavaScript Date object representing the Gregorian
* date.
* @returns An EthiopicDate object.
*/
function toEthiopicDate(gregorianDate) {
return createEthiopicDate(getDayNoGregorian(gregorianDate) - 2431);
}
@@ -0,0 +1,8 @@
/**
* Converts a number to Geez (Ethiopic) numerals.
*
* @param num - The number to convert
* @returns The number in Geez numerals
* @throws {Error} When input is 0 (Geez has no zero representation)
*/
export declare function toGeezNumerals(num: number): string;
@@ -0,0 +1,51 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.toGeezNumerals = toGeezNumerals;
/**
* Converts a number to Geez (Ethiopic) numerals.
*
* @param num - The number to convert
* @returns The number in Geez numerals
* @throws {Error} When input is 0 (Geez has no zero representation)
*/
function toGeezNumerals(num) {
const geezDigits = ["፩", "፪", "፫", "፬", "፭", "፮", "፯", "፰", "፱"];
const geezTens = ["፲", "፳", "፴", "፵", "፶", "፷", "፸", "፹", "፺"];
const geezHundreds = "፻";
const geezThousands = "፼";
if (num === 0)
return "-";
if (num < 0)
return `-${toGeezNumerals(-num)}`;
let result = "";
let remaining = num;
// Handle thousands (10,000 and above)
if (remaining >= 10000) {
const thousandsValue = Math.floor(remaining / 10000);
result +=
thousandsValue === 1
? geezThousands
: toGeezNumerals(thousandsValue) + geezThousands;
remaining %= 10000;
}
// Handle hundreds (100 - 9,900)
if (remaining >= 100) {
const hundredsValue = Math.floor(remaining / 100);
result +=
hundredsValue === 1
? geezHundreds
: toGeezNumerals(hundredsValue) + geezHundreds;
remaining %= 100;
}
// Handle tens (10 - 90)
if (remaining >= 10) {
const tensValue = Math.floor(remaining / 10);
result += geezTens[tensValue - 1];
remaining %= 10;
}
// Handle ones (1 - 9)
if (remaining > 0) {
result += geezDigits[remaining - 1];
}
return result;
}
@@ -0,0 +1,9 @@
import type { EthiopicDate } from "./EthiopicDate.js";
export declare function getDayNoEthiopian(etDate: EthiopicDate): number;
/**
* Converts an Ethiopic date to a Gregorian date.
*
* @param ethiopicDate - An EthiopicDate object.
* @returns A JavaScript Date object representing the Gregorian date.
*/
export declare function toGregorianDate(ethiopicDate: EthiopicDate): Date;
@@ -0,0 +1,59 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getDayNoEthiopian = getDayNoEthiopian;
exports.toGregorianDate = toGregorianDate;
const date_fns_1 = require("date-fns");
const isEthiopicDateValid_js_1 = require("./isEthiopicDateValid.js");
function getDayNoEthiopian(etDate) {
const num = Math.floor(etDate.year / 4);
const num2 = etDate.year % 4;
return num * 1461 + num2 * 365 + (etDate.month - 1) * 30 + etDate.day - 1;
}
function gregorianDateFromDayNo(dayNum) {
let year = 1, month = 1, day;
const num400 = Math.floor(dayNum / 146097); // number of full 400-year periods
dayNum %= 146097;
if (dayNum === 0) {
return new Date(400 * num400, 12 - 1, 31);
}
const num100 = Math.min(Math.floor(dayNum / 36524), 3); // number of full 100-year periods, but not more than 3
dayNum -= num100 * 36524;
if (dayNum === 0) {
return new Date(400 * num400 + 100 * num100, 12 - 1, 31);
}
const num4 = Math.floor(dayNum / 1461); // number of full 4-year periods
dayNum %= 1461;
if (dayNum === 0) {
return new Date(400 * num400 + 100 * num100 + 4 * num4, 12 - 1, 31);
}
const num1 = Math.min(Math.floor(dayNum / 365), 3); // number of full years, but not more than 3
dayNum -= num1 * 365;
if (dayNum === 0) {
return new Date(400 * num400 + 100 * num100 + 4 * num4 + num1, 12 - 1, 31);
}
year += 400 * num400 + 100 * num100 + 4 * num4 + num1;
while (dayNum > 0) {
const tempDate = new Date(year, month - 1);
const daysInMonth = (0, date_fns_1.getDaysInMonth)(tempDate);
if (dayNum <= daysInMonth) {
day = dayNum;
break;
}
dayNum -= daysInMonth;
month++;
}
// Remember in JavaScript Date object, months are 0-based.
return new Date(year, month - 1, day);
}
/**
* Converts an Ethiopic date to a Gregorian date.
*
* @param ethiopicDate - An EthiopicDate object.
* @returns A JavaScript Date object representing the Gregorian date.
*/
function toGregorianDate(ethiopicDate) {
if (!(0, isEthiopicDateValid_js_1.isEthiopicDateValid)(ethiopicDate)) {
throw new Error("Invalid Ethiopic date");
}
return gregorianDateFromDayNo(getDayNoEthiopian(ethiopicDate) + 2431);
}