From 5755ccef01fd23f2edc44390a13168f5d2fdc64b Mon Sep 17 00:00:00 2001 From: Philipp Wolfer Date: Sat, 9 Dec 2023 22:39:08 +0100 Subject: [PATCH] Do not apply locale formatting to Unix timestamps --- internal/cli/transfer.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/internal/cli/transfer.go b/internal/cli/transfer.go index 7f3c3c8..3816d96 100644 --- a/internal/cli/transfer.go +++ b/internal/cli/transfer.go @@ -18,6 +18,7 @@ package cli import ( "fmt" "math" + "strconv" "sync" "time" @@ -106,7 +107,7 @@ func (c *TransferCmd[E, I, R]) Transfer(exp backends.ExportProcessor[R], imp bac if err != nil { return err } - fmt.Println(i18n.Tr("From timestamp: %v (%v)", timestamp, timestamp.Unix())) + printTimestamp("From timestamp: %v (%v)", timestamp) // Prepare progress bars exportProgress := make(chan models.Progress) @@ -129,8 +130,7 @@ func (c *TransferCmd[E, I, R]) Transfer(exp backends.ExportProcessor[R], imp bac wg.Wait() progress.Wait() if result.Error != nil { - fmt.Println(i18n.Tr("Import failed, last reported timestamp was %v (%v)", - result.LastTimestamp, result.LastTimestamp.Unix())) + printTimestamp("Import failed, last reported timestamp was %v (%s)", result.LastTimestamp) return result.Error } fmt.Println(i18n.Tr("Imported %v of %v %s into %v.", @@ -168,7 +168,11 @@ func (c *TransferCmd[E, I, R]) updateTimestamp(result models.ImportResult, oldTi if result.LastTimestamp.Unix() < oldTimestamp.Unix() { result.LastTimestamp = oldTimestamp } - fmt.Println(i18n.Tr("Latest timestamp: %v (%v)\n", result.LastTimestamp, result.LastTimestamp.Unix())) + printTimestamp("Latest timestamp: %v (%v)", result.LastTimestamp) err := c.db.SetImportTimestamp(c.sourceName, c.targetName, c.entity, result.LastTimestamp) return err } + +func printTimestamp(s string, t time.Time) { + fmt.Println(i18n.Tr(s, t, strconv.FormatInt(t.Unix(), 10))) +}