This repository contains single-file examples that compute Swatch Internet Time ("beats") using the canonical definition used by the SwatchTime organization.
Canonical rules
- Reference zone: Biel Mean Time (BMT) = UTC+1 (fixed offset, no DST)
- One beat = 86.4 seconds (86400 / 1000)
- Beats run from
@000at Biel midnight (00:00:00 UTC+1) through@999just before the next Biel midnight
Computation (pseudocode)
// JavaScript-style pseudocode
now = new Date()
utcSeconds = now.getUTCHours() * 3600 + now.getUTCMinutes() * 60 + now.getUTCSeconds()
bielSeconds = (utcSeconds + 3600 + 24*3600) % (24*3600)
beat = Math.floor(bielSeconds / 86.4) % 1000
display = `@${String(beat).padStart(3,'0')}`
Quick test vectors
2025-01-01T00:00:00Z→ Biel 01:00:00 →@0412025-01-01T23:00:00Z→ Biel 00:00:00 (next day) →@0002025-06-01T12:34:56Z→ Biel 13:34:56 →@565
Files
bash/get_swatch_time.sh— Bash example. Run withbash bash/get_swatch_time.sh.c/get_swatch_time.c— C single-file example. Build:gcc -std=c11 c/get_swatch_time.c -o get_swatch_time -lm.cpp/get_swatch_time.cpp— C++ single-file example. Build:g++ -std=c++11 cpp/get_swatch_time.cpp -o get_swatch_time.csharp/get_swatch_time.cs— C# example. Run withdotnet scriptor compile as a console app.elixir/get_swatch_time.exs— Elixir example. Run withelixir elixir/get_swatch_time.exs.go/get_swatch_time.go— Go single-file example. Build or run withgo run go/get_swatch_time.go.haskell/get_swatch_time.hs— Haskell example. Run withrunhaskell haskell/get_swatch_time.hsor compile withghc.java/GetSwatchTime.java— Java example. Build/run withjavac java/GetSwatchTime.java && java -cp java GetSwatchTime.js/getSwatchTime.js— JavaScript single-file example. Run withnode js/getSwatchTime.jsor open in browser console.kotlin/get_swatch_time.kt— Kotlin example. Run as script withkotlinc -script kotlin/get_swatch_time.ktor compile withkotlinc.lua/get_swatch_time.lua— Lua example. Run withlua lua/get_swatch_time.lua.php/get_swatch_time.php— PHP example. Run withphp php/get_swatch_time.php.powershell/get_swatch_time.ps1— Windows PowerShell example. Run in PowerShell:powershell -File powershell/get_swatch_time.ps1.python/get_swatch_time.py— Python 3 single-file example. Run withpython3 python/get_swatch_time.py.ruby/get_swatch_time.rb— Ruby example. Run withruby ruby/get_swatch_time.rb.rust/get_swatch_time.rs— Rust single-file example that usesSystemTime. Compile withrustc rust/get_swatch_time.rs && ./get_swatch_timeor run withcargoif you prefer.swift/get_swatch_time.swift— Swift example. Run withswift swift/get_swatch_time.swift.
Usage
Each file prints the current Swatch beat to stdout/console. Some files accept an ISO timestamp or include example test lines you can uncomment to test known vectors.
When displaying centibeats (two decimal places), implementations that round the fractional beats to 2 decimals before wrapping can briefly produce a value of 1000.00 (for example when the raw value is 999.995). To avoid this transient display, round first then wrap values >= 1000 back into range (subtract 1000 or set to 0) before formatting for display.
Canonical JavaScript snippet each implementation should follow:
const rawBeats = bielSeconds / 86.4;
let rounded = Math.round(rawBeats * 100) / 100; // 2 decimals
if (rounded >= 1000) rounded = rounded - 1000; // wrap 1000 -> 0
const display = rounded.toFixed(2);This preserves human-friendly rounding while ensuring the UI never shows 1000.00 briefly.
License