Rocky_Mountain_Vending/.pnpm-store/v10/files/fc/cc11d661339d06b3ba83bcf0485961503ad2a693716dab803cdf7227d80f32ea8f256c62ea580d0ba2809b735ad75d5d087a83760d074adb85661e52da8d59
DMleadgen 46d973904b
Initial commit: Rocky Mountain Vending website
Next.js website for Rocky Mountain Vending company featuring:
- Product catalog with Stripe integration
- Service areas and parts pages
- Admin dashboard with Clerk authentication
- SEO optimized pages with JSON-LD structured data

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-12 16:22:15 -07:00

72 lines
2 KiB
Text

import { normalizeDates } from "./_lib/normalizeDates.js";
import { compareAsc } from "./compareAsc.js";
import { differenceInCalendarMonths } from "./differenceInCalendarMonths.js";
import { isLastDayOfMonth } from "./isLastDayOfMonth.js";
import { getMonth as coreGetMonth } from "./_core/getMonth.js";
import { setMonth as coreSetMonth } from "./_core/setMonth.js";
import { getDate as coreGetDate } from "./_core/getDate.js";
import { setDate as coreSetDate } from "./_core/setDate.js";
/**
* The {@link differenceInMonths} function options.
*/
/**
* @name differenceInMonths
* @category Month Helpers
* @summary Get the number of full months between the given dates.
*
* @param laterDate - The later date
* @param earlierDate - The earlier date
* @param options - An object with options
*
* @returns The number of full months
*
* @example
* // How many full months are between 31 January 2014 and 1 September 2014?
* const result = differenceInMonths(new Date(2014, 8, 1), new Date(2014, 0, 31))
* //=> 7
*/
export function differenceInMonths(laterDate, earlierDate, options) {
const [laterDate_, workingLaterDate, earlierDate_] = normalizeDates(
options?.in,
laterDate,
laterDate,
earlierDate,
);
const sign = compareAsc(workingLaterDate, earlierDate_);
const difference = Math.abs(
differenceInCalendarMonths(workingLaterDate, earlierDate_),
);
if (difference < 1) return 0;
if (
coreGetMonth(workingLaterDate) === 1 &&
coreGetDate(workingLaterDate) > 27
)
coreSetDate(workingLaterDate, 30);
coreSetMonth(
workingLaterDate,
coreGetMonth(workingLaterDate) - sign * difference,
);
let isLastMonthNotFull = compareAsc(workingLaterDate, earlierDate_) === -sign;
if (
isLastDayOfMonth(laterDate_) &&
difference === 1 &&
compareAsc(laterDate_, earlierDate_) === 1
) {
isLastMonthNotFull = false;
}
const result = sign * (difference - +isLastMonthNotFull);
return result === 0 ? 0 : result;
}
// Fallback for modularized imports:
export default differenceInMonths;