UNPKG

nhb-toolbox

Version:

A versatile collection of smart, efficient, and reusable utility functions and classes for everyday development needs.

58 lines 2.36 kB
import type { Numeric } from '../types/index'; import type { ClockTime, HourMinutes, UTCOffSet } from './types'; /** * * Extracts the hour and minute from a time string in `HH:MM` or `-HH:MM` format. * * @param time - The time string to extract from. * @return The extracted hour and minute as number tuple. */ export declare function extractHourMinute(time: `-${ClockTime}` | ClockTime): [number, number]; /** * * Converts a time string `HH:MM` or `-HH:MM` into total minutes from `00:00`. * * @param time - The time in `HH:MM` or `-HH:MM` format. * @returns The total minutes elapsed since `00:00`. */ export declare function getTotalMinutes(time: `-${ClockTime}` | ClockTime): number; /** * * Returns the current date and time as `Date` object. * - All the methods and properties of `new Date()` are accessible. * * @returns The current date and time as a `Date` object. */ export declare function getCurrentDateTime(): Date; /** * * Extract Time in `HH:MM` format from given UTC value. * * @param utc UTC value in `UTC-01:30` or `UTC+01:30` format. * @returns The UTC value in `HH:MM` format. */ export declare function extractTimeFromUTC(utc: UTCOffSet): `-${ClockTime}` | ClockTime; /** * * Converts a UTC value in `UTC-01:30` or `UTC+01:30` format into total minutes in number. * * @param time - UTC value in `UTC-01:30` or `UTC+01:30` format. * @returns The total minutes elapsed since `00:00`. */ export declare function extractMinutesFromUTC(utc: UTCOffSet): number; /** * * Converts a number of minutes into a time string in "HH:MM" format. * * @param minutes - The number of minutes to convert. Can be a number or a numeric string. * @returns A string representing the time in "HH:MM" format. * * @remarks Always returns the absolute value of the minutes, ignoring the sign if they are negative. * * @example * convertMinutesToTime(75); // "1:15" * convertMinutesToTime(-45); // "0:45" */ export declare function convertMinutesToTime(minutes: Numeric): HourMinutes; /** * * Converts a minute-based offset to a UTC offset string in the format `UTC±HH:MM`. * * @param minutes - The offset in minutes (positive or negative). * @returns A formatted UTC offset string like `UTC+05:30` or `UTC-04:00`. */ export declare function formatUTCOffset(minutes: Numeric): UTCOffSet; //# sourceMappingURL=utils.d.ts.map