Artifact 68dc929b656dad6828fa01ef63f4b8c394c1f002b4828389aba7c7e1deb9f001:
- File
julian_test.go
— part of check-in
[f5744359d3]
at
2026-04-19 16:30:54
on branch trunk
— Initial open source release
libfossil is a pure-Go implementation of the Fossil SCM, reading and writing the same .fossil SQLite repository format as upstream Fossil.
This is the first public release of code that previously lived in a private repository. The module path is github.com/danmestas/libfossil and the binary is named libfossil to avoid $PATH collisions with upstream fossil.
Included: - Repo lifecycle (create, clone), checkout/checkin, timeline, merge, diff, annotate, shun, tag, branch, bisect, stash, undo/redo - Sync-over-HTTP protocol (client and handler) - Two SQLite drivers: modernc (pure Go, default) and ncruces (wasm-capable) - Observer interfaces (SyncObserver, CheckoutObserver) with an optional OpenTelemetry implementation in observer/otel (separate submodule) - Deterministic simulation testing harness with BUGGIFY fault injection - Kong-based embeddable CLI under cli/ and a standalone binary under cmd/libfossil/ (user: [email protected], size: 1335) [annotate] [blame] [check-ins using]
package libfossil import ( "math" "testing" "time" ) func TestTimeToJulian(t *testing.T) { epoch := time.Date(1970, 1, 1, 0, 0, 0, 0, time.UTC) got := TimeToJulian(epoch) if math.Abs(got-2440587.5) > 0.0001 { t.Fatalf("TimeToJulian(epoch) = %f, want 2440587.5", got) } } func TestJulianToTime(t *testing.T) { got := JulianToTime(2440587.5) epoch := time.Date(1970, 1, 1, 0, 0, 0, 0, time.UTC) diff := got.Sub(epoch) if diff < -time.Second || diff > time.Second { t.Fatalf("JulianToTime(2440587.5) = %v, want %v (diff=%v)", got, epoch, diff) } } func TestJulianRoundTrip(t *testing.T) { now := time.Now().UTC().Truncate(time.Millisecond) julian := TimeToJulian(now) back := JulianToTime(julian) diff := now.Sub(back) if diff < -time.Millisecond || diff > time.Millisecond { t.Fatalf("Round-trip failed: %v -> %f -> %v (diff=%v)", now, julian, back, diff) } } func TestKnownJulianDates(t *testing.T) { tests := []struct { name string t time.Time julian float64 }{ {"J2000", time.Date(2000, 1, 1, 12, 0, 0, 0, time.UTC), 2451545.0}, {"2026-03-14 noon", time.Date(2026, 3, 14, 12, 0, 0, 0, time.UTC), 2461114.0}, } for _, tt := range tests { got := TimeToJulian(tt.t) if math.Abs(got-tt.julian) > 0.001 { t.Errorf("%s: TimeToJulian = %f, want %f", tt.name, got, tt.julian) } } }