https://github.com/SuaveIV/nu_script_time_sync
A Nushell script that checks whether your system clock has drifted, using the Time.now API.
https://github.com/SuaveIV/nu_script_time_sync
nushell nushell-script time-sync timenow
Last synced: 8 days ago
JSON representation
A Nushell script that checks whether your system clock has drifted, using the Time.now API.
- Host: GitHub
- URL: https://github.com/SuaveIV/nu_script_time_sync
- Owner: SuaveIV
- License: mit
- Created: 2026-03-11T07:01:26.000Z (about 2 months ago)
- Default Branch: main
- Last Pushed: 2026-03-11T07:32:20.000Z (about 2 months ago)
- Last Synced: 2026-03-11T14:10:22.090Z (about 2 months ago)
- Topics: nushell, nushell-script, time-sync, timenow
- Language: Nushell
- Homepage:
- Size: 9.77 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-nu - nu_script_time_sync
README
# time-sync.nu
[](https://www.nushell.sh/)
[](https://time.now/developer)
A Nushell script to check if your system clock is drifting. It queries the [Time.now API](https://time.now/developer/), compares the result to your local time, and tells you if your clock is out of sync.
## Why I wrote this
System clocks drift. Most of the time NTP handles it, but when it fails (suspended VMs, weird service configs, air-gapped machines), it fails silently and messes up your logs. I wanted a quick sanity check without having to remember the flags for `timedatectl` or parse `ntpq` output.
## Usage
### Run it once
```nushell
nu time-sync.nu
```
### Install as a command
Use it as a module in your `config.nu` to use it anywhere:
```nushell
use /path/to/time-sync.nu
```
Then run it:
```nushell
time-sync
time-sync --max-offset 10sec
time-sync --raw
```
This prints a formatted report:

For a one-line summary, use `-1`:

### Flags
| Flag | Default | What it does |
| ------ | --------- | -------------- |
| `--max-offset` | `5sec` | Allowed drift before the clock is marked out of sync |
| `--max-rtt` | `2sec` | Network latency cutoff. Above this, the check is flagged as unreliable |
| `--one-line` `-1` | (none) | Single-line output: `IN SYNC 14:32:07 → 14:32:07 312ms` |
| `--raw` `-r` | (none) | Returns a raw record instead of text. Best for scripting. |
### Scripting
```nushell
time-sync --raw | if not $in.synced { print "Clock drift detected!" }
```
The `--raw` flag returns a record with these fields: `local`, `network`, `drift`, `rtt`, `synced`, `reliable`, `timezone`.
## How it works
1. Records the time before and after the API call to measure round-trip latency.
2. Pulls UTC time from `https://time.now/developer/api/ip`.
3. Compares the network time to your local time.
4. Reports the drift, RTT, and sync status.
If the network is slow (RTT above `--max-rtt`), the script flags the result as unreliable. High latency inflates the apparent drift, so a slow API response doesn't actually mean your clock is wrong.
## Requirements
- [Nushell](https://www.nushell.sh/)
- Internet access
## Notes
- The script uses optional cell paths (`?`) to parse the API response. If the API changes its JSON shape slightly, the script shouldn't crash.
- Network errors surface as clean messages instead of raw Nu stack traces.
[World Time API by Time.Now](https://time.now)