All Projects → olebedev → When

olebedev / When

Licence: apache-2.0
A natural language date/time parser with pluggable rules

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to When

Period
PHP's time range API
Stars: ✭ 616 (-44.65%)
Mutual labels:  time, date, datetime
Vue Datetime
Mobile friendly datetime picker for Vue. Supports date and datetime modes, i18n and more.
Stars: ✭ 928 (-16.62%)
Mutual labels:  time, date, datetime
vue-timeselector
🕒 Simply customizable powerful time picker for Vue.js
Stars: ✭ 41 (-96.32%)
Mutual labels:  time, datetime, date
Carbon
A simple, semantic and developer-friendly golang package for datetime
Stars: ✭ 565 (-49.24%)
Mutual labels:  time, date, datetime
Laydate
layDate(日期与时间组件) 是 layui 独立维护的三大组件之一
Stars: ✭ 1,066 (-4.22%)
Mutual labels:  time, date, datetime
moment-cache
⏱ Simple utility to cache moment.js results and speed up moment calls.
Stars: ✭ 29 (-97.39%)
Mutual labels:  time, datetime, date
Pendulum
Python datetimes made easy
Stars: ✭ 4,639 (+316.8%)
Mutual labels:  time, date, datetime
dt
Go's missing DateTime package
Stars: ✭ 34 (-96.95%)
Mutual labels:  time, datetime, date
Tinydate
A tiny (349B) reusable date formatter. Extremely fast!
Stars: ✭ 990 (-11.05%)
Mutual labels:  time, date, datetime
date-php
这是一个Javascript模仿PHP日期时间格式化函数,使用方法和PHP非常类似,有丰富的模板字符,并在原来的基础上增加了一些模板字符。 This is a date function that implement PHP in Javascript. It is very similar to PHP, has rich template characters, and enhances some template characters on the basis of the original.
Stars: ✭ 24 (-97.84%)
Mutual labels:  time, datetime, date
rescript-date
📆 Date manipulation in ReScript.
Stars: ✭ 101 (-90.93%)
Mutual labels:  time, datetime, date
Zulu
A drop-in replacement for native Python datetimes that embraces UTC.
Stars: ✭ 52 (-95.33%)
Mutual labels:  time, date, datetime
chronos
One library to rule the time
Stars: ✭ 17 (-98.47%)
Mutual labels:  time, datetime, date
Angular Moment Picker
Angular Moment Picker is an AngularJS directive for date and time picker using Moment.js.
Stars: ✭ 536 (-51.84%)
Mutual labels:  time, date, datetime
shamsi date
A Flutter and Dart package for using Jalali (Shamsi, Solar, Persian or Jalaali) calendar. You can convert, format and manipulate Jalali and Gregorian (Miladi) date and times.
Stars: ✭ 59 (-94.7%)
Mutual labels:  time, datetime, date
nepali-datetime
Python's core datetime inspired nepali datetime (BS date & NPT) package 🇳🇵
Stars: ✭ 36 (-96.77%)
Mutual labels:  time, datetime, date
rutimeparser
Recognize date and time in russian text and return datetime.datetime.
Stars: ✭ 17 (-98.47%)
Mutual labels:  time, datetime, date
hs-hourglass
efficient and simpler time API for haskell
Stars: ✭ 43 (-96.14%)
Mutual labels:  time, datetime, date
dayjs
Extended fork of Day.js - 2KB immutable date library alternative to Moment.js
Stars: ✭ 36 (-96.77%)
Mutual labels:  time, datetime, date
React Datetime Picker
A datetime picker for your React app.
Stars: ✭ 294 (-73.58%)
Mutual labels:  time, date, datetime

when godoc wercker status

when is a natural language date/time parser with pluggable rules and merge strategies

Examples

  • tonight at 11:10 pm
  • at Friday afternoon
  • the deadline is next tuesday 14:00
  • drop me a line next wednesday at 2:25 p.m
  • it could be done at 11 am past tuesday

Check EN, RU and BR rules and tests for them, for more examples.

Needed rule not found? Open an issue with the case and it will be added asap.

How it works

Usually, 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, which is 5 by default. For example:

on next wednesday at 2:25 p.m.
   └──────┬─────┘    └───┬───┘
       weekday      hour + minute

So, we have a cluster of matched rules - "next wednesday at 2:25 p.m." in the string representation.

After that, each rule is applied to the context. In order of definition or in match order, if options.MatchByOrder is set to true(which it is by default). Each rule could be applied with given merge strategy. By default, it's an Override strategy. The other strategies are not implemented yet in the rules. Pull requests are welcome.

Usage

w := when.New(nil)
w.Add(en.All...)
w.Add(common.All...)

text := "drop me a line in next wednesday at 2:25 p.m"
r, err := w.Parse(text, time.Now())
if err != nil {
	// an error has occurred
}
if  r == nil {
 	// no matches found
}

fmt.Println(
	"the time",
	r.Time.String(),
	"mentioned in",
	text[r.Index:r.Index+len(r.Text)],
)

Distance Option

w := when.New(nil)
w.Add(en.All...)
w.Add(common.All...)

text := "February 23, 2019 | 1:46pm"

// With default distance (5):
// February 23, 2019 | 1:46pm
//            └───┬───┘
//           distance: 9 (1:46pm will be ignored)

r, _ := w.Parse(text, time.Now())
fmt.Printf(r.Time.String())
// "2019-02-23 09:21:21.835182427 -0300 -03"
// 2019-02-23 (correct)
//   09:21:21 ("wrong")

// With custom distance (10):
w.SetOptions(&rules.Options{
	Distance:     10,
	MatchByOrder: true})

r, _ = w.Parse(text, time.Now())
fmt.Printf(r.Time.String())
// "2019-02-23 13:46:21.559521554 -0300 -03"
// 2019-02-23 (correct)
//   13:46:21 (correct)

State of the project

The 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.

TODO

  • [ ] readme: describe all the existing rules
  • [ ] implement missed rules for these examples
  • [ ] add cli and simple rest api server(#2)

LICENSE

http://www.apache.org/licenses/LICENSE-2.0

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].