Repository: kopia/kopia
Pull request #2362 (2022-09-03 03:19:03)

feat(snapshots): always serialize timestamps in UTC timezone
This actually fixes test runs on non-UTC timezone which were broken
by #2343.

codecov[bot]: # [Codecov](https://codecov.io/gh/kopia/kopia/pull/2362?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kopia) Report
> Merging [#2362](https://codecov.io/gh/kopia/kopia/pull/2362?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kopia) (359c46e) into [master](https://codecov.io/gh/kopia/kopia/commit/cbb7d68fb68771adec507a05d78ec2498798c593?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kopia) (cbb7d68) will **increase** coverage by `0.02%`.
> The diff coverage is `100.00%`.

```diff
@@            Coverage Diff             @@
##           master    #2362      +/-   ##
==========================================
+ Coverage   74.37%   74.40%   +0.02%     
==========================================
  Files         436      436              
  Lines       34313    34313              
==========================================
+ Hits        25520    25529       +9     
+ Misses       6936     6931       -5     
+ Partials     1857     1853       -4     
```


| [Impacted Files](https://codecov.io/gh/kopia/kopia/pull/2362?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kopia) | Coverage Δ | |
|---|---|---|
| [fs/utc\_timestamp.go](https://codecov.io/gh/kopia/kopia/pull/2362/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kopia#diff-ZnMvdXRjX3RpbWVzdGFtcC5nbw==) | `100.00% <100.00%> (ø)` | |
| [internal/cache/persistent\_lru\_cache.go](https://codecov.io/gh/kopia/kopia/pull/2362/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kopia#diff-aW50ZXJuYWwvY2FjaGUvcGVyc2lzdGVudF9scnVfY2FjaGUuZ28=) | `96.05% <0.00%> (-1.76%)` | :arrow_down: |
| [internal/server/source\_manager.go](https://codecov.io/gh/kopia/kopia/pull/2362/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kopia#diff-aW50ZXJuYWwvc2VydmVyL3NvdXJjZV9tYW5hZ2VyLmdv) | `82.82% <0.00%> (+1.53%)` | :arrow_up: |
| [cli/command\_content\_verify.go](https://codecov.io/gh/kopia/kopia/pull/2362/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kopia#diff-Y2xpL2NvbW1hbmRfY29udGVudF92ZXJpZnkuZ28=) | `81.03% <0.00%> (+6.03%)` | :arrow_up: |

Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kopia). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kopia)


Patch:
diff --git a/fs/utc_timestamp.go b/fs/utc_timestamp.go
index 3aa0760c..be2797a0 100644
--- a/fs/utc_timestamp.go
+++ b/fs/utc_timestamp.go
@@ -26,7 +26,7 @@ func (u *UTCTimestamp) UnmarshalJSON(v []byte) error {
 // MarshalJSON implements json.Marshaler.
 func (u UTCTimestamp) MarshalJSON() ([]byte, error) {
 	//nolint:wrapcheck
-	return u.ToTime().MarshalJSON()
+	return u.ToTime().UTC().MarshalJSON()
 }
 
 // ToTime returns time.Time representation of the time.
@@ -61,7 +61,7 @@ func (u UTCTimestamp) Equal(other UTCTimestamp) bool {
 
 // Format formats the timestamp according to the provided layout.
 func (u UTCTimestamp) Format(layout string) string {
-	return u.ToTime().Format(layout)
+	return u.ToTime().UTC().Format(layout)
 }
 
 // UTCTimestampFromTime converts time.Time to UTCTimestamp.


Test patch:
diff --git a/fs/utc_timestamp_test.go b/fs/utc_timestamp_test.go
index 9a61a2db..67cd2216 100644
--- a/fs/utc_timestamp_test.go
+++ b/fs/utc_timestamp_test.go
@@ -30,6 +30,10 @@ func TestUTCTimestamp(t *testing.T) {
 	require.NoError(t, json.Unmarshal(v, &y))
 	require.Equal(t, x, y)
 
+	require.NoError(t, json.Unmarshal([]byte(`{"myts":"2022-07-10T11:15:22.656077568-07:00"}`), &y))
+	require.Equal(t, fs.UTCTimestamp(1657476922656077568), y.TS)
+	require.Equal(t, "2022-07-10T18:15:22.656077568Z", y.TS.Format(time.RFC3339Nano))
+
 	require.True(t, fs.UTCTimestampFromTime(t0) < fs.UTCTimestampFromTime(t1))
 	require.True(t, fs.UTCTimestampFromTime(t0).Equal(fs.UTCTimestampFromTime(t0)))
 	require.False(t, fs.UTCTimestampFromTime(t0).Equal(fs.UTCTimestampFromTime(t1)))