npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@empellio/business-hours

v0.1.0

Published

A lightweight and accurate TypeScript library for handling business opening hours. Supports multiple daily time slots, holidays, exceptions, overnight openings, and timezone-aware calculations.

Readme

@empellio/business-hours

A lightweight and accurate TypeScript library for handling business opening hours. Supports multiple daily time slots, holidays, exceptions, overnight openings, and timezone-aware calculations. Runs in both Node.js and the browser. Perfect for scheduling, booking systems, e-commerce stores, and any application that needs to determine "open/closed" status and calculate time until next opening or closing.

Installation

npm install @empellio/business-hours luxon
# or
yarn add @empellio/business-hours luxon

Quick start

import { createBusinessHours } from '@empellio/business-hours'

const bh = createBusinessHours({
  timezone: 'Europe/Prague',
  week: {
    mon: [{ open: '09:00', close: '12:00' }, { open: '13:00', close: '17:00' }],
    tue: [{ open: '09:00', close: '17:00' }],
    wed: 'closed',
    thu: [{ open: '09:00', close: '17:00' }],
    fri: [{ open: '09:00', close: '15:00' }],
    sat: [{ open: '10:00', close: '14:00' }],
    sun: 'closed'
  },
  holidays: [
    { date: '2025-12-24', closed: true, note: 'Christmas Eve' },
    { date: '2025-12-31', slots: [{ open: '09:00', close: '12:00' }] }
  ],
  exceptions: [
    { date: '2025-08-20', closed: true, note: 'Inventory' },
    { date: '2025-08-22', slots: [{ open: '12:00', close: '20:00' }] }
  ],
  locale: 'en-US'
})

bh.isOpenNow()
bh.isOpenAt('2025-08-22T18:30:00Z')
bh.nextOpen()
bh.nextClose()
bh.timeUntilClose()
bh.timeUntilOpen()
bh.todaysSlots()
bh.weeklySummary()

Configuration

type WeekdayKey = 'mon'|'tue'|'wed'|'thu'|'fri'|'sat'|'sun'
type HHMM = `${number}${number}:${number}${number}`

type SlotInput = { open: HHMM, close: HHMM }
type DaySpec = 'closed' | SlotInput[]

type Holiday = { date: string, closed?: boolean, slots?: SlotInput[], note?: string }
type Exception = { date: string, closed?: boolean, slots?: SlotInput[], note?: string }

type Config = {
  timezone: string
  week: Record<WeekdayKey, DaySpec>
  holidays?: Holiday[]
  exceptions?: Exception[]
  locale?: string
  firstDayOfWeek?: WeekdayKey
  strictValidation?: boolean
}

Validation rules:

  • Check HH:MM format for open/close times
  • Allow overnight slots (open > close)
  • No overlapping slots in the same day (after overnight normalization)
  • Exceptions override holidays
  • strictValidation: true throws errors for invalid configs, false auto-corrects deterministically

Overnight & DST handling

  • Overnight slots are split internally into day-bound ranges
  • All calculations are timezone-aware using Luxon
  • DST changes are handled via Luxon's setZone

API reference

  • createBusinessHours(config: Config): BusinessHours
  • isOpenNow(): boolean
  • isOpenAt(date: Date | string): boolean
  • nextOpen(from?: Date | string): { start: Date, end: Date } | null
  • nextClose(from?: Date | string): { at: Date } | null
  • currentSlot(at?: Date | string): { open: Date, close: Date } | null
  • timeUntilClose(at?: Date | string): { ms: number, minutes: number } | null
  • timeUntilOpen(at?: Date | string): { ms: number, minutes: number } | null
  • todaysSlots(at?: Date | string): Array<{ open: Date, close: Date }>
  • slotsOn(date: Date | string): Array<{ open: Date, close: Date }>
  • weeklySummary(options?): string[] | string
  • listUpcomingSlots(daysAhead?: number): Array<{ date: string, slots: Array<{ open: Date, close: Date }> }>
  • withOverrides(overrides: Partial<Config>): BusinessHours

Examples

Time until close

const res = bh.timeUntilClose()
// { ms: number, minutes: number } | null

Next open slot

const res = bh.nextOpen()
// { start: Date, end: Date } | null

Weekly summary

bh.weeklySummary()
// ["Mon 09:00–12:00, 13:00–17:00", ...]

Performance tips

  • The library precompiles weekly slots and caches recent days (LRU up to 14 days)
  • Prefer reusing a single instance per config

Changelog

  • 0.1.0: Initial release