deploy: v0.12 存档迁移+考古日志滚动条

This commit is contained in:
2026-06-24 03:04:38 +00:00
parent 4831505ef9
commit b4c6111516
58986 changed files with 7569452 additions and 31667 deletions
+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 });
}