weekday abbreviations
This commit is contained in:
parent
064adad7cb
commit
a715625e0a
|
@ -116,12 +116,14 @@ func NewDateFromString(date string) Date {
|
||||||
fallthrough
|
fallthrough
|
||||||
case "no date":
|
case "no date":
|
||||||
return Date{}
|
return Date{}
|
||||||
|
|
||||||
case "today":
|
case "today":
|
||||||
return Today()
|
return Today()
|
||||||
|
case "tod":
|
||||||
|
return Today()
|
||||||
case "tomorrow":
|
case "tomorrow":
|
||||||
return Today().AddDays(1)
|
return Today().AddDays(1)
|
||||||
|
case "tom":
|
||||||
|
return Today().AddDays(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
t, err := time.Parse("2006-01-02", fmt.Sprintf("%.10s", date))
|
t, err := time.Parse("2006-01-02", fmt.Sprintf("%.10s", date))
|
||||||
|
@ -241,35 +243,35 @@ func ParseWeekday(wd string) (time.Weekday, bool) {
|
||||||
switch lowerAndTrim(wd) {
|
switch lowerAndTrim(wd) {
|
||||||
case "monday":
|
case "monday":
|
||||||
return time.Monday, true
|
return time.Monday, true
|
||||||
|
case "mon":
|
||||||
|
return time.Monday, true
|
||||||
case "tuesday":
|
case "tuesday":
|
||||||
return time.Tuesday, true
|
return time.Tuesday, true
|
||||||
|
case "tue":
|
||||||
|
return time.Tuesday, true
|
||||||
case "wednesday":
|
case "wednesday":
|
||||||
return time.Wednesday, true
|
return time.Wednesday, true
|
||||||
|
case "wed":
|
||||||
|
return time.Wednesday, true
|
||||||
case "thursday":
|
case "thursday":
|
||||||
return time.Thursday, true
|
return time.Thursday, true
|
||||||
|
case "thu":
|
||||||
|
return time.Thursday, true
|
||||||
case "friday":
|
case "friday":
|
||||||
return time.Friday, true
|
return time.Friday, true
|
||||||
|
case "fri":
|
||||||
|
return time.Friday, true
|
||||||
case "saturday":
|
case "saturday":
|
||||||
return time.Saturday, true
|
return time.Saturday, true
|
||||||
|
case "sat":
|
||||||
|
return time.Saturday, true
|
||||||
case "sunday":
|
case "sunday":
|
||||||
return time.Sunday, true
|
return time.Sunday, true
|
||||||
case "maandag":
|
case "sun":
|
||||||
return time.Monday, true
|
|
||||||
case "dinsdag":
|
|
||||||
return time.Tuesday, true
|
|
||||||
case "woensdag":
|
|
||||||
return time.Wednesday, true
|
|
||||||
case "donderdag":
|
|
||||||
return time.Thursday, true
|
|
||||||
case "vrijdag":
|
|
||||||
return time.Friday, true
|
|
||||||
case "zaterdag":
|
|
||||||
return time.Saturday, true
|
|
||||||
case "zondag":
|
|
||||||
return time.Sunday, true
|
return time.Sunday, true
|
||||||
|
default:
|
||||||
|
return time.Monday, false
|
||||||
}
|
}
|
||||||
|
|
||||||
return time.Monday, false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func lowerAndTrim(str string) string {
|
func lowerAndTrim(str string) string {
|
||||||
|
|
|
@ -142,6 +142,10 @@ func TestNewDateFromString(t *testing.T) {
|
||||||
name: "dayname capitalized",
|
name: "dayname capitalized",
|
||||||
input: "Monday",
|
input: "Monday",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "dayname short",
|
||||||
|
input: "mon",
|
||||||
|
},
|
||||||
} {
|
} {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
test.Equals(t, monday, task.NewDateFromString(tc.input))
|
test.Equals(t, monday, task.NewDateFromString(tc.input))
|
||||||
|
@ -158,10 +162,18 @@ func TestNewDateFromString(t *testing.T) {
|
||||||
name: "today",
|
name: "today",
|
||||||
exp: task.Today(),
|
exp: task.Today(),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "tod",
|
||||||
|
exp: task.Today(),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "tomorrow",
|
name: "tomorrow",
|
||||||
exp: task.Today().Add(1),
|
exp: task.Today().Add(1),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "tom",
|
||||||
|
exp: task.Today().Add(1),
|
||||||
|
},
|
||||||
} {
|
} {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
test.Equals(t, tc.exp, task.NewDateFromString(tc.name))
|
test.Equals(t, tc.exp, task.NewDateFromString(tc.name))
|
||||||
|
|
Loading…
Reference in New Issue