Skip to content

Commit f823b1c

Browse files
authored
Merge pull request #61 from ijt/issue/60/mar-24
Issue/60/mar 24
2 parents f2ba7b5 + 3d599d8 commit f823b1c

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

v2/parse.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,21 @@ func oneWordStrToRange(w string, now time.Time) (Range, bool) {
565565
case eq(w, "tomorrow"):
566566
return truncateDay(now.AddDate(0, 0, 1)), true
567567
}
568+
569+
// Try for a date like mar-24.
570+
if strings.Count(w, "-") == 1 {
571+
dashParts := strings.Split(w, "-")
572+
if len(dashParts) == 2 {
573+
m, ok := monthNameToMonth[dashParts[0]]
574+
if ok {
575+
dom, ok := parseDayOfMonthNoCheck(dashParts[1])
576+
if ok && okDayOfMonth(dom) {
577+
return truncateDay(time.Date(now.Year(), m, dom, 0, 0, 0, 0, now.Location())), true
578+
}
579+
}
580+
}
581+
}
582+
568583
return Range{}, false
569584
}
570585

v2/parse_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,15 @@ func Test_parseImplicitRange(t *testing.T) {
235235
wantR: truncateDay(time.Date(2023, 3, 4, 0, 0, 0, 0, time.UTC)),
236236
wantParsed: "mar 4th",
237237
},
238+
{
239+
name: "md date with dash",
240+
args: args{
241+
s: "mar-24",
242+
now: time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC),
243+
},
244+
wantR: truncateDay(time.Date(2023, 3, 24, 0, 0, 0, 0, time.UTC)),
245+
wantParsed: "mar-24",
246+
},
238247
{
239248
name: "december 40",
240249
args: args{

0 commit comments

Comments
 (0)