Is it possible to have 'deadlines' extended to work without 'in/within'
It would be nice to be able to parse "2 hours" or "4 days" instead of requiring the in/within, maybe it's a bit "noisy" but if it were possible via an option or some sort of "aggressive" version of deadline i think it could be nice - sometimes you just want to parse a time no matter what, and it won't always have the in/within at the start
Hey @smt923,
Sorry for late reply here. This is possible to do. Please keep in mind that by cutting the context that can be matched we generalise the rule so we increase possibilities where the rul will be capturing what is not intended to be captured.
This is possible with slight modifications of the deadline rule. The are couple of things to do, to make it work:
- introduce an optional parameter to the rule in this line
- handle the optional parameter while creating the RegExp here
By that, you will be able to use the rule with changed pattern, for example:
w := when.New(nil)
w.Add(deadline({ Aggressive: true }))
text := "2 hours"
r, err := w.Parse(text, time.Now())
// handle the result here
Please feel free to send a PR, happy to review, when you're ready!