Toolbox-XToolbox-X

Extract Total Minutes

Extract Total Minutes — Chronos Documentation.

getTotalMinutes

Converts a time string in HH:MM or -HH:MM format into total minutes from 00:00.

Import

import { getTotalMinutes } from "toolbox-x/utils";

Function Signature

getTotalMinutes(time: `-${ClockTime}` | ClockTime): number;

Parameters

  • time: A time string in either:
    • Positive format: HH:MM (e.g., "08:30")
    • Negative format: -HH:MM (e.g., "-05:00")

Returns

Total minutes elapsed since 00:00:

  • Positive number for times in HH:MM format
  • Negative number for times in -HH:MM format
  • 0 for 00:00 or -00:00

Example Usage

playground.ts

Notes

  • Handles both positive and negative time formats
  • Maintains sign convention from input
  • Returns raw numeric value (no rounding)
  • Follows 24-hour time format
  • Returns 0 for both 00:00 and -00:00
  • It internally uses extractHourMinute

Aliases

  • extractTotalMinutesFromTime
  • getTotalMinutesFromTime

Type Safety

Input is strictly validated through types:

type ClockTime = `${ClockHour}:${ClockMinute}`;
type ClockHour = '00'|'01'|...|'23';
type ClockMinute = '00'|'01'|...|'59';

Use Cases

  • Time duration calculations
  • Timezone offset conversions
  • Scheduling and time arithmetic
  • Comparing time intervals
  • Converting time formats for storage

Conclusion

The getTotalMinutes function provides:

  1. Simple conversion from time strings to minutes
  2. Accurate time math for calculations
  3. Consistent handling of signed times
  4. Type-safe operations through strict input validation

Last updated: Fri, May 22, 2026 07:46:19AM (Coordinated Universal Time)

On this page