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:
parent
991ce89aae
commit
7693a663d5
2 changed files with 22 additions and 0 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue