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
@@ -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);
}