fix tags and duedates

This commit is contained in:
bel
2020-01-26 18:34:41 +00:00
parent 2f0c09ff72
commit 6733ccd4b8
4 changed files with 34 additions and 2 deletions

View File

@@ -61,6 +61,18 @@ func ToStrArr(k string) []string {
}
func ToTime(s string) time.Time {
v, _ := time.Parse("2006-01-02 15:04:05", s)
v, err := time.Parse("2006-01-02 15:04:05", s)
if err != nil || v.IsZero() {
v, err = time.Parse("2006-01-02", s)
}
if err != nil || v.IsZero() {
v, err = time.Parse("1/2/06", s)
}
if err != nil || v.IsZero() {
v, err = time.Parse("02 Jan 2006 3:04 PM", s)
}
if err != nil || v.IsZero() {
v, err = time.Parse("02 Jan 2006 3:04 PM", strings.ReplaceAll(s, "+", " "))
}
return v
}

View File

@@ -79,6 +79,18 @@ func TestToTime(t *testing.T) {
in: "5",
out: "0001-01-01 00:00:00",
},
{
in: "1/2/03",
out: "2003-01-02 00:00:00",
},
{
in: "11/12/03",
out: "2003-11-12 00:00:00",
},
{
in: "01+Jan+2020+12:00+PM",
out: "2020-01-01 12:00:00",
},
}
for _, c := range cases {