Skip to content

Commit 0a43b7b

Browse files
authored
Merge pull request #49 from ijt/issue/48/oct-nov
Issue/48/oct nov
2 parents 6d57390 + 7702860 commit 0a43b7b

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

v2/parse.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,19 +223,25 @@ func parseImplicitRange(s string, now time.Time, dir Direction) (r Range, parsed
223223
code := ""
224224
for sow < len(s) {
225225
prevD := d
226-
c, ok := parseDateWord(&d, w)
226+
wCode, ok := parseDateWord(&d, w)
227227
if !ok {
228228
d = prevD
229229
break
230230
}
231+
// If the date word just parsed is one of the things already parsed
232+
// for this date then don't accept it and stop parsing.
233+
if strings.ContainsAny(code, wCode) {
234+
d = prevD
235+
break
236+
}
231237
// "d" has to come either at the beginning or after a month name,
232238
// or we ignore it and consider the implicit range to have ended
233239
// one word before.
234-
if c == "d" && !(len(code) == 0 || code[len(code)-1] == 'm') {
240+
if wCode == "d" && !(len(code) == 0 || code[len(code)-1] == 'm') {
235241
d = prevD
236242
break
237243
}
238-
code = code + c
244+
code = code + wCode
239245
eolgw = eow
240246
sow, eow, w = findSignalNoise(s, eow)
241247
}

v2/parse_test.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ func TestParseRange_fail(t *testing.T) {
165165
func Test_parseImplicitRange(t *testing.T) {
166166
type args struct {
167167
s string
168-
ls string
169168
now time.Time
170169
dir Direction
171170
}
@@ -179,20 +178,27 @@ func Test_parseImplicitRange(t *testing.T) {
179178
{
180179
name: "small int after year is ignored",
181180
args: args{
182-
s: "Jan 2017 1",
183-
ls: "jan 2017 1",
181+
s: "Jan 2017 1",
184182
},
185183
wantR: truncateMonth(time.Date(2017, time.January, 1, 0, 0, 0, 0, time.UTC)),
186184
wantParsed: "Jan 2017",
187185
},
188186
{
189187
name: "small int before year at beginning causes failure",
190188
args: args{
191-
s: "1 2017 Jan",
192-
ls: "1 2017 jan",
189+
s: "1 2017 Jan",
193190
},
194191
wantErr: true,
195192
},
193+
{
194+
name: "oct nov",
195+
args: args{
196+
s: "oct nov",
197+
now: time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC),
198+
},
199+
wantR: truncateMonth(time.Date(2023, 10, 1, 0, 0, 0, 0, time.UTC)),
200+
wantParsed: "oct",
201+
},
196202
}
197203
for _, tt := range tests {
198204
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)