Skip to content

Commit

Permalink
Fix console formatter for timestampunixnano (#502)
Browse files Browse the repository at this point in the history
Co-authored-by: Ted Lilley <[email protected]>
  • Loading branch information
binaryphile and Ted Lilley authored Nov 3, 2022
1 parent e3027a5 commit 5bdc93f
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions console.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 5bdc93f

Please sign in to comment.