diff options
| author | Paul Buetow <paul@buetow.org> | 2024-10-10 10:34:26 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2024-10-10 10:34:26 +0300 |
| commit | 2f006df7a6aff97bb69bb2b6ffd607890863ebf9 (patch) | |
| tree | ecbe059b685d94cafb0b6e0e3b01b1d5bb36bd44 /internal/entry | |
| parent | be3abe2462bca511ede21cacd1e5a3690b5aa745 (diff) | |
initial timestamp package
Diffstat (limited to 'internal/entry')
| -rw-r--r-- | internal/entry/entry.go | 17 | ||||
| -rw-r--r-- | internal/entry/entry_test.go | 5 |
2 files changed, 7 insertions, 15 deletions
diff --git a/internal/entry/entry.go b/internal/entry/entry.go index 0874e64..5a9c0fb 100644 --- a/internal/entry/entry.go +++ b/internal/entry/entry.go @@ -7,7 +7,7 @@ import ( "strings" "time" - "codeberg.org/snonux/gos/internal/format" + "codeberg.org/snonux/gos/internal/timestamp" ) type State int @@ -31,9 +31,6 @@ func (s State) String() string { } } -// The time this code was written a:round, actually. -const oldestValidTime = "20240912-102800" - type Entry struct { Path string Time time.Time @@ -42,7 +39,7 @@ type Entry struct { func (e Entry) String() string { return fmt.Sprintf("Path:%s;Stamp:%s,State:%s", - e.Path, e.Time.Format(format.Time), e.State) + e.Path, e.Time.Format(timestamp.Format), e.State) } var Zero = Entry{} @@ -67,16 +64,11 @@ func New(filePath string) (Entry, error) { } var err error - if e.Time, err = time.Parse(format.Time, parts[len(parts)-2]); err != nil { + if e.Time, err = timestamp.Parse(parts[len(parts)-2]); err != nil { return e, err } - oldestValid, err := time.Parse(format.Time, oldestValidTime) - if err != nil { - panic(err) - } - - if e.Time.Before(oldestValid) { + if e.Time.Before(timestamp.OldestValidTime()) { return e, fmt.Errorf("entry time does not seem legit, it is too old: %v", e.Time) } @@ -96,6 +88,7 @@ func (e *Entry) MarkPosted() error { return errors.New("entry is already posted") } // TODO: Also update the timestamp to reflect the posting time in the file path. + // Write a timestamp.Update() function for this. if err := os.Rename(e.Path, strings.TrimSuffix(e.Path, ".queued")+".posted"); err != nil { return err } diff --git a/internal/entry/entry_test.go b/internal/entry/entry_test.go index 5e3a5d3..0ec8166 100644 --- a/internal/entry/entry_test.go +++ b/internal/entry/entry_test.go @@ -3,9 +3,8 @@ package entry import ( "fmt" "testing" - "time" - "codeberg.org/snonux/gos/internal/format" + "codeberg.org/snonux/gos/internal/timestamp" ) func TestEntry(t *testing.T) { @@ -27,7 +26,7 @@ func TestEntry(t *testing.T) { t.Errorf("expected state %s but got %s", state, ent.State) } - expectedTime, err := time.Parse(format.Time, stamp) + expectedTime, err := timestamp.Parse(stamp) if err != nil { t.Error(err) } |
