Skip to main content
Home

latest

Utility for doing math on strings in the format "hh:mm", such as adding, subtracting, intersection testing and modulo

This package works with Node.js, Deno, Bun, BrowsersIt is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
94%
Published
a year ago (0.1.2)
method HHMM.prototype.lt
HHMM.prototype.lt(other: string | number): boolean

lt = less than

Checks whether this represents a time earlier than the input time

It's recommended to use the HM symbol property, but there are multiple ways to compare less than.

const time1 = "08:00"
const time2 = "09:00"

// ✅ Most ergonomic and readable
if (time1[HM] < time2[HM]) 

// 🟧 Not a bad solution either, but at-a-glance readability suffers
if (time1[HM].lt(time2))

// 🟧 Works, but there's 6 more characters to read and write for each `new HHMM()` compared
// to using the HM symbol property. Multiply that with the number of times
// you are doing any comparison, add/subtract etc.
if (new HHMM(time1) < new HHMM(time2))

// 🟥 Worst of both worlds
if (new HHMM(time1).lt(time2))

Examples

Example 1

const time = new HHMM("20:00")
time.lt("24:00")
time.lt(600) // comparing minutes. 600 minutes = 10:00

Parameters

other: string | number

Return Type

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@revosw/hhmm

Import symbol

import { HHMM } from "@revosw/hhmm";
or

Import directly with a jsr specifier

import { HHMM } from "jsr:@revosw/hhmm";

Add Package

pnpm i jsr:@revosw/hhmm
or (using pnpm 10.8 or older)
pnpm dlx jsr add @revosw/hhmm

Import symbol

import { HHMM } from "@revosw/hhmm";

Add Package

yarn add jsr:@revosw/hhmm
or (using Yarn 4.8 or older)
yarn dlx jsr add @revosw/hhmm

Import symbol

import { HHMM } from "@revosw/hhmm";

Add Package

vlt install jsr:@revosw/hhmm

Import symbol

import { HHMM } from "@revosw/hhmm";

Add Package

npx jsr add @revosw/hhmm

Import symbol

import { HHMM } from "@revosw/hhmm";

Add Package

bunx jsr add @revosw/hhmm

Import symbol

import { HHMM } from "@revosw/hhmm";