memory: dates in memory_search and the dream's notes are the user's local time, with the hour and offset (Norethcy on X)
memory_search printed a memory's Updated as a bare UTC date, so a memory
saved at 04:30 on the 11th in Shanghai read as the 10th, and the stored
times were written in UTC. Now:
- every memory time is written in the local zone (now() instead of
now().UTC()): created, updated, edited, used, sync tombstones, digest
publish time;
- memory_search shows 2026-11-11T04:30+08:00 (memoryStamp);
- the dream's notes list the creation day in local time, as "Today" there
already was.
Old data: the file already held full timestamps, only in UTC ("...Z").
They parse as the same instants and are shown in local time, so no
migration; they are rewritten with a local offset when next changed.
There is no date filter in memory_search, and the Memory tab shows no
dates, so nothing else read the UTC day.
Tests: TestMemorySearchDatesInLocalTime (gateway) with time.Local at +08:00
reads an old "Z" memory and checks a new save is stored with +08:00. Red on
the old code both halves, broken by hand: the DateOnly line printed
2026-11-10, and now().UTC() in memory.go failed the saved-zone check.
Run with TZ=UTC and TZ=Asia/Shanghai on mote: internal/memory,
internal/memdistill, internal/gui (memory tests) ok; gofmt clean;
go vet ./..., linux nogui, windows ok. Not run: full ./... suite before
the tag (started after it), GUI browser tests (no assets changed).
This commit is contained in:
@@ -28,6 +28,11 @@ A memory is one short text (`MaxText` runes) with:
|
||||
| `status` | active, candidate, archived, superseded | only active ones are searched by default and digested. Candidates wait under "To review". |
|
||||
| `pinned` | bool | first in lists and digests. |
|
||||
|
||||
Times (`created`, `updated`) are RFC3339 in the zone the memory was saved
|
||||
in, with its offset. `memory_search` and the dream's notes show them in the
|
||||
reader's local zone (`memoryStamp`, `TestMemorySearchDatesInLocalTime`); a
|
||||
memory saved earlier, stored as UTC, reads the same way.
|
||||
|
||||
`Save` keeps one memory per scope and text (`TestSaveKeepsOneOfTheSameText`)
|
||||
and refuses empty or over-long text, an unknown kind and a bad scope
|
||||
(`TestSaveRefusesWhatIsntAMemory`).
|
||||
|
||||
@@ -369,7 +369,7 @@ func memoryLine(m *memory.Memory, c memoryCaller) string {
|
||||
if m.Pinned {
|
||||
l += ", pinned"
|
||||
}
|
||||
l += ", " + m.Updated.Format(time.DateOnly) + ": " + strings.Join(strings.Fields(m.Text), " ")
|
||||
l += ", " + memoryStamp(m.Updated) + ": " + strings.Join(strings.Fields(m.Text), " ")
|
||||
if m.Why != "" {
|
||||
l += " (why: " + strings.Join(strings.Fields(m.Why), " ") + ")"
|
||||
}
|
||||
@@ -463,3 +463,10 @@ func memoryForget(a memoryArgs) (string, error) {
|
||||
}
|
||||
return "Forgotten: [" + m.ID + "] " + strings.Join(strings.Fields(m.Text), " "), nil
|
||||
}
|
||||
|
||||
// memoryStamp is when a memory was last changed, in the reader's own zone
|
||||
// with its offset (2026-11-11T04:30+08:00). A date alone, taken in UTC,
|
||||
// put a memory on the day before or after the one the user lived
|
||||
// (Norethcy on X). Memories saved before this are stored in UTC ("…Z")
|
||||
// and are shown the same way.
|
||||
func memoryStamp(t time.Time) string { return t.In(time.Local).Format("2006-01-02T15:04Z07:00") }
|
||||
|
||||
@@ -6,8 +6,10 @@ import (
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/memory"
|
||||
"github.com/yetone/magpie/internal/settings"
|
||||
@@ -250,3 +252,38 @@ func TestRootDirs(t *testing.T) {
|
||||
t.Fatalf("dirs %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
// A memory is dated in the reader's own zone, with the time and its
|
||||
// offset: at 04:30 in Shanghai on the 11th, UTC is still the 10th
|
||||
// (Norethcy on X). One saved before, stored as "…Z", reads the same way.
|
||||
func TestMemorySearchDatesInLocalTime(t *testing.T) {
|
||||
fresh(t)
|
||||
oldLocal := time.Local
|
||||
time.Local = time.FixedZone("CST", 8*3600)
|
||||
t.Cleanup(func() { time.Local = oldLocal })
|
||||
|
||||
old := `{"memories":[{"id":"m1","text":"Heavy tests run on mote","kind":"fact","scope":"global","origin":"agent","status":"active","created":"2026-11-10T20:30:00Z","updated":"2026-11-10T20:30:00Z"}]}`
|
||||
if err := os.MkdirAll(filepath.Dir(memory.Path()), 0o700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(memory.Path(), []byte(old), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
h := lanGuard(New().Handler())
|
||||
said, bad := memPost(t, h, memorySearchTool, `{"query":"mote"}`)
|
||||
if bad || !strings.Contains(said, ", 2026-11-11T04:30+08:00: Heavy tests run on mote") {
|
||||
t.Fatalf("an old UTC memory: %s", said)
|
||||
}
|
||||
|
||||
// a new one is kept with the zone it was saved in
|
||||
if _, bad := memPost(t, h, memorySaveTool, `{"text":"Answer in Chinese","kind":"preference"}`); bad {
|
||||
t.Fatal("save failed")
|
||||
}
|
||||
b, _ := os.ReadFile(memory.Path())
|
||||
if !strings.Contains(string(b), `"updated": "`) && !strings.Contains(string(b), `"updated":"`) {
|
||||
t.Fatalf("no updated in %s", b)
|
||||
}
|
||||
if !regexp.MustCompile(`"updated":\s*"[^"]*\+08:00"`).Match(b) {
|
||||
t.Fatalf("saved in UTC, not the local zone: %s", b)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@ func listing(ms []*memory.Memory) string {
|
||||
var b strings.Builder
|
||||
fmt.Fprintf(&b, "Today: %s\n\nNotes:\n", now().Format("2006-01-02"))
|
||||
for i, m := range ms {
|
||||
fmt.Fprintf(&b, "n%d | %s | %s | used %d× | ", i+1, m.Kind, m.Created.Format("2006-01-02"), m.Uses)
|
||||
fmt.Fprintf(&b, "n%d | %s | %s | used %d× | ", i+1, m.Kind, m.Created.In(time.Local).Format("2006-01-02"), m.Uses)
|
||||
if memory.Fixed(m) {
|
||||
b.WriteString("fixed | ")
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ func publish(f *file) {
|
||||
}
|
||||
}
|
||||
f.Digest = d
|
||||
f.Published = now().UTC()
|
||||
f.Published = now()
|
||||
}
|
||||
|
||||
// Publish makes what memory holds now the digest agents are given. It
|
||||
|
||||
@@ -369,7 +369,7 @@ func norm(s string) string {
|
||||
// user threw the same text away before (dismissed), or set it aside in
|
||||
// that scope: m is nil then, or the one set aside, and added false.
|
||||
func Save(in Input, origin string, src *Source, proj *Project) (m *Memory, added bool, err error) {
|
||||
t := now().UTC()
|
||||
t := now()
|
||||
m = &Memory{Kind: Fact, Scope: Global, Origin: origin, Status: Active, Created: t, Updated: t}
|
||||
if origin == FromUser {
|
||||
m.Edited = t
|
||||
@@ -512,7 +512,7 @@ func editIn(f *file, m *Memory, in Input, byUser bool) error {
|
||||
if byUser && (in.Text != nil || in.Kind != nil || in.Scope != nil || in.Why != nil) {
|
||||
c.Origin = FromUser
|
||||
}
|
||||
c.Updated = now().UTC()
|
||||
c.Updated = now()
|
||||
if byUser {
|
||||
c.Edited = c.Updated
|
||||
}
|
||||
@@ -579,7 +579,7 @@ func touch(ids []string) {
|
||||
if len(ids) == 0 {
|
||||
return
|
||||
}
|
||||
t := now().UTC()
|
||||
t := now()
|
||||
f, err := view()
|
||||
if err != nil {
|
||||
return
|
||||
|
||||
@@ -246,7 +246,7 @@ func Promote(ids []string) (*Memory, error) {
|
||||
ms = append(ms, m)
|
||||
}
|
||||
slices.SortFunc(ms, keptFirst)
|
||||
t := now().UTC()
|
||||
t := now()
|
||||
// the same text global already: that one is kept, and these go into it
|
||||
for _, g := range f.Memories {
|
||||
if g.Scope == Global && (g.Status == Active || g.Status == Candidate) && norm(g.Text) == norm(ms[0].Text) {
|
||||
@@ -291,7 +291,7 @@ func MadeSkill(id, name string) error {
|
||||
if m == nil {
|
||||
return ErrNotFound
|
||||
}
|
||||
t := now().UTC()
|
||||
t := now()
|
||||
m.Skill = name
|
||||
m.Status = Archived
|
||||
m.Updated, m.Edited = t, t
|
||||
|
||||
@@ -23,7 +23,7 @@ func removed(f *file, id string) {
|
||||
if f.Removed == nil {
|
||||
f.Removed = map[string]time.Time{}
|
||||
}
|
||||
f.Removed[id] = now().UTC()
|
||||
f.Removed[id] = now()
|
||||
}
|
||||
|
||||
// Bundle is what of memory goes to another computer, in a backup or a
|
||||
@@ -99,7 +99,7 @@ func Combine(a, b *Bundle) *Bundle {
|
||||
b = &Bundle{}
|
||||
}
|
||||
out := &Bundle{Memories: []*Memory{}}
|
||||
cut := now().UTC().Add(-keepRemoved)
|
||||
cut := now().Add(-keepRemoved)
|
||||
for _, r := range []map[string]time.Time{a.Removed, b.Removed} {
|
||||
for id, t := range r {
|
||||
if t.Before(cut) {
|
||||
|
||||
@@ -68,7 +68,7 @@ func live(m *Memory) bool { return m != nil && (m.Status == Active || m.Status =
|
||||
func Tidy(p Plan) ([]Change, error) {
|
||||
var out []Change
|
||||
err := change(func(f *file) error {
|
||||
t := now().UTC()
|
||||
t := now()
|
||||
for _, mg := range p.Merges {
|
||||
var ms []*Memory
|
||||
for _, id := range mg.IDs {
|
||||
@@ -175,7 +175,7 @@ func Tidy(p Plan) ([]Change, error) {
|
||||
func Untidy(cs []Change) (int, error) {
|
||||
n := 0
|
||||
err := change(func(f *file) error {
|
||||
t := now().UTC()
|
||||
t := now()
|
||||
for i := len(cs) - 1; i >= 0; i-- {
|
||||
c := cs[i]
|
||||
for k, id := range c.IDs {
|
||||
|
||||
Reference in New Issue
Block a user