{"id":13413976,"url":"https://github.com/olebedev/when","last_synced_at":"2025-05-13T20:20:43.169Z","repository":{"id":45468367,"uuid":"77456467","full_name":"olebedev/when","owner":"olebedev","description":"A natural language date/time parser with pluggable rules","archived":false,"fork":false,"pushed_at":"2025-03-03T21:30:56.000Z","size":105,"stargazers_count":1434,"open_issues_count":16,"forks_count":87,"subscribers_count":27,"default_branch":"master","last_synced_at":"2025-04-28T11:54:34.297Z","etag":null,"topics":["date","datetime","golang","natural-language","parser","time"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/olebedev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-12-27T13:11:46.000Z","updated_at":"2025-04-25T11:23:01.000Z","dependencies_parsed_at":"2025-01-16T05:00:32.499Z","dependency_job_id":"5ed8dded-11d7-4536-85b2-244d432b0713","html_url":"https://github.com/olebedev/when","commit_stats":{"total_commits":60,"total_committers":13,"mean_commits":4.615384615384615,"dds":0.2833333333333333,"last_synced_commit":"987a8eed4b47550d4a297b27bc984f589685dd70"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olebedev%2Fwhen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olebedev%2Fwhen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olebedev%2Fwhen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olebedev%2Fwhen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/olebedev","download_url":"https://codeload.github.com/olebedev/when/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251311332,"owners_count":21569008,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["date","datetime","golang","natural-language","parser","time"],"created_at":"2024-07-30T20:01:54.207Z","updated_at":"2025-04-28T11:54:47.839Z","avatar_url":"https://github.com/olebedev.png","language":"Go","readme":"# when [![godoc](http://img.shields.io/badge/godoc-reference-blue.svg?style=flat)](https://godoc.org/github.com/olebedev/when)\n\n\u003e `when` is a natural language date/time parser with pluggable rules and merge strategies\n\n### Examples\n\n- **tonight at 11:10 pm**\n- at **Friday afternoon**\n- the deadline is **next tuesday 14:00**\n- drop me a line **next wednesday at 2:25 p.m**\n- it could be done at **11 am past tuesday**\n\nCheck [EN](https://github.com/olebedev/when/blob/master/rules/en) rules and tests of them, for more examples.\n\n**Needed rule not found?**\nOpen [an issue](https://github.com/olebedev/when/issues/new) with the case and it will be added asap.\n\n### How it works\n\nUsually, there are several rules added to the parser's instance for checking. Each rule has its own borders - length and offset in provided string. Meanwhile, each rule yields only the first match over the string. So, the library checks all the rules and extracts a cluster of matched rules which have distance between each other less or equal to [`options.Distance`](https://github.com/olebedev/when/blob/master/when.go#L141-L144), which is 5 by default. For example:\n\n```\non next wednesday at 2:25 p.m.\n   └──────┬─────┘    └───┬───┘\n       weekday      hour + minute\n```\n\nSo, we have a cluster of matched rules - `\"next wednesday at 2:25 p.m.\"` in the string representation.\n\nAfter that, each rule is applied to the context. In order of definition or in match order, if [`options.MatchByOrder`](https://github.com/olebedev/when/blob/master/when.go#L141-L144) is set to `true`(which it is by default). Each rule could be applied with given merge strategy. By default, it's an [Override](https://github.com/olebedev/when/blob/master/rules/rules.go#L13) strategy. The other strategies are not implemented yet in the rules. **Pull requests are welcome.**\n\n### Supported Languages\n\n- [EN](https://github.com/olebedev/when/blob/master/rules/en) - English\n- [RU](https://github.com/olebedev/when/blob/master/rules/ru) - Russian\n- [BR](https://github.com/olebedev/when/blob/master/rules/br) - Brazilian Portuguese\n- [ZH](https://github.com/olebedev/when/blob/master/rules/zh) - Chinese\n- [NL](https://github.com/olebedev/when/blob/master/rules/nl) - Dutch\n\n### Install\n\nThe project follows the official [release workflow](https://go.dev/doc/modules/release-workflow). It is recommended to refer to this resource for detailed information on the process.\n\nTo install the latest version:\n\n```\n$ go get github.com/olebedev/when@latest\n```\n\n### Usage\n\n```go\nw := when.New(nil)\nw.Add(en.All...)\nw.Add(common.All...)\n\ntext := \"drop me a line in next wednesday at 2:25 p.m\"\nr, err := w.Parse(text, time.Now())\nif err != nil {\n\t// an error has occurred\n}\nif  r == nil {\n \t// no matches found\n}\n\nfmt.Println(\n\t\"the time\",\n\tr.Time.String(),\n\t\"mentioned in\",\n\ttext[r.Index:r.Index+len(r.Text)],\n)\n```\n\n#### Distance Option\n\n```go\nw := when.New(nil)\nw.Add(en.All...)\nw.Add(common.All...)\n\ntext := \"February 23, 2019 | 1:46pm\"\n\n// With default distance (5):\n// February 23, 2019 | 1:46pm\n//            └───┬───┘\n//           distance: 9 (1:46pm will be ignored)\n\nr, _ := w.Parse(text, time.Now())\nfmt.Printf(r.Time.String())\n// \"2019-02-23 09:21:21.835182427 -0300 -03\"\n// 2019-02-23 (correct)\n//   09:21:21 (\"wrong\")\n\n// With custom distance (10):\nw.SetOptions(\u0026rules.Options{\n\tDistance:     10,\n\tMatchByOrder: true})\n\nr, _ = w.Parse(text, time.Now())\nfmt.Printf(r.Time.String())\n// \"2019-02-23 13:46:21.559521554 -0300 -03\"\n// 2019-02-23 (correct)\n//   13:46:21 (correct)\n```\n\n### State of the project\n\nThe project is in a more-or-less complete state. It's used for one project already. Bugs will be fixed as soon as they will be found.\n\n### TODO\n\n- [ ] readme: describe all the existing rules\n- [ ] implement missed rules for [these examples](https://github.com/mojombo/chronic#examples)\n- [ ] add cli and simple rest api server([#2](https://github.com/olebedev/when/issues/2))\n\n### LICENSE\n\nhttp://www.apache.org/licenses/LICENSE-2.0\n","funding_links":[],"categories":["开源类库","Text Processing","Go","Open source library","Natural Language Processing","Relational Databases","\u003cspan id=\"自然语言处理-natural-language-processing\"\u003e自然语言处理 Natural Language Processing\u003c/span\u003e","Template Engines","文本处理","自然语言处理","自然語言處理","Bot Building"],"sub_categories":["日期时间","Parsers/Encoders/Decoders","Appointment Time","Strings","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e","解析 器/Encoders/Decoders","暂未分类这些库被放在这里是因为其他类别似乎都不适合。","Advanced Console UIs","Uncategorized","高級控制台界面","交流","暂未分类","高级控制台界面"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Folebedev%2Fwhen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Folebedev%2Fwhen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Folebedev%2Fwhen/lists"}