Skip to content

Commit

Permalink
feat: change datetime from RFC 3339 to RFC 3339 Nano.
Browse files Browse the repository at this point in the history
  • Loading branch information
vvatanabe committed Oct 30, 2023
1 parent 6670a16 commit ff774c8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions internal/clock/clock.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ func Now() time.Time {
return time.Now().UTC()
}

func FormatRFC3339(now time.Time) string {
return now.UTC().Format(time.RFC3339)
func FormatRFC3339Nano(now time.Time) string {
return now.UTC().Format(time.RFC3339Nano)
}

func RFC3339ToUnixMilli(rfc3339Date string) int64 {
t, _ := time.Parse(time.RFC3339, rfc3339Date)
func RFC3339NanoToUnixMilli(rfc3339NanoDate string) int64 {
t, _ := time.Parse(time.RFC3339Nano, rfc3339NanoDate)
return t.UnixMilli()
}

Expand Down
12 changes: 6 additions & 6 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type SystemInfo struct {
}

func newDefaultSystemInfo(id string, now time.Time) *SystemInfo {
ts := clock.FormatRFC3339(now)
ts := clock.FormatRFC3339Nano(now)
return &SystemInfo{
ID: id,
Status: StatusReady,
Expand Down Expand Up @@ -82,7 +82,7 @@ func (m *Message[T]) IsQueueSelected(now time.Time, visibilityTimeout time.Durat
if m.Status != StatusProcessing {
return false
}
peekUTCTimestamp := clock.RFC3339ToUnixMilli(m.PeekFromQueueTimestamp)
peekUTCTimestamp := clock.RFC3339NanoToUnixMilli(m.PeekFromQueueTimestamp)
timeDifference := now.UnixMilli() - peekUTCTimestamp
return timeDifference <= visibilityTimeout.Milliseconds()
}
Expand Down Expand Up @@ -124,7 +124,7 @@ func (m *Message[T]) Ready(now time.Time) error {
Current: m.Status,
}
}
ts := clock.FormatRFC3339(now)
ts := clock.FormatRFC3339Nano(now)
m.Status = StatusReady
m.LastUpdatedTimestamp = ts
return nil
Expand All @@ -138,7 +138,7 @@ func (m *Message[T]) StartProcessing(now time.Time, visibilityTimeout time.Durat
Current: m.Status,
}
}
ts := clock.FormatRFC3339(now)
ts := clock.FormatRFC3339Nano(now)
m.Status = StatusProcessing
m.LastUpdatedTimestamp = ts
m.PeekFromQueueTimestamp = ts
Expand All @@ -153,7 +153,7 @@ func (m *Message[T]) MoveToDLQ(now time.Time) error {
Current: m.Status,
}
}
ts := clock.FormatRFC3339(now)
ts := clock.FormatRFC3339Nano(now)
m.QueueType = QueueTypeDLQ
m.Status = StatusReady
m.ReceiveCount = 0
Expand All @@ -178,7 +178,7 @@ func (m *Message[T]) RestoreFromDLQ(now time.Time) error {
Current: m.Status,
}
}
ts := clock.FormatRFC3339(now)
ts := clock.FormatRFC3339Nano(now)
m.QueueType = QueueTypeStandard
m.Status = StatusReady
m.LastUpdatedTimestamp = ts
Expand Down
6 changes: 3 additions & 3 deletions sdk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func TestDynamoMQClientSendMessage(t *testing.T) {
Result: &Result{
ID: "A-101",
Status: StatusReady,
LastUpdatedTimestamp: clock.FormatRFC3339(time.Date(2023, 12, 1, 0, 0, 10, 0, time.UTC)),
LastUpdatedTimestamp: clock.FormatRFC3339Nano(time.Date(2023, 12, 1, 0, 0, 10, 0, time.UTC)),
Version: 1,
},
Message: func() *Message[test.MessageData] {
Expand Down Expand Up @@ -709,7 +709,7 @@ func TestDynamoMQClientUpdateMessageAsVisible(t *testing.T) {
Result: &Result{
ID: "A-101",
Status: StatusReady,
LastUpdatedTimestamp: clock.FormatRFC3339(time.Date(2023, 12, 1, 0, 0, 10, 0, time.UTC)),
LastUpdatedTimestamp: clock.FormatRFC3339Nano(time.Date(2023, 12, 1, 0, 0, 10, 0, time.UTC)),
Version: 2,
},
Message: func() *Message[test.MessageData] {
Expand Down Expand Up @@ -1024,7 +1024,7 @@ func TestDynamoMQClientRedriveMessage(t *testing.T) {
want: &RedriveMessageOutput{
ID: "A-101",
Status: StatusReady,
LastUpdatedTimestamp: clock.FormatRFC3339(time.Date(2023, 12, 1, 0, 0, 10, 0, time.UTC)),
LastUpdatedTimestamp: clock.FormatRFC3339Nano(time.Date(2023, 12, 1, 0, 0, 10, 0, time.UTC)),
Version: 2,
},
},
Expand Down

0 comments on commit ff774c8

Please sign in to comment.