Skip to content

Commit 36525fa

Browse files
authored
Replace time.Now() with time.Now().UTC() and time.Unix() with time.Unix().UTC() (#648)
1 parent 0ae59f6 commit 36525fa

File tree

109 files changed

+534
-535
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+534
-535
lines changed

common/archiver/filestore/historyArchiver_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ func (s *historyArchiverSuite) TestArchive_Fail_HistoryMutated() {
215215
Events: []*historypb.HistoryEvent{
216216
{
217217
EventId: common.FirstEventID + 1,
218-
EventTime: timestamp.TimePtr(time.Now()),
218+
EventTime: timestamp.TimePtr(time.Now().UTC()),
219219
Version: testCloseFailoverVersion + 1,
220220
},
221221
},
@@ -279,12 +279,12 @@ func (s *historyArchiverSuite) TestArchive_Success() {
279279
Events: []*historypb.HistoryEvent{
280280
{
281281
EventId: common.FirstEventID + 1,
282-
EventTime: timestamp.TimePtr(time.Now()),
282+
EventTime: timestamp.TimePtr(time.Now().UTC()),
283283
Version: testCloseFailoverVersion,
284284
},
285285
{
286286
EventId: common.FirstEventID + 2,
287-
EventTime: timestamp.TimePtr(time.Now()),
287+
EventTime: timestamp.TimePtr(time.Now().UTC()),
288288
Version: testCloseFailoverVersion,
289289
},
290290
},
@@ -293,7 +293,7 @@ func (s *historyArchiverSuite) TestArchive_Success() {
293293
Events: []*historypb.HistoryEvent{
294294
{
295295
EventId: testNextEventID - 1,
296-
EventTime: timestamp.TimePtr(time.Now()),
296+
EventTime: timestamp.TimePtr(time.Now().UTC()),
297297
Version: testCloseFailoverVersion,
298298
},
299299
},

common/archiver/gcloud/historyArchiver_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ func (h *historyArchiverSuite) TestArchive_Fail_HistoryMutated() {
258258
Events: []*historypb.HistoryEvent{
259259
{
260260
EventId: common.FirstEventID + 1,
261-
EventTime: timestamp.TimePtr(time.Now()),
261+
EventTime: timestamp.TimePtr(time.Now().UTC()),
262262
Version: testCloseFailoverVersion + 1,
263263
},
264264
},
@@ -335,12 +335,12 @@ func (h *historyArchiverSuite) TestArchive_Success() {
335335
Events: []*historypb.HistoryEvent{
336336
{
337337
EventId: common.FirstEventID + 1,
338-
EventTime: timestamp.TimePtr(time.Now()),
338+
EventTime: timestamp.TimePtr(time.Now().UTC()),
339339
Version: testCloseFailoverVersion,
340340
},
341341
{
342342
EventId: common.FirstEventID + 2,
343-
EventTime: timestamp.TimePtr(time.Now()),
343+
EventTime: timestamp.TimePtr(time.Now().UTC()),
344344
Version: testCloseFailoverVersion,
345345
},
346346
},
@@ -349,7 +349,7 @@ func (h *historyArchiverSuite) TestArchive_Success() {
349349
Events: []*historypb.HistoryEvent{
350350
{
351351
EventId: testNextEventID - 1,
352-
EventTime: timestamp.TimePtr(time.Now()),
352+
EventTime: timestamp.TimePtr(time.Now().UTC()),
353353
Version: testCloseFailoverVersion,
354354
},
355355
},

common/archiver/gcloud/util.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func constructVisibilityFilenamePrefix(namespaceID, tag string) string {
6868
}
6969

7070
func constructTimeBasedSearchKey(namespaceID, tag string, timestamp int64, precision string) string {
71-
t := time.Unix(0, timestamp).In(time.UTC)
71+
t := time.Unix(0, timestamp).UTC()
7272
var timeFormat = ""
7373
switch precision {
7474
case PrecisionSecond:
@@ -144,7 +144,7 @@ func decodeVisibilityRecord(data []byte) (*archiverproto.ArchiveVisibilityReques
144144
}
145145

146146
func constructVisibilityFilename(namespace, workflowTypeName, workflowID, runID, tag string, timestamp int64) string {
147-
t := time.Unix(0, timestamp).In(time.UTC)
147+
t := time.Unix(0, timestamp).UTC()
148148
prefix := constructVisibilityFilenamePrefix(namespace, tag)
149149
return fmt.Sprintf("%s_%s_%s_%s_%s.visibility", prefix, t.Format(time.RFC3339), hash(workflowTypeName), hash(workflowID), hash(runID))
150150
}

common/archiver/s3store/historyArchiver_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ func (s *historyArchiverSuite) TestArchive_Fail_HistoryMutated() {
345345
Events: []*historypb.HistoryEvent{
346346
{
347347
EventId: common.FirstEventID + 1,
348-
EventTime: timestamp.TimePtr(time.Now()),
348+
EventTime: timestamp.TimePtr(time.Now().UTC()),
349349
Version: testCloseFailoverVersion + 1,
350350
},
351351
},
@@ -409,12 +409,12 @@ func (s *historyArchiverSuite) TestArchive_Success() {
409409
Events: []*historypb.HistoryEvent{
410410
{
411411
EventId: common.FirstEventID + 1,
412-
EventTime: timestamp.TimePtr(time.Now()),
412+
EventTime: timestamp.TimePtr(time.Now().UTC()),
413413
Version: testCloseFailoverVersion,
414414
},
415415
{
416416
EventId: common.FirstEventID + 2,
417-
EventTime: timestamp.TimePtr(time.Now()),
417+
EventTime: timestamp.TimePtr(time.Now().UTC()),
418418
Version: testCloseFailoverVersion,
419419
},
420420
},
@@ -423,7 +423,7 @@ func (s *historyArchiverSuite) TestArchive_Success() {
423423
Events: []*historypb.HistoryEvent{
424424
{
425425
EventId: testNextEventID - 1,
426-
EventTime: timestamp.TimePtr(time.Now()),
426+
EventTime: timestamp.TimePtr(time.Now().UTC()),
427427
Version: testCloseFailoverVersion,
428428
},
429429
},

common/archiver/s3store/util.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func constructHistoryKeyPrefix(path, namespaceID, workflowID, runID string) stri
150150
}
151151

152152
func constructTimeBasedSearchKey(path, namespaceID, primaryIndexKey, primaryIndexValue, secondaryIndexKey string, timestamp int64, precision string) string {
153-
t := time.Unix(0, timestamp).In(time.UTC)
153+
t := time.Unix(0, timestamp).UTC()
154154
var timeFormat = ""
155155
switch precision {
156156
case PrecisionSecond:
@@ -170,7 +170,7 @@ func constructTimeBasedSearchKey(path, namespaceID, primaryIndexKey, primaryInde
170170
}
171171

172172
func constructTimestampIndex(path, namespaceID, primaryIndexKey, primaryIndexValue, secondaryIndexKey string, timestamp int64, runID string) string {
173-
t := time.Unix(0, timestamp).In(time.UTC)
173+
t := time.Unix(0, timestamp).UTC()
174174
return fmt.Sprintf("%s/%s/%s", constructVisibilitySearchPrefix(path, namespaceID, primaryIndexKey, primaryIndexValue, secondaryIndexKey), t.Format(time.RFC3339), runID)
175175
}
176176

common/backoff/cron.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ func GetBackoffForNextSchedule(cronSchedule string, scheduledTime time.Time, now
5959
return NoBackoff
6060
}
6161

62-
scheduledUTCTime := scheduledTime.In(time.UTC)
63-
nowUTC := now.In(time.UTC)
62+
scheduledUTCTime := scheduledTime.UTC()
63+
nowUTC := now.UTC()
6464

6565
var nextScheduleTime time.Time
6666
if nowUTC.Before(scheduledUTCTime) {

common/backoff/retrypolicy.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ type (
7979
}
8080
)
8181

82-
// SystemClock implements Clock interface that uses time.Now().
82+
// SystemClock implements Clock interface that uses time.Now().UTC().
8383
var SystemClock = systemClock{}
8484

8585
// NewExponentialRetryPolicy returns an instance of ExponentialRetryPolicy using the provided initialInterval
@@ -179,7 +179,7 @@ func (p *ExponentialRetryPolicy) ComputeNextDelay(elapsedTime time.Duration, num
179179

180180
// Now returns the current time using the system clock
181181
func (t systemClock) Now() time.Time {
182-
return time.Now()
182+
return time.Now().UTC()
183183
}
184184

185185
// Reset will set the Retrier into initial state

common/cache/lru.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func (c *lru) Iterator() Iterator {
110110
c.mut.Lock()
111111
iterator := &iteratorImpl{
112112
lru: c,
113-
createTime: time.Now(),
113+
createTime: time.Now().UTC(),
114114
nextItem: c.byAccess.Front(),
115115
}
116116
iterator.prepareNext()
@@ -171,7 +171,7 @@ func (c *lru) Get(key interface{}) interface{} {
171171

172172
entry := element.Value.(*entryImpl)
173173

174-
if c.isEntryExpired(entry, time.Now()) {
174+
if c.isEntryExpired(entry, time.Now().UTC()) {
175175
// Entry has expired
176176
c.deleteInternal(element)
177177
return nil
@@ -249,15 +249,15 @@ func (c *lru) putInternal(key interface{}, value interface{}, allowUpdate bool)
249249
elt := c.byKey[key]
250250
if elt != nil {
251251
entry := elt.Value.(*entryImpl)
252-
if c.isEntryExpired(entry, time.Now()) {
252+
if c.isEntryExpired(entry, time.Now().UTC()) {
253253
// Entry has expired
254254
c.deleteInternal(elt)
255255
} else {
256256
existing := entry.value
257257
if allowUpdate {
258258
entry.value = value
259259
if c.ttl != 0 {
260-
entry.createTime = time.Now()
260+
entry.createTime = time.Now().UTC()
261261
}
262262
}
263263

@@ -279,7 +279,7 @@ func (c *lru) putInternal(key interface{}, value interface{}, allowUpdate bool)
279279
}
280280

281281
if c.ttl != 0 {
282-
entry.createTime = time.Now()
282+
entry.createTime = time.Now().UTC()
283283
}
284284

285285
c.byKey[key] = c.byAccess.PushFront(entry)

common/cache/namespaceCache_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ func (s *namespaceCacheSuite) TestGetNamespace_NonLoaded_GetByName() {
216216
"abc": {
217217
Reason: "test reason",
218218
Operator: "test operator",
219-
CreateTime: timestamp.TimePtr(time.Unix(0, 123)),
219+
CreateTime: timestamp.TimePtr(time.Unix(0, 123).UTC()),
220220
},
221221
},
222222
}},

common/checksum/crc_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func TestCRC32OverProto(t *testing.T) {
4949
WorkflowId: uuid.New(),
5050
RunId: uuid.New(),
5151
},
52-
StartTime: timestamp.TimePtr(time.Now()),
52+
StartTime: timestamp.TimePtr(time.Now().UTC()),
5353
HistoryLength: 550,
5454
}
5555

0 commit comments

Comments
 (0)