fix(time): correct export data timestamp conversions (#586)

This commit is contained in:
Roger authored and GitHub committed 2026-04-23 20:39:56 +08:00
1 parent 0c6c781567
commit 50c4ea84cb
14 files changed
+228 -30

No files matched your search

+30
View File
@@ -5,6 +5,7 @@ import (
"path/filepath"
"strings"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@@ -334,3 +335,32 @@ func TestExtractCategory(t *testing.T) {
assert.Empty(t, data.CreditCards)
})
}
// Anchor: 2024-01-15T10:30:00Z, in seconds past the Core Data epoch (2001-01-01Z).
const anchorCoreDataSeconds = 1705314600 - 978307200
func TestCoredataTimestamp_AnchorDate(t *testing.T) {
got := coredataTimestamp(float64(anchorCoreDataSeconds))
want := time.Date(2024, 1, 15, 10, 30, 0, 0, time.UTC)
assert.Equal(t, want, got)
}
func TestCoredataTimestamp_EpochZero(t *testing.T) {
assert.True(t, coredataTimestamp(0).IsZero())
}
func TestCoredataTimestamp_NegativeReturnsZeroTime(t *testing.T) {
assert.True(t, coredataTimestamp(-1).IsZero())
}
func TestCoredataTimestamp_FractionalSecondsPreserved(t *testing.T) {
got := coredataTimestamp(float64(anchorCoreDataSeconds) + 0.5)
assert.Equal(t, 500*int64(time.Millisecond), int64(got.Nanosecond()))
}
func TestCoredataTimestamp_AlwaysUTC(t *testing.T) {
// assert.Same: pointer equality reliably catches any regression that
// leaks time.Local, independent of the runner's configured TZ.
got := coredataTimestamp(float64(anchorCoreDataSeconds))
assert.Same(t, time.UTC, got.Location())
}