From a48ac8fa791c95462355e2c2d9511f859535a9f7 Mon Sep 17 00:00:00 2001 From: Denys Smirnov Date: Mon, 6 Oct 2025 20:24:50 +0300 Subject: [PATCH] Fix zero time handling in mono package. --- .changeset/mono-fix-zero.md | 5 +++++ utils/mono/mono.go | 3 +++ utils/mono/mono_test.go | 17 +++++++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 .changeset/mono-fix-zero.md create mode 100644 utils/mono/mono_test.go diff --git a/.changeset/mono-fix-zero.md b/.changeset/mono-fix-zero.md new file mode 100644 index 000000000..04b637d07 --- /dev/null +++ b/.changeset/mono-fix-zero.md @@ -0,0 +1,5 @@ +--- +"@livekit/protocol": patch +--- + +Fix zero time handling in mono package. diff --git a/utils/mono/mono.go b/utils/mono/mono.go index 624daaa82..eab94df71 100644 --- a/utils/mono/mono.go +++ b/utils/mono/mono.go @@ -22,6 +22,9 @@ var ( ) func FromTime(t time.Time) time.Time { + if t.IsZero() { + return time.Time{} + } return epoch.Add(t.Sub(epoch)) } diff --git a/utils/mono/mono_test.go b/utils/mono/mono_test.go new file mode 100644 index 000000000..a3a3c4b6e --- /dev/null +++ b/utils/mono/mono_test.go @@ -0,0 +1,17 @@ +package mono + +import ( + "testing" + "time" + + "github.com/stretchr/testify/require" +) + +func TestMonoZero(t *testing.T) { + ts := time.Time{} + ts2 := FromTime(ts) + require.True(t, ts.IsZero()) + require.True(t, ts2.IsZero()) + require.True(t, ts.Equal(ts2)) + require.Equal(t, ts.String(), ts2.String()) +}