1
0
Fork 0
mirror of https://github.com/anyproto/anytype-heart.git synced 2025-06-09 09:35:00 +09:00

GO-4560 Fix test

This commit is contained in:
kirillston 2024-11-21 20:28:17 +01:00
parent 991ce89aae
commit 7693a663d5
No known key found for this signature in database
GPG key ID: 88218A7F1109754B
2 changed files with 22 additions and 0 deletions

View file

@ -45,6 +45,11 @@ func TimeToDateName(t time.Time, includeTime bool) string {
func DateNameToId(name string) (string, error) {
t, err := time.Parse(dateNameLayout, name)
if err == nil {
return TimeToDateId(t, true), nil
}
t, err = time.Parse(shortDateNameLayout, name)
if err != nil {
return "", err
}

View file

@ -92,3 +92,20 @@ func TestParseDateId(t *testing.T) {
assert.Error(t, err)
})
}
func TestDateNameToId(t *testing.T) {
t.Run("short name", func(t *testing.T) {
for _, pair := range []struct {
name, id string
}{
{"21 Nov 2024", "_date_2024-11-21"},
{"01 Dec 2124", "_date_2124-12-01"},
{"01 Jan 1924", "_date_1924-01-01"},
} {
id, err := DateNameToId(pair.name)
assert.NoError(t, err)
assert.Equal(t, pair.id, id)
}
})
}