import { type Maybe } from '../value/maybe.type'; import { type Hours, type Minutes } from './date'; import { type MinutesIncrement, type MinutesIncrementConverter, type MinutesIncrementConverterConfig } from './minute'; /** * A number that represents hours and rounded to the nearest minute. * * It has only three decimal places max. * * Fractional hours are safe to add together. * * For example: * * - 10 minutes: 0.16 * - 15 minutes : 0.25 * * @semanticType * @semanticTopic date * @semanticTopic numeric */ export type FractionalHour = number; /** * Precision function that rounds fractional hour values to 3 decimal places. */ export declare const FRACTIONAL_HOURS_PRECISION_FUNCTION: import("..").CutValueToPrecisionFunction; /** * Converts the number of minutes to a fractional hour. * * Minutes are rounded down before conversion. * * @param minutes - Number of minutes to convert. * @returns The equivalent fractional hour value. */ export declare function minutesToFractionalHours(minutes: Minutes): FractionalHour; /** * Converts a fractional hour value to the equivalent number of minutes. * * @param hours - Fractional hour value to convert. * @returns The equivalent number of minutes (rounded) */ export declare function fractionalHoursToMinutes(hours: FractionalHour): Minutes; /** * Rounds the input hour to the nearest FractionalHour precision (3 decimal places). * * @param hour - The hour value to round. * @returns The rounded fractional hour. */ export declare function hourToFractionalHour(hour: Hours): FractionalHour; /** * Input for computing the next fractional hour by adding minutes and/or hours. */ export interface ComputeFractionalHour { readonly minutes?: Maybe; readonly hours?: Maybe; } /** * Computes the next fractional hour by adding the specified hours and minutes to the input value. * * @param input - The starting fractional hour value. * @param change - The hours and/or minutes to add. * @returns The resulting fractional hour. */ export declare function computeNextFractionalHour(input: FractionalHour, change: ComputeFractionalHour): FractionalHour; /** * The hour of the day. * * Number from 0-23. * * @semanticType * @semanticTopic date * @semanticTopic numeric */ export type HourOfDay = number; export declare const HOUR_OF_DAY_MINIUMUM = 0; export declare const HOUR_OF_DAY_MAXMIMUM: number; /** * Returns true if the input value is a valid HourOfDay (0-23). * * @param input - Candidate value to validate against the HourOfDay range. * @returns True when the value falls within 0-23. */ export declare function isHourOfDay(input: number): input is HourOfDay; /** * The minute of the day. * * Number from 0-1439. * * @semanticType * @semanticTopic date * @semanticTopic numeric */ export type MinuteOfDay = number; /** * A MinuteOfDay expressed as a MinutesIncrement, which is the index of the increment of the day that contains it. * * For example, with a 15 minute increment: 0 (00:00) is 0, 15 (00:15) is 1, 60 (01:00) is 4, and 1425 (23:45) is 95. * * Is always an integer. * * Optional generic typing exists for communicating the increment size in minutes. * * Use minuteOfDayIncrementConverter() to convert between MinuteOfDay and MinuteOfDayIncrement values. * * @semanticType * @semanticTopic date * @semanticTopic numeric */ export type MinuteOfDayIncrement = MinutesIncrement; /** * A MinuteOfDayIncrement for a 15 minute increment, where each value is a quarter hour of the day. * * Number from 0-95. * * @semanticType * @semanticTopic date * @semanticTopic numeric */ export type MinuteOfDayFifteenMinuteIncrement = MinuteOfDayIncrement<15>; export declare const MINUTE_OF_DAY_MINIUMUM = 0; export declare const MINUTE_OF_DAY_MAXMIMUM: number; /** * Returns true if the input value is a valid MinuteOfDay (0-1439). * * @param input - Candidate value to validate against the MinuteOfDay range. * @returns True when the value falls within 0-1439. */ export declare function isMinuteOfDay(input: number): input is MinuteOfDay; /** * A pair of hours and minutes. */ export interface HoursAndMinutes { readonly hour: Hours; readonly minute: Minutes; } /** * Converts the input number of minutes to the equivalent in hours and minutes. * * @param inputMinutes - Total minutes to break down. * @returns Split hour-and-minute pair representing the same duration. */ export declare function minutesToHoursAndMinutes(inputMinutes: Minutes): HoursAndMinutes; /** * Reads the hour and minutes of the Date in the local timezone. * * @param date - Reference instant whose local clock time should be split. * @returns Local-time hour-and-minute pair for `date`. */ export declare function dateToHoursAndMinutes(date: Date): HoursAndMinutes; /** * Converts the input hours and minutes to a MinuteOfDay. * * @param hour - The hour component (0-23) * @param minute - The minute component (0-59) * @returns The corresponding MinuteOfDay value. */ export declare function toMinuteOfDay(hour: Hours, minute: Minutes): MinuteOfDay; /** * Creates a new date with the time set to the given minute of the day. * * @param minuteOfDay - The minute of the day (0-1439) * @param day - Optional base date to use (defaults to the current date) * @returns Instant at the requested minute-of-day on the supplied calendar day. */ export declare function dateFromMinuteOfDay(minuteOfDay: Minutes | MinuteOfDay, day?: Date): Date; /** * Converts a Date to a MinuteOfDay based on the local timezone. * * @param date - Reference instant whose local clock should be folded into the day. * @returns Minute-of-day for `date` in the system timezone. */ export declare function dateToMinuteOfDay(date: Date): MinuteOfDay; /** * Converts the input minutes to a valid MinuteOfDay by wrapping around the day boundary. * * @param minutes - The minutes value to convert. * @returns A MinuteOfDay value (0-1439) */ export declare function asMinuteOfDay(minutes: Minutes): MinuteOfDay; /** * minuteOfDayIncrementConverter() configuration. * * Fractional increments are not allowed, since a MinuteOfDay is always an integer. */ export type MinuteOfDayIncrementConverterConfig = Omit, 'allowFractionalIncrement'>; export type MinuteOfDayIncrementConverterInput = MinuteOfDayIncrementConverterConfig | T; /** * Converts between MinuteOfDay and MinuteOfDayIncrement values for a specific increment size. * * All conversions wrap around the day boundary, so a value that rounds up past the last increment of the day becomes 0 (midnight). */ export interface MinuteOfDayIncrementConverter extends MinutesIncrementConverter { /** * Number of increments in a day. For example, 96 for a 15 minute increment. */ readonly incrementsInDay: number; /** * Reduces the MinuteOfDay to a MinuteOfDayIncrement using the configured rounding. */ readonly reduce: (minuteOfDay: MinuteOfDay) => MinuteOfDayIncrement; /** * Expands the MinuteOfDayIncrement to the MinuteOfDay at the start of that increment. */ readonly expand: (increment: MinuteOfDayIncrement) => MinuteOfDay; /** * Rounds the MinuteOfDay to the start of an increment using the configured rounding. Equivalent to expand(reduce(minuteOfDay)). */ readonly round: (minuteOfDay: MinuteOfDay) => MinuteOfDay; } /** * Creates a MinuteOfDayIncrementConverter that reduces MinuteOfDay values to MinuteOfDayIncrement values, expands them back, and rounds MinuteOfDay values to the start of an increment. * * Accepts either an increment size (uses 'floor' rounding) or a full config with the increment and rounding type. * * @param input - Increment size in minutes, or full configuration. * @returns Converter that reduces, expands, and rounds MinuteOfDay values by the increment. * @throws {Error} If the increment is not a positive integer. * * @dbxUtil * @dbxUtilCategory date * @dbxUtilKind factory * @dbxUtilTags date, minute, minute-of-day, increment, round, convert, factory * @dbxUtilRelated minutes-increment-converter, number-factor-converter * * @example * ```ts * const converter = minuteOfDayIncrementConverter(15); * converter.reduce(68); // 4 (01:08 is within the 01:00 increment) * converter.expand(4); // 60 * converter.round(68); // 60 * * const ceilConverter = minuteOfDayIncrementConverter({ increment: 15, round: 'ceil' }); * ceilConverter.round(68); // 75 * ceilConverter.round(1439); // 0 (wraps to midnight) * ``` * * @__NO_SIDE_EFFECTS__ */ export declare function minuteOfDayIncrementConverter(input: MinuteOfDayIncrementConverterInput): MinuteOfDayIncrementConverter; /** * Returns a human-readable string that represents the input hours and minutes. * * Examples: * - {} -> '' * - { hour: 1, minute: 30 } -> "1 hours and 30 minutes" * - { hour: 1 } -> "1 hours" * - { minute: 30 } -> "30 minutes" * * @param input - The hours and minutes to format. * @returns A human-readable string representation. */ export declare function hoursAndMinutesToString(input: HoursAndMinutes): string;