@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.
33 lines • 2.16 kB
TypeScript
import { FractionalDigit } from "../../types/fractional-digit.js";
import "../../types/index.js";
/**
* Return the end of the quarter for a given zoned ISO datetime.
*
* - Calculates which quarter (1-4) the date falls into and returns the last moment of that quarter.
* - Returns one nanosecond before the next local quarter starts in `value`'s own zone (see `floorToZone`), so the result is never before `value`: a quarter whose last local hour repeats (`Africa/Cairo`, 2010-09-30) ends with the second pass.
* - The end is written at nanosecond precision by default, so the string names the end itself.
* - Validation is performed on the input.
* - **Compatibility:** before 1.16.0 the default printed no fractional digits, which wrote a moment
* earlier than the end. Pass `{ fractionalSecondDigits: 0 }` to keep the previous string.
*
* @param value ISO ZonedDateTime string
* @param optionsArg optional setting for the precision of the output string
* @returns ISO ZonedDateTime string for the end of the quarter, or "" on invalid input
*
* @example endOfQuarterForZoned("2024-02-15T14:30:00+00:00[UTC]") // "2024-03-31T23:59:59.999999999+00:00[UTC]"
* @example endOfQuarterForZoned("2024-02-15T14:30:00+00:00[UTC]", { fractionalSecondDigits: 0 }) // "2024-03-31T23:59:59+00:00[UTC]" — the pre-1.16.0 string
* @example endOfQuarterForZoned("2024-05-10T10:00:00+00:00[UTC]") // "2024-06-30T23:59:59.999999999+00:00[UTC]"
* @example endOfQuarterForZoned("2024-11-20T08:00:00+00:00[UTC]") // "2024-12-31T23:59:59.999999999+00:00[UTC]"
* @example endOfQuarterForZoned("2024-02-15T14:30:00+00:00[UTC]", { fractionalSecondDigits: 3 }) // "2024-03-31T23:59:59.999+00:00[UTC]"
* @example endOfQuarterForZoned("invalid") // ""
*/
export declare function endOfQuarterForZoned(value: string, optionsArg?: {
/**
* The number of fractional-second digits the result is written with, `0` to `9`, or `"auto"` to
* drop trailing zeros. Fewer than 9 digits truncate the string, as Temporal's `toString` does,
* so it names a moment before the end.
*
* @defaultValue `9`
*/
fractionalSecondDigits?: FractionalDigit;
}): string;