From e5281120b4bcb922ce6d9fd2328b9a3c42bd6d49 Mon Sep 17 00:00:00 2001 From: Harish Kukreja Date: Fri, 28 Apr 2023 22:24:45 -0400 Subject: [PATCH 1/2] feat: epoch int64 milliseconds time encoder --- zapcore/encoder.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/zapcore/encoder.go b/zapcore/encoder.go index 5769ff3e4..3ae040e40 100644 --- a/zapcore/encoder.go +++ b/zapcore/encoder.go @@ -108,6 +108,13 @@ func EpochMillisTimeEncoder(t time.Time, enc PrimitiveArrayEncoder) { enc.AppendFloat64(millis) } +// EpochMillisInt64TimeEncoder serializes a time.Time to a 64-bit signed integer number of +// milliseconds since the Unix epoch. +func EpochMillisInt64TimeEncoder(t time.Time, enc PrimitiveArrayEncoder) { + millis := t.UnixMilli() + enc.AppendInt64(millis) +} + // EpochNanosTimeEncoder serializes a time.Time to an integer number of // nanoseconds since the Unix epoch. func EpochNanosTimeEncoder(t time.Time, enc PrimitiveArrayEncoder) { From f0402f59f8254050b329d150a54f52ee2d9b8eba Mon Sep 17 00:00:00 2001 From: Harish Kukreja Date: Fri, 28 Apr 2023 22:25:34 -0400 Subject: [PATCH 2/2] test: case for epoch int64 milliseconds encoder --- zapcore/json_encoder_impl_test.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/zapcore/json_encoder_impl_test.go b/zapcore/json_encoder_impl_test.go index fde241f56..1eecedcea 100644 --- a/zapcore/json_encoder_impl_test.go +++ b/zapcore/json_encoder_impl_test.go @@ -473,6 +473,11 @@ func TestJSONEncoderTimeArrays(t *testing.T) { encoder: EpochMillisTimeEncoder, want: `[1008720000000,1040169600000,1071619200000]`, }, + { + desc: "epoch millis as int64", + encoder: EpochMillisInt64TimeEncoder, + want: `[1008720000000,1040169600000,1071619200000]`, + }, { desc: "iso8601", encoder: ISO8601TimeEncoder,