@toreda/time
Version:
Simple, small footprint library for common time operations and converting between units of time.
20 lines (19 loc) • 850 B
TypeScript
import type { TimeUnit } from '../unit';
/**
* Parse a timestamp value into a number expressed in `units`. Accepts:
* - finite numbers (treated as **already** a timestamp in `units`; not
* re-interpreted as ms or seconds)
* - any string accepted by `Date.parse` (ISO 8601, RFC 2822, etc.) —
* converted from ms to `units`
*
* Returns null for empty / whitespace-only strings, NaN/Infinity numeric
* input, unparseable strings, pre-epoch results (negative timestamps), and
* any result outside the safe integer range.
*
* @param value Timestamp value to parse.
* @param units Target unit. Numeric inputs are treated as already in
* this unit; date-string inputs are converted from ms.
*
* @category Time Parsing
*/
export declare function timeValueParseDate(value: number | string, units: TimeUnit): number | null;