Rocky_Mountain_Vending/.pnpm-store/v10/files/8b/14ec7d2d286bb2d3aa612b7ba9f83f61f71f70a38dcb15e51e8368dcd0aa3a1148f657cc94147c728fe6941621477919bea24bfdf58c58571defdfacadb9bf
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

102 lines
2.3 KiB
Text

import { defaultLocale } from "./_lib/defaultLocale.js";
import { getDefaultOptions } from "./_lib/defaultOptions.js";
/**
* The {@link formatDuration} function options.
*/
const defaultFormat = [
"years",
"months",
"weeks",
"days",
"hours",
"minutes",
"seconds",
];
/**
* @name formatDuration
* @category Common Helpers
* @summary Formats a duration in human-readable format
*
* @description
* Return human-readable duration string i.e. "9 months 2 days"
*
* @param duration - The duration to format
* @param options - An object with options.
*
* @returns The formatted date string
*
* @example
* // Format full duration
* formatDuration({
* years: 2,
* months: 9,
* weeks: 1,
* days: 7,
* hours: 5,
* minutes: 9,
* seconds: 30
* })
* //=> '2 years 9 months 1 week 7 days 5 hours 9 minutes 30 seconds'
*
* @example
* // Format partial duration
* formatDuration({ months: 9, days: 2 })
* //=> '9 months 2 days'
*
* @example
* // Customize the format
* formatDuration(
* {
* years: 2,
* months: 9,
* weeks: 1,
* days: 7,
* hours: 5,
* minutes: 9,
* seconds: 30
* },
* { format: ['months', 'weeks'] }
* ) === '9 months 1 week'
*
* @example
* // Customize the zeros presence
* formatDuration({ years: 0, months: 9 })
* //=> '9 months'
* formatDuration({ years: 0, months: 9 }, { zero: true })
* //=> '0 years 9 months'
*
* @example
* // Customize the delimiter
* formatDuration({ years: 2, months: 9, weeks: 3 }, { delimiter: ', ' })
* //=> '2 years, 9 months, 3 weeks'
*/
export function formatDuration(duration, options) {
const defaultOptions = getDefaultOptions();
const locale = options?.locale ?? defaultOptions.locale ?? defaultLocale;
const format = options?.format ?? defaultFormat;
const zero = options?.zero ?? false;
const delimiter = options?.delimiter ?? " ";
if (!locale.formatDistance) {
return "";
}
const result = format
.reduce((acc, unit) => {
const token = `x${unit.replace(/(^.)/, (m) => m.toUpperCase())}`;
const value = duration[unit];
if (value !== undefined && (zero || duration[unit])) {
return acc.concat(locale.formatDistance(token, value));
}
return acc;
}, [])
.join(delimiter);
return result;
}
// Fallback for modularized imports:
export default formatDuration;