sdxc-duration

Converts compile-time-checked duration strings to milliseconds or seconds in TypeScript.

5|Updated Feb 2, 2026
One-click install
npx skills add https://github.com/sergiodxa/monorepo --skill sdxc-duration-sergiodxa
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: sdxc-duration
Source: https://github.com/sergiodxa/monorepo/tree/main/.agents/skills/sdxc-duration
Command: npx skills add https://github.com/sergiodxa/monorepo --skill sdxc-duration-sergiodxa

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @sdxc/result.

What problem does it solve? Bare millisecond literals like 2592000000 are unreadable, and hand-written duration strings can contain typos that silently become NaN timers at runtime. This Skill provides a template-literal DurationInput type so invalid spellings fail at compile time, plus converters and a parser for runtime text. ## Core Features & Use Cases - Type-safe duration declarations: DurationInput accepts strings like "30 days" or "250ms" and rejects misspellings such as "5 minuts" at compile time. - Unit conversion: toMs() and toSeconds() convert one declared duration to the unit each boundary needs, such as a cookie Max-Age in seconds versus Date arithmetic in milliseconds. - Runtime validation: parse() returns a Result<number, InvalidDurationError> for durations read from environment variables or form fields, naming the rejected text instead of producing NaN. - Use Case: Declare a ttl: DurationInput parameter on a cache function, let callers write "30 days", and convert to seconds at the storage boundary. ## Quick Start Add @sdxc/duration as a workspace dependency and use it to declare a TTL parameter that accepts strings like "5 minutes" and converts them with toMs or toSeconds.

Frequently Asked Questions about sdxc-duration

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I parse a duration string like "30 days" in TypeScript?▼

Use the parse function from @sdxc/duration, which returns a Result<number, InvalidDurationError> containing milliseconds. For values already typed as DurationInput, call toMs or toSeconds directly without parsing.

How do I type a function parameter that accepts duration strings?▼

Declare the parameter as DurationInput from @sdxc/duration. It accepts spelled-out strings like "5 minutes", abbreviations like "30s", or a bare number of milliseconds, and rejects misspellings at compile time.

Does @sdxc/duration support months, years, or fractional amounts?▼

No. Months and years are rejected because they have no fixed length, and fractional amounts, uppercase units, and compound durations are also rejected. The grammar requires a single space for long spellings and none for short aliases.

Why does toSeconds return 0 for my duration?▼

toSeconds rounds to the nearest second with halves up, so any duration under half a second becomes 0. Many seconds-based APIs read 0 as no caching, so pass at least "1 second" when a TTL must be non-zero.

What happens when toMs receives an invalid duration string?▼

toMs returns NaN rather than throwing when a value reaches it behind a cast. Route runtime text through parse instead, which returns a Result that names the rejected text.