@northguild/gmt
Version:
Date and time library for JavaScript and TypeScript, built on TC39 Temporal: time zones, DST, business days, ISO 8601 strings in and out. Never throws.
16 lines (15 loc) • 670 B
JavaScript
// src/internal/temporalCompat/fixedMonthArithmetic.ts
/** `BalanceNonISODate(start.year, start.month + months, 1)` for `monthsPerYear` months in every year. */
function addFixedMonths(start, months, monthsPerYear) {
const ordinal = start.month - 1 + months;
const years = Math.floor(ordinal / monthsPerYear);
return {
year: start.year + years,
month: ordinal - years * monthsPerYear + 1
};
}
/** The signed month count from `from` to `to` for `monthsPerYear` months in every year. */
function fixedMonthsBetween(from, to, monthsPerYear) {
return (to.year - from.year) * monthsPerYear + (to.month - from.month);
}
export { addFixedMonths, fixedMonthsBetween };