Epoch
time_epoch¶
Return the current Unix epoch in seconds. Selects the fastest available method at load time: EPOCHSECONDS (bash 5+ / zsh), printf %T (bash 4.2+), date, perl, or a portable pure-shell fallback.
Exit codes¶
- 0: Always
Output on stdout¶
- Current Unix epoch as an integer
time_epoch_in¶
Return the current Unix epoch expressed in a larger time unit.
Example¶
time_epoch_in days
time_epoch_in hours
Arguments¶
- $1 (string): Unit: seconds, minutes, hours, or days
Exit codes¶
- 0: Always
- 1: Unrecognised unit
Output on stdout¶
- Integer epoch value in the requested unit
time_ldaptime_to_epoch¶
Convert a Windows/LDAP 100-nanosecond interval timestamp to a Unix epoch. The LDAP timestamp counts 100ns intervals since 1 January 1601.
Example¶
time_ldaptime_to_epoch 132000000000000000 # => Unix epoch integer
Arguments¶
- $1 (int): LDAP timestamp (100-nanosecond intervals since 1601-01-01)
Exit codes¶
- 0: Always
Output on stdout¶
- Unix epoch as an integer
time_date_to_epoch¶
Convert an SSL-style date/time string to a Unix epoch using perl. Intended for systems where date(1) does not support the -d flag. Expected input format: "Nov 10 2034 21:19:01"
Arguments¶
- $1 (string): Month (e.g. Nov)
- $2 (int): Day of month
- $3 (int): Four-digit year
- $4 (string): Time as HH:MM:SS
Exit codes¶
- 0: Always
- 1: perl not available
Output on stdout¶
- Unix epoch integer
time_epoch_ms¶
Get the current Unix epoch in milliseconds. Uses date %3N (milliseconds) when available; falls back to seconds * 1000 for systems where %N is unsupported (e.g. macOS date).
Example¶
time_epoch_ms # => 1710000000123
Exit codes¶
- 0: Always
Output on stdout¶
- Current epoch in milliseconds
time_sleep_until¶
Sleep until a given Unix epoch second (or epoch millisecond). If the target time is in the past, returns immediately. Pass --ms to treat the argument as milliseconds.
Example¶
time_sleep_until $(( $(date +%s) + 30 )) # sleep ~30s from now
time_sleep_until --ms $(( $(time_epoch_ms) + 5000 ))
Options¶
- [--ms] flag Treat $1 as epoch milliseconds rather than seconds
Arguments¶
- $1 (int): Target epoch (seconds, or ms when --ms given)
Exit codes¶
- 0: Awoke at or after target; 1 Bad argument