mirror of
https://github.com/acamarata/temporal-hijri.git
synced 2026-06-30 19:04:29 +00:00
ci: format all files with prettier to fix format:check
This commit is contained in:
parent
40478b6f7b
commit
70bd956179
9 changed files with 145 additions and 145 deletions
|
|
@ -1,20 +1,20 @@
|
|||
import tsParser from '@typescript-eslint/parser';
|
||||
import tsPlugin from '@typescript-eslint/eslint-plugin';
|
||||
import eslintConfigPrettier from 'eslint-config-prettier';
|
||||
import { typescript } from '@acamarata/eslint-config';
|
||||
import tsParser from "@typescript-eslint/parser";
|
||||
import tsPlugin from "@typescript-eslint/eslint-plugin";
|
||||
import eslintConfigPrettier from "eslint-config-prettier";
|
||||
import { typescript } from "@acamarata/eslint-config";
|
||||
|
||||
export default [
|
||||
{
|
||||
files: ['**/*.ts'],
|
||||
plugins: { '@typescript-eslint': tsPlugin },
|
||||
files: ["**/*.ts"],
|
||||
plugins: { "@typescript-eslint": tsPlugin },
|
||||
languageOptions: {
|
||||
parser: tsParser,
|
||||
parserOptions: { project: true, tsconfigRootDir: import.meta.dirname },
|
||||
},
|
||||
},
|
||||
...typescript.map((config) => ({ files: ['**/*.ts'], ...config })),
|
||||
...typescript.map((config) => ({ files: ["**/*.ts"], ...config })),
|
||||
eslintConfigPrettier,
|
||||
{
|
||||
ignores: ['dist/', 'node_modules/', 'test.mjs', 'test-cjs.cjs'],
|
||||
ignores: ["dist/", "node_modules/", "test.mjs", "test-cjs.cjs"],
|
||||
},
|
||||
];
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { getCalendar } from 'hijri-core';
|
||||
import { HijriCalendar } from './HijriCalendar';
|
||||
import { getCalendar } from "hijri-core";
|
||||
import { HijriCalendar } from "./HijriCalendar";
|
||||
|
||||
/**
|
||||
* Temporal calendar implementation for the FCNA/ISNA calendar.
|
||||
|
|
@ -17,6 +17,6 @@ import { HijriCalendar } from './HijriCalendar';
|
|||
*/
|
||||
export class FcnaCalendar extends HijriCalendar {
|
||||
constructor() {
|
||||
super(getCalendar('fcna'));
|
||||
super(getCalendar("fcna"));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { Temporal } from '@js-temporal/polyfill';
|
||||
import type { CalendarEngine } from 'hijri-core';
|
||||
import { Temporal } from "@js-temporal/polyfill";
|
||||
import type { CalendarEngine } from "hijri-core";
|
||||
|
||||
type DateUnit = 'year' | 'years' | 'month' | 'months' | 'week' | 'weeks' | 'day' | 'days';
|
||||
type DateUnit = "year" | "years" | "month" | "months" | "week" | "weeks" | "day" | "days";
|
||||
|
||||
/** Reference year for monthDay construction when no year is specified. */
|
||||
const REFERENCE_YEAR = 1444;
|
||||
|
|
@ -109,8 +109,8 @@ export class HijriCalendar {
|
|||
* Resolve the overflow option from a Temporal options bag.
|
||||
* Returns 'constrain' (the default) or 'reject'.
|
||||
*/
|
||||
private resolveOverflow(options?: { overflow?: 'constrain' | 'reject' }): 'constrain' | 'reject' {
|
||||
return options?.overflow ?? 'constrain';
|
||||
private resolveOverflow(options?: { overflow?: "constrain" | "reject" }): "constrain" | "reject" {
|
||||
return options?.overflow ?? "constrain";
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -120,9 +120,9 @@ export class HijriCalendar {
|
|||
day: number,
|
||||
maxDay: number,
|
||||
month: number,
|
||||
overflow: 'constrain' | 'reject',
|
||||
overflow: "constrain" | "reject",
|
||||
): number {
|
||||
if (overflow === 'reject' && day > maxDay) {
|
||||
if (overflow === "reject" && day > maxDay) {
|
||||
throw new RangeError(`Day ${day} exceeds ${maxDay} days in month ${month}`);
|
||||
}
|
||||
return Math.min(day, maxDay);
|
||||
|
|
@ -157,7 +157,7 @@ export class HijriCalendar {
|
|||
*/
|
||||
monthCode(date: Temporal.PlainDate): string {
|
||||
const { hm } = this.toHijri(date);
|
||||
return `M${String(hm).padStart(2, '0')}`;
|
||||
return `M${String(hm).padStart(2, "0")}`;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -278,7 +278,7 @@ export class HijriCalendar {
|
|||
|
||||
dateFromFields(
|
||||
fields: { year: number; month: number; day: number },
|
||||
options?: { overflow?: 'constrain' | 'reject' },
|
||||
options?: { overflow?: "constrain" | "reject" },
|
||||
): Temporal.PlainDate {
|
||||
const overflow = this.resolveOverflow(options);
|
||||
const maxDay = this.engine.daysInMonth(fields.year, fields.month);
|
||||
|
|
@ -293,12 +293,12 @@ export class HijriCalendar {
|
|||
*/
|
||||
yearMonthFromFields(
|
||||
fields: { year: number; month: number },
|
||||
options?: { overflow?: 'constrain' | 'reject' },
|
||||
options?: { overflow?: "constrain" | "reject" },
|
||||
): Temporal.PlainYearMonth {
|
||||
const overflow = this.resolveOverflow(options);
|
||||
// Clamp month to 1-12 or reject.
|
||||
const maxMonth = 12;
|
||||
if (overflow === 'reject' && (fields.month < 1 || fields.month > maxMonth)) {
|
||||
if (overflow === "reject" && (fields.month < 1 || fields.month > maxMonth)) {
|
||||
throw new RangeError(`Month ${fields.month} is out of range 1-${maxMonth}`);
|
||||
}
|
||||
const month = Math.max(1, Math.min(fields.month, maxMonth));
|
||||
|
|
@ -316,7 +316,7 @@ export class HijriCalendar {
|
|||
*/
|
||||
monthDayFromFields(
|
||||
fields: { month: number; day: number; year?: number },
|
||||
options?: { overflow?: 'constrain' | 'reject' },
|
||||
options?: { overflow?: "constrain" | "reject" },
|
||||
): Temporal.PlainMonthDay {
|
||||
const overflow = this.resolveOverflow(options);
|
||||
const year = fields.year ?? REFERENCE_YEAR;
|
||||
|
|
@ -346,7 +346,7 @@ export class HijriCalendar {
|
|||
dateAdd(
|
||||
date: Temporal.PlainDate,
|
||||
duration: Temporal.Duration,
|
||||
_options?: { overflow?: 'constrain' | 'reject' },
|
||||
_options?: { overflow?: "constrain" | "reject" },
|
||||
): Temporal.PlainDate {
|
||||
const { hy, hm, hd } = this.toHijri(date);
|
||||
|
||||
|
|
@ -386,16 +386,16 @@ export class HijriCalendar {
|
|||
two: Temporal.PlainDate,
|
||||
options?: { largestUnit?: DateUnit },
|
||||
): Temporal.Duration {
|
||||
const largestUnit: DateUnit = options?.largestUnit ?? 'days';
|
||||
const largestUnit: DateUnit = options?.largestUnit ?? "days";
|
||||
|
||||
if (largestUnit === 'years' || largestUnit === 'year') {
|
||||
if (largestUnit === "years" || largestUnit === "year") {
|
||||
const h1 = this.toHijri(one);
|
||||
const h2 = this.toHijri(two);
|
||||
const diff = borrowHijriDiff(this.engine, h2.hy - h1.hy, h2.hm - h1.hm, h2.hd - h1.hd, h2);
|
||||
return new Temporal.Duration(diff.years, diff.months, 0, diff.days);
|
||||
}
|
||||
|
||||
if (largestUnit === 'months' || largestUnit === 'month') {
|
||||
if (largestUnit === "months" || largestUnit === "month") {
|
||||
const h1 = this.toHijri(one);
|
||||
const h2 = this.toHijri(two);
|
||||
const diff = borrowHijriDiff(this.engine, h2.hy - h1.hy, h2.hm - h1.hm, h2.hd - h1.hd, h2);
|
||||
|
|
@ -404,11 +404,11 @@ export class HijriCalendar {
|
|||
}
|
||||
|
||||
// For weeks and days, delegate to ISO arithmetic which is exact.
|
||||
if (largestUnit === 'weeks' || largestUnit === 'week') {
|
||||
return one.until(two, { largestUnit: 'weeks' });
|
||||
if (largestUnit === "weeks" || largestUnit === "week") {
|
||||
return one.until(two, { largestUnit: "weeks" });
|
||||
}
|
||||
|
||||
return one.until(two, { largestUnit: 'days' });
|
||||
return one.until(two, { largestUnit: "days" });
|
||||
}
|
||||
|
||||
mergeFields(
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { getCalendar } from 'hijri-core';
|
||||
import { HijriCalendar } from './HijriCalendar';
|
||||
import { getCalendar } from "hijri-core";
|
||||
import { HijriCalendar } from "./HijriCalendar";
|
||||
|
||||
/**
|
||||
* Temporal calendar implementation for the Umm al-Qura calendar.
|
||||
|
|
@ -15,6 +15,6 @@ import { HijriCalendar } from './HijriCalendar';
|
|||
*/
|
||||
export class UaqCalendar extends HijriCalendar {
|
||||
constructor() {
|
||||
super(getCalendar('uaq'));
|
||||
super(getCalendar("uaq"));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
12
src/index.ts
12
src/index.ts
|
|
@ -1,12 +1,12 @@
|
|||
export { HijriCalendar } from './calendars/HijriCalendar';
|
||||
export { UaqCalendar } from './calendars/UaqCalendar';
|
||||
export { FcnaCalendar } from './calendars/FcnaCalendar';
|
||||
export { HijriCalendar } from "./calendars/HijriCalendar";
|
||||
export { UaqCalendar } from "./calendars/UaqCalendar";
|
||||
export { FcnaCalendar } from "./calendars/FcnaCalendar";
|
||||
|
||||
export type { HijriDate, CalendarEngine, ConversionOptions } from 'hijri-core';
|
||||
export type { HijriDate, CalendarEngine, ConversionOptions } from "hijri-core";
|
||||
|
||||
// Pre-built singletons. Import and use directly; no need to instantiate.
|
||||
import { UaqCalendar } from './calendars/UaqCalendar';
|
||||
import { FcnaCalendar } from './calendars/FcnaCalendar';
|
||||
import { UaqCalendar } from "./calendars/UaqCalendar";
|
||||
import { FcnaCalendar } from "./calendars/FcnaCalendar";
|
||||
|
||||
export const uaqCalendar = new UaqCalendar();
|
||||
export const fcnaCalendar = new FcnaCalendar();
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
export type { HijriDate, CalendarEngine, ConversionOptions } from 'hijri-core';
|
||||
export type { HijriDate, CalendarEngine, ConversionOptions } from "hijri-core";
|
||||
|
|
|
|||
54
test-cjs.cjs
54
test-cjs.cjs
|
|
@ -1,4 +1,4 @@
|
|||
'use strict';
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* CJS test suite for temporal-hijri.
|
||||
|
|
@ -6,66 +6,66 @@
|
|||
* Verifies that the CommonJS build loads and functions correctly via require().
|
||||
*/
|
||||
|
||||
const { describe, it } = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { Temporal } = require('@js-temporal/polyfill');
|
||||
const { UaqCalendar, FcnaCalendar, uaqCalendar, fcnaCalendar } = require('./dist/index.cjs');
|
||||
const { describe, it } = require("node:test");
|
||||
const assert = require("node:assert/strict");
|
||||
const { Temporal } = require("@js-temporal/polyfill");
|
||||
const { UaqCalendar, FcnaCalendar, uaqCalendar, fcnaCalendar } = require("./dist/index.cjs");
|
||||
|
||||
const isoRamadan = Temporal.PlainDate.from('2023-03-23');
|
||||
const isoRamadan = Temporal.PlainDate.from("2023-03-23");
|
||||
|
||||
// ── Class and singleton exports ───────────────────────────────────────────────
|
||||
|
||||
describe('CJS class exports', () => {
|
||||
it('UaqCalendar class loads via require', () => {
|
||||
assert(typeof UaqCalendar === 'function', 'UaqCalendar should be a constructor');
|
||||
describe("CJS class exports", () => {
|
||||
it("UaqCalendar class loads via require", () => {
|
||||
assert(typeof UaqCalendar === "function", "UaqCalendar should be a constructor");
|
||||
const cal = new UaqCalendar();
|
||||
assert.equal(cal.id, 'hijri-uaq');
|
||||
assert.equal(cal.id, "hijri-uaq");
|
||||
});
|
||||
|
||||
it('FcnaCalendar class loads via require', () => {
|
||||
assert(typeof FcnaCalendar === 'function', 'FcnaCalendar should be a constructor');
|
||||
it("FcnaCalendar class loads via require", () => {
|
||||
assert(typeof FcnaCalendar === "function", "FcnaCalendar should be a constructor");
|
||||
const cal = new FcnaCalendar();
|
||||
assert.equal(cal.id, 'hijri-fcna');
|
||||
assert.equal(cal.id, "hijri-fcna");
|
||||
});
|
||||
|
||||
it('uaqCalendar singleton id', () => {
|
||||
assert.equal(uaqCalendar.id, 'hijri-uaq');
|
||||
it("uaqCalendar singleton id", () => {
|
||||
assert.equal(uaqCalendar.id, "hijri-uaq");
|
||||
});
|
||||
|
||||
it('fcnaCalendar singleton id', () => {
|
||||
assert.equal(fcnaCalendar.id, 'hijri-fcna');
|
||||
it("fcnaCalendar singleton id", () => {
|
||||
assert.equal(fcnaCalendar.id, "hijri-fcna");
|
||||
});
|
||||
});
|
||||
|
||||
// ── Field accessors ───────────────────────────────────────────────────────────
|
||||
|
||||
describe('CJS field accessors', () => {
|
||||
it('uaqCalendar.year(2023-03-23) = 1444', () => {
|
||||
describe("CJS field accessors", () => {
|
||||
it("uaqCalendar.year(2023-03-23) = 1444", () => {
|
||||
assert.equal(uaqCalendar.year(isoRamadan), 1444);
|
||||
});
|
||||
|
||||
it('uaqCalendar.month(2023-03-23) = 9', () => {
|
||||
it("uaqCalendar.month(2023-03-23) = 9", () => {
|
||||
assert.equal(uaqCalendar.month(isoRamadan), 9);
|
||||
});
|
||||
|
||||
it('uaqCalendar.day(2023-03-23) = 1', () => {
|
||||
it("uaqCalendar.day(2023-03-23) = 1", () => {
|
||||
assert.equal(uaqCalendar.day(isoRamadan), 1);
|
||||
});
|
||||
});
|
||||
|
||||
// ── dateFromFields ─────────────────────────────────────────────────────────────
|
||||
|
||||
describe('CJS dateFromFields', () => {
|
||||
it('uaqCalendar.dateFromFields({year:1444, month:9, day:1}) = 2023-03-23', () => {
|
||||
describe("CJS dateFromFields", () => {
|
||||
it("uaqCalendar.dateFromFields({year:1444, month:9, day:1}) = 2023-03-23", () => {
|
||||
const result = uaqCalendar.dateFromFields({ year: 1444, month: 9, day: 1 });
|
||||
assert.equal(result.toString(), '2023-03-23');
|
||||
assert.equal(result.toString(), "2023-03-23");
|
||||
});
|
||||
});
|
||||
|
||||
// ── fields() ──────────────────────────────────────────────────────────────────
|
||||
|
||||
describe('CJS fields()', () => {
|
||||
it('returns the input array unchanged', () => {
|
||||
assert.deepEqual(uaqCalendar.fields(['year', 'month', 'day']), ['year', 'month', 'day']);
|
||||
describe("CJS fields()", () => {
|
||||
it("returns the input array unchanged", () => {
|
||||
assert.deepEqual(uaqCalendar.fields(["year", "month", "day"]), ["year", "month", "day"]);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
140
test.mjs
140
test.mjs
|
|
@ -5,127 +5,127 @@
|
|||
* Reference point: 2023-03-23 = 1 Ramadan 1444 AH (both UAQ and FCNA agree).
|
||||
*/
|
||||
|
||||
import { describe, it } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { Temporal } from '@js-temporal/polyfill';
|
||||
import { UaqCalendar, FcnaCalendar, uaqCalendar, fcnaCalendar } from './dist/index.mjs';
|
||||
import { describe, it } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { Temporal } from "@js-temporal/polyfill";
|
||||
import { UaqCalendar, FcnaCalendar, uaqCalendar, fcnaCalendar } from "./dist/index.mjs";
|
||||
|
||||
// Reference date: 2023-03-23 = 1 Ramadan 1444 AH
|
||||
const isoRamadan = Temporal.PlainDate.from('2023-03-23');
|
||||
const isoRamadan = Temporal.PlainDate.from("2023-03-23");
|
||||
// 2023-04-21 = 1 Shawwal 1444 AH (first day after Ramadan)
|
||||
const isoShawwal = Temporal.PlainDate.from('2023-04-21');
|
||||
const isoShawwal = Temporal.PlainDate.from("2023-04-21");
|
||||
// 2021-08-09 = 1 Muharram 1443 AH (a 355-day / leap year)
|
||||
const isoLeapYear = Temporal.PlainDate.from('2021-08-09');
|
||||
const isoLeapYear = Temporal.PlainDate.from("2021-08-09");
|
||||
|
||||
// ── 1. Class exports ──────────────────────────────────────────────────────────
|
||||
|
||||
describe('Class exports', () => {
|
||||
it('UaqCalendar class export', () => {
|
||||
assert(UaqCalendar, 'UaqCalendar should be exported');
|
||||
describe("Class exports", () => {
|
||||
it("UaqCalendar class export", () => {
|
||||
assert(UaqCalendar, "UaqCalendar should be exported");
|
||||
const cal = new UaqCalendar();
|
||||
assert(cal instanceof UaqCalendar, 'UaqCalendar should be instantiable');
|
||||
assert(cal instanceof UaqCalendar, "UaqCalendar should be instantiable");
|
||||
});
|
||||
|
||||
it('FcnaCalendar class export', () => {
|
||||
assert(FcnaCalendar, 'FcnaCalendar should be exported');
|
||||
it("FcnaCalendar class export", () => {
|
||||
assert(FcnaCalendar, "FcnaCalendar should be exported");
|
||||
const cal = new FcnaCalendar();
|
||||
assert(cal instanceof FcnaCalendar, 'FcnaCalendar should be instantiable');
|
||||
assert(cal instanceof FcnaCalendar, "FcnaCalendar should be instantiable");
|
||||
});
|
||||
});
|
||||
|
||||
// ── 2. Calendar IDs ───────────────────────────────────────────────────────────
|
||||
|
||||
describe('Calendar IDs', () => {
|
||||
it('uaqCalendar.id', () => {
|
||||
assert.equal(uaqCalendar.id, 'hijri-uaq');
|
||||
describe("Calendar IDs", () => {
|
||||
it("uaqCalendar.id", () => {
|
||||
assert.equal(uaqCalendar.id, "hijri-uaq");
|
||||
});
|
||||
|
||||
it('fcnaCalendar.id', () => {
|
||||
assert.equal(fcnaCalendar.id, 'hijri-fcna');
|
||||
it("fcnaCalendar.id", () => {
|
||||
assert.equal(fcnaCalendar.id, "hijri-fcna");
|
||||
});
|
||||
});
|
||||
|
||||
// ── 3. Field accessors on 1 Ramadan 1444 (2023-03-23) ────────────────────────
|
||||
|
||||
describe('Field accessors (UAQ, 1 Ramadan 1444)', () => {
|
||||
it('year = 1444', () => {
|
||||
describe("Field accessors (UAQ, 1 Ramadan 1444)", () => {
|
||||
it("year = 1444", () => {
|
||||
assert.equal(uaqCalendar.year(isoRamadan), 1444);
|
||||
});
|
||||
|
||||
it('month = 9 (Ramadan)', () => {
|
||||
it("month = 9 (Ramadan)", () => {
|
||||
assert.equal(uaqCalendar.month(isoRamadan), 9);
|
||||
});
|
||||
|
||||
it('day = 1', () => {
|
||||
it("day = 1", () => {
|
||||
assert.equal(uaqCalendar.day(isoRamadan), 1);
|
||||
});
|
||||
|
||||
it('monthCode = "M09"', () => {
|
||||
assert.equal(uaqCalendar.monthCode(isoRamadan), 'M09');
|
||||
assert.equal(uaqCalendar.monthCode(isoRamadan), "M09");
|
||||
});
|
||||
|
||||
it('daysInMonth = 29 (Ramadan 1444)', () => {
|
||||
it("daysInMonth = 29 (Ramadan 1444)", () => {
|
||||
assert.equal(uaqCalendar.daysInMonth(isoRamadan), 29);
|
||||
});
|
||||
|
||||
it('monthsInYear = 12', () => {
|
||||
it("monthsInYear = 12", () => {
|
||||
assert.equal(uaqCalendar.monthsInYear(isoRamadan), 12);
|
||||
});
|
||||
|
||||
it('daysInWeek = 7', () => {
|
||||
it("daysInWeek = 7", () => {
|
||||
assert.equal(uaqCalendar.daysInWeek(isoRamadan), 7);
|
||||
});
|
||||
|
||||
it('dayOfWeek = 4 (Thursday)', () => {
|
||||
it("dayOfWeek = 4 (Thursday)", () => {
|
||||
assert.equal(uaqCalendar.dayOfWeek(isoRamadan), 4);
|
||||
});
|
||||
|
||||
it('dayOfYear = 237', () => {
|
||||
it("dayOfYear = 237", () => {
|
||||
assert.equal(uaqCalendar.dayOfYear(isoRamadan), 237);
|
||||
});
|
||||
});
|
||||
|
||||
// ── 4. dateFromFields ─────────────────────────────────────────────────────────
|
||||
|
||||
describe('dateFromFields', () => {
|
||||
it('dateFromFields({year:1444, month:9, day:1}) = 2023-03-23', () => {
|
||||
describe("dateFromFields", () => {
|
||||
it("dateFromFields({year:1444, month:9, day:1}) = 2023-03-23", () => {
|
||||
const result = uaqCalendar.dateFromFields({ year: 1444, month: 9, day: 1 });
|
||||
assert.equal(result.toString(), '2023-03-23');
|
||||
assert.equal(result.toString(), "2023-03-23");
|
||||
});
|
||||
});
|
||||
|
||||
// ── 5. dateAdd ────────────────────────────────────────────────────────────────
|
||||
|
||||
describe('dateAdd', () => {
|
||||
it('adding 1 month from 1 Ramadan 1444 lands on 1 Shawwal 1444', () => {
|
||||
describe("dateAdd", () => {
|
||||
it("adding 1 month from 1 Ramadan 1444 lands on 1 Shawwal 1444", () => {
|
||||
const oneMonth = new Temporal.Duration(0, 1, 0, 0);
|
||||
const result = uaqCalendar.dateAdd(isoRamadan, oneMonth);
|
||||
assert.equal(result.toString(), isoShawwal.toString());
|
||||
assert.equal(uaqCalendar.month(result), 10);
|
||||
});
|
||||
|
||||
it('adding 7 days from 1 Ramadan 1444', () => {
|
||||
it("adding 7 days from 1 Ramadan 1444", () => {
|
||||
const sevenDays = new Temporal.Duration(0, 0, 0, 7);
|
||||
const result = uaqCalendar.dateAdd(isoRamadan, sevenDays);
|
||||
assert.equal(uaqCalendar.day(result), 8);
|
||||
assert.equal(uaqCalendar.month(result), 9);
|
||||
});
|
||||
|
||||
it('adding 1 week from 1 Ramadan 1444', () => {
|
||||
it("adding 1 week from 1 Ramadan 1444", () => {
|
||||
const oneWeek = new Temporal.Duration(0, 0, 1, 0);
|
||||
const result = uaqCalendar.dateAdd(isoRamadan, oneWeek);
|
||||
assert.equal(uaqCalendar.day(result), 8);
|
||||
assert.equal(uaqCalendar.month(result), 9);
|
||||
});
|
||||
|
||||
it('adding 12 months rolls the year forward', () => {
|
||||
it("adding 12 months rolls the year forward", () => {
|
||||
const twelveMonths = new Temporal.Duration(0, 12, 0, 0);
|
||||
const result = uaqCalendar.dateAdd(isoRamadan, twelveMonths);
|
||||
assert.equal(uaqCalendar.year(result), 1445);
|
||||
assert.equal(uaqCalendar.month(result), 9);
|
||||
});
|
||||
|
||||
it('subtracting months via negative duration', () => {
|
||||
it("subtracting months via negative duration", () => {
|
||||
const negMonth = new Temporal.Duration(0, -1, 0, 0);
|
||||
const result = uaqCalendar.dateAdd(isoShawwal, negMonth);
|
||||
assert.equal(uaqCalendar.month(result), 9);
|
||||
|
|
@ -135,29 +135,29 @@ describe('dateAdd', () => {
|
|||
|
||||
// ── 6. dateUntil ──────────────────────────────────────────────────────────────
|
||||
|
||||
describe('dateUntil', () => {
|
||||
it('days between 1 Ramadan and 1 Shawwal 1444', () => {
|
||||
const dur = uaqCalendar.dateUntil(isoRamadan, isoShawwal, { largestUnit: 'days' });
|
||||
describe("dateUntil", () => {
|
||||
it("days between 1 Ramadan and 1 Shawwal 1444", () => {
|
||||
const dur = uaqCalendar.dateUntil(isoRamadan, isoShawwal, { largestUnit: "days" });
|
||||
assert.equal(dur.days, 29);
|
||||
});
|
||||
|
||||
it('months between 1 Ramadan and 1 Shawwal 1444', () => {
|
||||
const dur = uaqCalendar.dateUntil(isoRamadan, isoShawwal, { largestUnit: 'months' });
|
||||
it("months between 1 Ramadan and 1 Shawwal 1444", () => {
|
||||
const dur = uaqCalendar.dateUntil(isoRamadan, isoShawwal, { largestUnit: "months" });
|
||||
assert.equal(dur.months, 1);
|
||||
assert.equal(dur.days, 0);
|
||||
});
|
||||
|
||||
it('years between dates spanning one Hijri year', () => {
|
||||
it("years between dates spanning one Hijri year", () => {
|
||||
const iso1443 = uaqCalendar.dateFromFields({ year: 1443, month: 1, day: 1 });
|
||||
const iso1444 = uaqCalendar.dateFromFields({ year: 1444, month: 1, day: 1 });
|
||||
const dur = uaqCalendar.dateUntil(iso1443, iso1444, { largestUnit: 'years' });
|
||||
const dur = uaqCalendar.dateUntil(iso1443, iso1444, { largestUnit: "years" });
|
||||
assert.equal(dur.years, 1);
|
||||
assert.equal(dur.months, 0);
|
||||
assert.equal(dur.days, 0);
|
||||
});
|
||||
|
||||
it('weeks between dates', () => {
|
||||
const dur = uaqCalendar.dateUntil(isoRamadan, isoShawwal, { largestUnit: 'weeks' });
|
||||
it("weeks between dates", () => {
|
||||
const dur = uaqCalendar.dateUntil(isoRamadan, isoShawwal, { largestUnit: "weeks" });
|
||||
assert.equal(dur.weeks, 4);
|
||||
assert.equal(dur.days, 1);
|
||||
});
|
||||
|
|
@ -165,8 +165,8 @@ describe('dateUntil', () => {
|
|||
|
||||
// ── 7. inLeapYear ─────────────────────────────────────────────────────────────
|
||||
|
||||
describe('inLeapYear', () => {
|
||||
it('1443 AH (355 days) is a leap year, 1444 AH (354) is not', () => {
|
||||
describe("inLeapYear", () => {
|
||||
it("1443 AH (355 days) is a leap year, 1444 AH (354) is not", () => {
|
||||
assert.equal(uaqCalendar.inLeapYear(isoLeapYear), true);
|
||||
assert.equal(uaqCalendar.inLeapYear(isoRamadan), false);
|
||||
});
|
||||
|
|
@ -174,18 +174,18 @@ describe('inLeapYear', () => {
|
|||
|
||||
// ── 8. FCNA calendar ──────────────────────────────────────────────────────────
|
||||
|
||||
describe('FCNA calendar', () => {
|
||||
it('fcnaCalendar.year(2023-03-23) returns a valid Hijri year', () => {
|
||||
describe("FCNA calendar", () => {
|
||||
it("fcnaCalendar.year(2023-03-23) returns a valid Hijri year", () => {
|
||||
const year = fcnaCalendar.year(isoRamadan);
|
||||
assert(typeof year === 'number' && year > 1400, `Expected a Hijri year > 1400, got ${year}`);
|
||||
assert(typeof year === "number" && year > 1400, `Expected a Hijri year > 1400, got ${year}`);
|
||||
});
|
||||
});
|
||||
|
||||
// ── 9. Out-of-range error ─────────────────────────────────────────────────────
|
||||
|
||||
describe('Out-of-range error', () => {
|
||||
it('uaqCalendar.year throws RangeError for out-of-range date (1800-01-01)', () => {
|
||||
const outOfRange = Temporal.PlainDate.from('1800-01-01');
|
||||
describe("Out-of-range error", () => {
|
||||
it("uaqCalendar.year throws RangeError for out-of-range date (1800-01-01)", () => {
|
||||
const outOfRange = Temporal.PlainDate.from("1800-01-01");
|
||||
assert.throws(
|
||||
() => uaqCalendar.year(outOfRange),
|
||||
(err) => err instanceof RangeError,
|
||||
|
|
@ -195,11 +195,11 @@ describe('Out-of-range error', () => {
|
|||
|
||||
// ── 10. overflow option ───────────────────────────────────────────────────────
|
||||
|
||||
describe('overflow option', () => {
|
||||
describe("overflow option", () => {
|
||||
it('dateFromFields with overflow: "constrain" clamps day', () => {
|
||||
const result = uaqCalendar.dateFromFields(
|
||||
{ year: 1444, month: 9, day: 31 },
|
||||
{ overflow: 'constrain' },
|
||||
{ overflow: "constrain" },
|
||||
);
|
||||
assert.equal(uaqCalendar.day(result), 29);
|
||||
assert.equal(uaqCalendar.month(result), 9);
|
||||
|
|
@ -207,19 +207,19 @@ describe('overflow option', () => {
|
|||
|
||||
it('dateFromFields with overflow: "reject" throws RangeError', () => {
|
||||
assert.throws(
|
||||
() => uaqCalendar.dateFromFields({ year: 1444, month: 9, day: 31 }, { overflow: 'reject' }),
|
||||
() => uaqCalendar.dateFromFields({ year: 1444, month: 9, day: 31 }, { overflow: "reject" }),
|
||||
(err) => err instanceof RangeError,
|
||||
);
|
||||
});
|
||||
|
||||
it('monthDayFromFields with overflow: "constrain" clamps day', () => {
|
||||
const result = uaqCalendar.monthDayFromFields({ month: 9, day: 31 }, { overflow: 'constrain' });
|
||||
const result = uaqCalendar.monthDayFromFields({ month: 9, day: 31 }, { overflow: "constrain" });
|
||||
assert.ok(result);
|
||||
});
|
||||
|
||||
it('monthDayFromFields with overflow: "reject" throws RangeError', () => {
|
||||
assert.throws(
|
||||
() => uaqCalendar.monthDayFromFields({ month: 9, day: 31 }, { overflow: 'reject' }),
|
||||
() => uaqCalendar.monthDayFromFields({ month: 9, day: 31 }, { overflow: "reject" }),
|
||||
(err) => err instanceof RangeError,
|
||||
);
|
||||
});
|
||||
|
|
@ -227,22 +227,22 @@ describe('overflow option', () => {
|
|||
|
||||
// ── 11. fields() ──────────────────────────────────────────────────────────────
|
||||
|
||||
describe('fields()', () => {
|
||||
it('returns the input array unchanged', () => {
|
||||
const input = ['year', 'month', 'day'];
|
||||
describe("fields()", () => {
|
||||
it("returns the input array unchanged", () => {
|
||||
const input = ["year", "month", "day"];
|
||||
const result = uaqCalendar.fields(input);
|
||||
assert.deepEqual(result, ['year', 'month', 'day']);
|
||||
assert.deepEqual(result, ["year", "month", "day"]);
|
||||
});
|
||||
|
||||
it('returns an empty array for empty input', () => {
|
||||
it("returns an empty array for empty input", () => {
|
||||
assert.deepEqual(uaqCalendar.fields([]), []);
|
||||
});
|
||||
});
|
||||
|
||||
// ── 12. yearMonthFromFields ─────────────────────────────────────────────────
|
||||
|
||||
describe('yearMonthFromFields', () => {
|
||||
it('creates a PlainYearMonth for Ramadan 1444', () => {
|
||||
describe("yearMonthFromFields", () => {
|
||||
it("creates a PlainYearMonth for Ramadan 1444", () => {
|
||||
const result = uaqCalendar.yearMonthFromFields({ year: 1444, month: 9 });
|
||||
assert.ok(result);
|
||||
assert.equal(result.month, 3);
|
||||
|
|
@ -252,13 +252,13 @@ describe('yearMonthFromFields', () => {
|
|||
|
||||
// ── 13. monthDayFromFields ──────────────────────────────────────────────────
|
||||
|
||||
describe('monthDayFromFields', () => {
|
||||
it('creates a PlainMonthDay for 15 Ramadan (default reference year)', () => {
|
||||
describe("monthDayFromFields", () => {
|
||||
it("creates a PlainMonthDay for 15 Ramadan (default reference year)", () => {
|
||||
const result = uaqCalendar.monthDayFromFields({ month: 9, day: 15 });
|
||||
assert.ok(result);
|
||||
});
|
||||
|
||||
it('creates a PlainMonthDay with explicit year', () => {
|
||||
it("creates a PlainMonthDay with explicit year", () => {
|
||||
const result = uaqCalendar.monthDayFromFields({ month: 9, day: 1, year: 1445 });
|
||||
assert.ok(result);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,17 +1,17 @@
|
|||
import { defineConfig } from 'tsup';
|
||||
import { defineConfig } from "tsup";
|
||||
|
||||
export default defineConfig({
|
||||
entry: ['src/index.ts'],
|
||||
format: ['cjs', 'esm'],
|
||||
entry: ["src/index.ts"],
|
||||
format: ["cjs", "esm"],
|
||||
dts: true,
|
||||
clean: true,
|
||||
outDir: 'dist',
|
||||
outDir: "dist",
|
||||
splitting: false,
|
||||
sourcemap: true,
|
||||
target: 'es2020',
|
||||
platform: 'node',
|
||||
external: ['hijri-core', '@js-temporal/polyfill'],
|
||||
target: "es2020",
|
||||
platform: "node",
|
||||
external: ["hijri-core", "@js-temporal/polyfill"],
|
||||
outExtension({ format }) {
|
||||
return { js: format === 'esm' ? '.mjs' : '.cjs' };
|
||||
return { js: format === "esm" ? ".mjs" : ".cjs" };
|
||||
},
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue