Skip to content

Commit a37d8e1

Browse files
committed
Merge branch '335-backward-compatible-format' into 'master'
fix(engine): try to parse date in the legacy format to keep backward compatibility when restore clone sessions (#335) Closes #335 See merge request postgres-ai/database-lab!511
2 parents 21ff8dc + 9cdf738 commit a37d8e1

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

engine/pkg/models/local_time.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
"time"
1111
)
1212

13+
const legacyFormat = "2006-01-02 15:04:05 UTC"
14+
1315
// LocalTime defines a type of time with custom marshalling depends on locale.
1416
type LocalTime struct {
1517
time.Time
@@ -30,7 +32,11 @@ func (t *LocalTime) UnmarshalJSON(data []byte) error {
3032

3133
parsedTime, err := time.Parse(time.RFC3339, string(localTime))
3234
if err != nil {
33-
return err
35+
// Try to parse the legacy format to keep backward compatibility when restore clone sessions.
36+
parsedTime, err = time.Parse(legacyFormat, string(localTime))
37+
if err != nil {
38+
return err
39+
}
3440
}
3541

3642
t.Time = parsedTime

engine/pkg/models/local_time_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ func TestLocalTimeUnMarshalling(t *testing.T) {
5252
unmarshalling: []byte(`""`),
5353
expectedTime: time.Time{},
5454
},
55+
{
56+
unmarshalling: []byte(`"2006-02-01 15:04:05 UTC"`),
57+
expectedTime: time.Date(2006, 02, 1, 15, 04, 05, 0, time.UTC),
58+
},
5559
}
5660

5761
for _, tc := range testCases {

0 commit comments

Comments
 (0)