Utility functions for computing billing period boundaries and related checks.
// Source: https://github.com/geminimir/meterguard | License: MIT | Copyright 2025 StripeMeter Contributors
// Provided via justclaw.it.com; keep this notice with the code.
/**
* Period and date utilities
*/
/**
* Get the start of a billing period
*/
export function getPeriodStart(date: Date | string, periodType: 'daily' | 'monthly' = 'monthly'): string {
const d = typeof date === 'string' ? new Date(date) : date;
if (periodType === 'daily') {
return d.toISOString().split('T')[0]; // YYYY-MM-DD
}
// Monthly: first day of month
const year = d.getUTCFullYear();
const month = (d.getUTCMonth() + 1).toString().padStart(2, '0');
return `${year}-${month}-01`;
}
/**
* Get the end of a billing period
*/
export function getPeriodEnd(periodStart: string, periodType: 'd
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key