Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Epoch milliseconds int64 time encoder #1279

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions zapcore/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions zapcore/json_encoder_impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down