/** * Python time module for TypeScript * * Provides time-related functions including time access, conversions, * and formatting. Note that `sleep()` uses a synchronous busy-wait * which blocks the event loop. * * @see {@link https://docs.python.org/3/library/time.html | Python time documentation} * @module */ /** * Structure representing a time tuple, similar to Python's struct_time. */ interface StructTime { /** Year (e.g., 2023) */ tm_year: number; /** Month (1-12) */ tm_mon: number; /** Day of month (1-31) */ tm_mday: number; /** Hour (0-23) */ tm_hour: number; /** Minute (0-59) */ tm_min: number; /** Second (0-61, allowing for leap seconds) */ tm_sec: number; /** Day of week (0-6, Monday is 0) */ tm_wday: number; /** Day of year (1-366) */ tm_yday: number; /** DST flag (-1, 0, or 1) */ tm_isdst: number; } /** * Return the time in seconds since the epoch as a floating point number. * * @returns Seconds since Unix epoch (January 1, 1970) * * @example * ```typescript * console.log(time()) // 1704067200.123 * ``` */ declare function time(): number; /** * Return the time in nanoseconds since the epoch as a BigInt. * * @returns Nanoseconds since Unix epoch * * @example * ```typescript * console.log(timeNs()) // 1704067200123456789n * ``` */ declare function timeNs(): bigint; /** * Suspend execution for the given number of seconds. * WARNING: This uses a synchronous busy-wait that blocks the event loop. * * @param secs - Number of seconds to sleep (can be fractional) * * @example * ```typescript * sleep(0.5) // Sleep for 500 milliseconds * ``` */ declare function sleep(secs: number): void; /** * Return the value of a performance counter (monotonic clock). * Uses performance.now() for high precision. * * @returns Seconds as a float (relative to an undefined reference point) * * @example * ```typescript * const start = perfCounter() * // ... do work ... * const elapsed = perfCounter() - start * ``` */ declare function perfCounter(): number; /** * Return the value of a performance counter in nanoseconds. * * @returns Nanoseconds as a BigInt (relative to an undefined reference point) */ declare function perfCounterNs(): bigint; /** * Return the value of a monotonic clock. * This clock cannot go backwards and is not affected by system clock updates. * * @returns Seconds as a float (relative to an undefined reference point) */ declare function monotonic(): number; /** * Return the value of a monotonic clock in nanoseconds. * * @returns Nanoseconds as a BigInt */ declare function monotonicNs(): bigint; /** * Convert seconds since epoch to a StructTime in local time. * * @param secs - Seconds since epoch (defaults to current time) * @returns StructTime object representing local time * * @example * ```typescript * const t = localtime() * console.log(t.tm_year, t.tm_mon, t.tm_mday) * ``` */ declare function localtime(secs?: number): StructTime; /** * Convert seconds since epoch to a StructTime in UTC. * * @param secs - Seconds since epoch (defaults to current time) * @returns StructTime object representing UTC time */ declare function gmtime(secs?: number): StructTime; /** * Convert a StructTime to seconds since epoch (inverse of localtime). * * @param t - StructTime object * @returns Seconds since epoch as a float */ declare function mktime(t: StructTime): number; /** * Format a StructTime as a string using strftime-style format codes. * * Supported format codes: * - %Y: Year with century (e.g., 2023) * - %y: Year without century (00-99) * - %m: Month (01-12) * - %d: Day of month (01-31) * - %H: Hour 24-hour (00-23) * - %I: Hour 12-hour (01-12) * - %M: Minute (00-59) * - %S: Second (00-61) * - %p: AM or PM * - %A: Full weekday name * - %a: Abbreviated weekday name * - %B: Full month name * - %b: Abbreviated month name * - %w: Weekday as decimal (0-6, Sunday is 0) * - %j: Day of year (001-366) * - %U: Week number of year (Sunday first day) * - %W: Week number of year (Monday first day) * - %c: Locale's date and time representation * - %x: Locale's date representation * - %X: Locale's time representation * - %%: Literal % * * @param format - Format string * @param t - StructTime object (defaults to current local time) * @returns Formatted time string */ declare function strftime(format: string, t?: StructTime): string; /** * Parse a string according to a format and return a StructTime. * * @param timeString - String to parse * @param format - Format string (same codes as strftime) * @returns StructTime object * @throws Error if string doesn't match format */ declare function strptime(timeString: string, format: string): StructTime; /** * Convert a StructTime to a string in the format: "Dow Mon dd hh:mm:ss yyyy" * * @param t - StructTime object (defaults to current local time) * @returns Formatted time string */ declare function asctime(t?: StructTime): string; /** * Convert seconds since epoch to a string (equivalent to asctime(localtime(secs))) * * @param secs - Seconds since epoch (defaults to current time) * @returns Formatted time string */ declare function ctime(secs?: number): string; /** * Return the offset of the local timezone from UTC in seconds. * Positive values mean west of UTC, negative mean east. */ declare const timezone: number; /** * Return the offset of the local timezone from UTC in seconds during DST. * This is the same as timezone on systems that don't have DST. */ declare const altzone: number; /** * Return a tuple of two strings: standard timezone name and DST timezone name. */ declare const tzname: [string, string]; /** * True if DST is defined for the local timezone. */ declare const daylight = 0; /** * Return the process time as a float (CPU time used by the process). * In JavaScript, this approximates using Date.now(). */ declare function processTime(): number; /** * Return the process time in nanoseconds. */ declare function processTimeNs(): bigint; /** * Return the current thread's CPU time (same as processTime in JavaScript). */ declare function threadTime(): number; /** * Return the current thread's CPU time in nanoseconds. */ declare function threadTimeNs(): bigint; type timeModule_StructTime = StructTime; declare const timeModule_altzone: typeof altzone; declare const timeModule_asctime: typeof asctime; declare const timeModule_ctime: typeof ctime; declare const timeModule_daylight: typeof daylight; declare const timeModule_gmtime: typeof gmtime; declare const timeModule_localtime: typeof localtime; declare const timeModule_mktime: typeof mktime; declare const timeModule_monotonic: typeof monotonic; declare const timeModule_monotonicNs: typeof monotonicNs; declare const timeModule_perfCounter: typeof perfCounter; declare const timeModule_perfCounterNs: typeof perfCounterNs; declare const timeModule_processTime: typeof processTime; declare const timeModule_processTimeNs: typeof processTimeNs; declare const timeModule_sleep: typeof sleep; declare const timeModule_strftime: typeof strftime; declare const timeModule_strptime: typeof strptime; declare const timeModule_threadTime: typeof threadTime; declare const timeModule_threadTimeNs: typeof threadTimeNs; declare const timeModule_time: typeof time; declare const timeModule_timeNs: typeof timeNs; declare const timeModule_timezone: typeof timezone; declare const timeModule_tzname: typeof tzname; declare namespace timeModule { export { type timeModule_StructTime as StructTime, timeModule_altzone as altzone, timeModule_asctime as asctime, timeModule_ctime as ctime, timeModule_daylight as daylight, timeModule_gmtime as gmtime, timeModule_localtime as localtime, timeModule_mktime as mktime, timeModule_monotonic as monotonic, timeModule_monotonicNs as monotonicNs, timeModule_perfCounter as perfCounter, timeModule_perfCounterNs as perfCounterNs, timeModule_processTime as processTime, timeModule_processTimeNs as processTimeNs, timeModule_sleep as sleep, timeModule_strftime as strftime, timeModule_strptime as strptime, timeModule_threadTime as threadTime, timeModule_threadTimeNs as threadTimeNs, timeModule_time as time, timeModule_timeNs as timeNs, timeModule_timezone as timezone, timeModule_tzname as tzname }; } export { type StructTime as S, altzone as a, asctime as b, ctime as c, daylight as d, monotonic as e, monotonicNs as f, gmtime as g, perfCounterNs as h, processTime as i, processTimeNs as j, strftime as k, localtime as l, mktime as m, strptime as n, threadTime as o, perfCounter as p, threadTimeNs as q, time as r, sleep as s, timeModule as t, timeNs as u, timezone as v, tzname as w };