Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Lines changed: 7 additions & 1 deletion
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

Lines changed: 4 additions & 0 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /