From 5bdc93f7eb6ae1e8a973d3b92b98c0d918b0fd03 Mon Sep 17 00:00:00 2001 From: Ted Lilley Date: Wed, 2 Nov 2022 20:35:19 -0400 Subject: [PATCH] Fix console formatter for timestampunixnano (#502) Co-authored-by: Ted Lilley --- console.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/console.go b/console.go index 9cc3285..8b0e0c6 100644 --- a/console.go +++ b/console.go @@ -348,15 +348,19 @@ func consoleDefaultFormatTimestamp(timeFormat string, noColor bool) Formatter { if err != nil { t = tt.String() } else { - var sec, nsec int64 = i, 0 + var sec, nsec int64 + switch TimeFieldFormat { - case TimeFormatUnixMs: - nsec = int64(time.Duration(i) * time.Millisecond) - sec = 0 + case TimeFormatUnixNano: + sec, nsec = 0, i case TimeFormatUnixMicro: - nsec = int64(time.Duration(i) * time.Microsecond) - sec = 0 + sec, nsec = 0, int64(time.Duration(i)*time.Microsecond) + case TimeFormatUnixMs: + sec, nsec = 0, int64(time.Duration(i)*time.Millisecond) + default: + sec, nsec = i, 0 } + ts := time.Unix(sec, nsec) t = ts.Format(timeFormat) }