olebedev / when Goto Github PK
View Code? Open in Web Editor NEWA natural language date/time parser with pluggable rules
License: Apache License 2.0
A natural language date/time parser with pluggable rules
License: Apache License 2.0
For example, if I have a static value, such as my birthday, could I enter something like "halfway through my 18th year"? Thus the distance would be birth_date + 18 years.
The following string crashes the exampel with a Segmentation Violation:
2022-01-15T22:00
when
cannot parse dates with relative delta from some date:
gore> r, err := w.Parse("завтра в 12:00 поезд, напомни за час", time.Now())
&when.Result{
Index: 0,
Text: "завтра в 12:00",
Source: "завтра в 12:00 поезд, напомни за час",
Time: 2019-02-28 12:00:28 Local,
}
nil
BTW, I have old rutimeparser lib for Python. Maybe, some test cases will be useful for you.
I couldn't see to find any timezone parsing code. So, for example, if I am saying "10 PM EST" while the machine's local time is in PST then I expect 7 PM as the outcome in local time or 10 PM with the timezone information extracted.
seems like it'd be handy
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
The getDays
method attempts to access array elements using a passed in month argument as an index. The problem is month can be larger than 12 because the regex defined in SlashDMY
matches on dates in a mm/dd/yyyy format. So this means a date like 1/30/2023
will cause a panic.
Not sure why this is happening, but the following strings are yielding results that are a month off:
when.Parse("September 5th", time.Now()) => 2018-10-05 23:41:28.856911 -0700 PDT
when.Parse("Sept. 5th", time.Now()) => 2018-10-05 23:41:52.679274 -0700 PDT
when.Parse("Sep 5", time.Now()) => 2018-10-05 23:41:52.679274 -0700 PDT
Correct:
when.Parse("October 5th", time.Now()) => 2018-10-05 23:42:06.57631 -0700 PDT
For example, a sentence
breakfast at 8.00, lunch at 12.00
contains 2 matches. Is it possible to extract both of them and return all results?
Hi! I picked up when
in a quick project to file tasks into notion, and it's been great so far! I'm glad I don't have to rewrite all of this natural time parsing myself. Being the end of the year, I've been trying to schedule tasks for next January when I go back to work, and was surprised when they were parsed as January of 2021 instead of 2022.
I was wondering:
ExactMonthDate
parses, e.g. January 4th
as 2021-01-04
instead of 2022-01-04
?ExactMonthDate
the next occurrence of the date? This is a breaking change to the library, so I understand if it's not acceptable to upstream.I do have a working approach (that isn't particularly well thought out 😁) which I could turn over to a pull request if y'all are interested.
Thanks!
Hi!
Can you, please, add exact date rules for both languages? i.e.
25 april at 2.25pm and
25 апреля в 2.30 вечера
Thanks for this great library!
There is an empty impl at today rule.
Line 27 in 53693fb
Hi there,
As the codeowner of the Dutch language in when
, I propose the addition of support for a common expression in Dutch. It's now friday, let's say that I want to make an appointment for next wednesday. In Dutch it's just as common to say "volgende week woensdag" (which translates to "next week on wednesday") as to say "komende woensdag" (which translates to "next wednesday"). So I'd like to add support for "volgende week woensdag" as well.
Before implementing this feature, I thought it might be best to discuss it here, maybe other supported languages have the same pattern. In that case it could be beneficial to work together on this.
My kind regards,
Reinder.
Can we have a semver release of this package - x.y.z , say 1.0.0 so it becomes easy to integrate the same in apps and track future changes if any ?
Not getting a date back for standard U.S. format: "10/20" or "10/20/17". Getting a panic on "10/20/2017":
package main
import (
"fmt"
"os"
"time"
"github.com/olebedev/when"
"github.com/olebedev/when/rules/common"
"github.com/olebedev/when/rules/en"
)
func main() {
w := when.New(nil)
w.Add(en.All...)
w.Add(common.All...)
text := "10/20/2017"
r, err := w.Parse(text, time.Now())
if err != nil {
fmt.Printf("Error: %s\n", err)
os.Exit(1)
}
if r == nil {
fmt.Println("NO MATCH")
os.Exit(1)
}
fmt.Println(
"the time",
r.Time.String(),
"mentioned in",
text[r.Index:r.Index+len(r.Text)],
)
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.