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

Fix handling of Time values out of UnixNano range #804

Merged
merged 3 commits into from
Mar 27, 2020
Merged

Fix handling of Time values out of UnixNano range #804

merged 3 commits into from
Mar 27, 2020

Conversation

prashantv
Copy link
Collaborator

Fixes #737, #803.

Time values are encoded by storing the UnixNano representation, but this
fails when the value of UnixNano is out of int64 range, see docs:

https://golang.org/pkg/time/#Time.UnixNano

The result is undefined if the Unix time in nanoseconds cannot be
represented by an int64 (a date before the year 1678 or after 2262)

Fix this by storing values outside of UnixNano range as-is rather
than using UnixNano with a new Field type.

Fixes #737, #803.

Time values are encoded by storing the UnixNano representation, but this
fails when the value of UnixNano is out of int64 range, see docs:

https://golang.org/pkg/time/#Time.UnixNano
> The result is undefined if the Unix time in nanoseconds cannot be
represented by an int64 (a date before the year 1678 or after 2262)

Fix this by storing values outside of UnixNano range as-is rather
than using UnixNano with a new Field type.
@prashantv prashantv requested a review from abhinav March 24, 2020 18:54
@codecov
Copy link

codecov bot commented Mar 24, 2020

Codecov Report

Merging #804 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #804   +/-   ##
=======================================
  Coverage   98.31%   98.31%           
=======================================
  Files          43       43           
  Lines        2311     2315    +4     
=======================================
+ Hits         2272     2276    +4     
  Misses         32       32           
  Partials        7        7           
Impacted Files Coverage Δ
field.go 100.00% <100.00%> (ø)
zapcore/field.go 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f994215...0182292. Read the comment docs.

@prashantv prashantv changed the title Fix handling of Time values out of UnixNano rnage Fix handling of Time values out of UnixNano range Mar 25, 2020
field.go Outdated Show resolved Hide resolved
@@ -164,6 +165,10 @@ func TestFields(t *testing.T) {
}

func TestEquals(t *testing.T) {
timeOutOfRange := time.Unix(0, math.MaxInt64).Add(time.Nanosecond)
timeOutOfRangeNano := time.Unix(0, timeOutOfRange.UnixNano())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should try out of range in both directions.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 done

zapcore/field_test.go Outdated Show resolved Hide resolved
@prashantv prashantv merged commit ec2dc45 into master Mar 27, 2020
@prashantv prashantv deleted the time branch March 27, 2020 04:34
uvfive pushed a commit to bxsmart/zap that referenced this pull request May 21, 2020
Fixes uber-go#737, uber-go#803.

Time values are encoded by storing the UnixNano representation, but this
fails when the value of UnixNano is out of int64 range, see docs:

https://golang.org/pkg/time/#Time.UnixNano
> The result is undefined if the Unix time in nanoseconds cannot be
represented by an int64 (a date before the year 1678 or after 2262)

Fix this by storing values outside of UnixNano range as-is rather
than using UnixNano with a new Field type.
cgxxv pushed a commit to cgxxv/zap that referenced this pull request Mar 25, 2022
Fixes uber-go#737, uber-go#803.

Time values are encoded by storing the UnixNano representation, but this
fails when the value of UnixNano is out of int64 range, see docs:

https://golang.org/pkg/time/#Time.UnixNano
> The result is undefined if the Unix time in nanoseconds cannot be
represented by an int64 (a date before the year 1678 or after 2262)

Fix this by storing values outside of UnixNano range as-is rather
than using UnixNano with a new Field type.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

inconsistent display of zap.Time field with zero time struct
2 participants