ProductPromotion
Logo

Clojure

made by https://0x3d.site

GitHub - tokenmill/timewords: Multilingual library to easily parse date strings to java.util.Date objects.
Multilingual library to easily parse date strings to java.util.Date objects. - tokenmill/timewords
Visit Site

GitHub - tokenmill/timewords: Multilingual library to easily parse date strings to java.util.Date objects.

GitHub - tokenmill/timewords: Multilingual library to easily parse date strings to java.util.Date objects.

timewords

Clojars Project

Library to parse a date string to java.util.Date object. For example:

  • "2 weeks from now" -> 2018-11-29T09:52:23.000-00:00
  • "28th February 2019" -> 2019-02-28T00:00:00.000-00:00

When the library cannot parse the input string it returns nil.

More formally, from four types of temporal expressions: time, duration, interval, and set; only one type is of interest: time. Also, time type can be divided into two subtypes: fuzzy (e.g. last Sunday) and absolute (1st of January, 2019). To parse a fuzzy time string a reference time (i.e. a java.util.Date object) is required. By default, reference time is now.

The library is designed to support multiple languages. Currently two languages are supported: English and Lithuanian. Default language is English.

Usage

Clojure

Add a dependency to your

  • project.clj - [lt.tokenmill/timewords "0.5.0"]
  • deps.edn - lt.tokenmill/timewords {:mvn/version "0.5.0"}
(require '[timewords.core :refer [parse]])
=> nil
(parse "2001-01-01")
=> #inst"2001-01-01T00:00:00.000-00:00"
(timewords.core/parse "now")
=> #inst"2016-12-13T09:52:02.000-00:00"
(timewords.core/parse "2 weeks ago")
=> #inst"2016-11-29T09:52:23.000-00:00"
(timewords.core/parse "2 weeks from now")
=> #inst"2016-12-29T09:54:23.000-00:00"
(timewords.core/parse "last monday")
=> #inst"2016-12-12T09:54:23.000-00:00"
(timewords.core/parse "last june")
=> #inst"2016-06-12T09:54:23.000-00:00"
(timewords.core/parse "last spring")
=> #inst"2016-05-12T09:54:23.000-00:00"

(timewords.core/parse "29th February 2016")
=> #inst"2016-02-29T00:00:00.000-00:00"
(timewords.core/parse "29th February 2017")
=> #inst"2017-02-01T00:00:00.000-00:00"
(timewords.core/parse "Sunday, 1st January 2017")
=> #inst"2017-01-01T00:00:00.000-00:00"

(timewords.core/parse "2016 m. gruodžio 22 d. 11:10" nil "lt")
=> #inst"2016-12-22T11:10:00.000-00:00"

Java

As of now the JAR is stored in Clojars, therefore maven is not going to find the artifact. You should add the repository information to your pom.xml:

<repositories>
    <repository>
        <id>clojars.org</id>
        <url>http://clojars.org/repo</url>
    </repository>
</repositories>

Add a maven dependency to your pom.xml:

<dependency>
    <groupId>lt.tokenmill</groupId>
    <artifactId>timewords</artifactId>
    <version>0.4.0</version>
</dependency>
import lt.tokenmill.timewords.Timewords;

public static void main(String[] args) {
    Timewords timewords = new Timewords();
    Date d1 = timewords.parse("2001-01-01");
    Date d2 = timewords.parse("2001-01-01", new Date());
    Date d3 = timewords.parse("2001-01-01", new Date(), "en");
}

Note that timewords depends on org.clojure/clojure which must be provided.

Notes

Relative dates that can be understood as a time period, e.g. last December are rounded to the beginning of the period, e.g. last December translates to 2016-12-01T00:00:00Z.

Timewords of the form in monthname is interpreted as if it refers to the past, i.e. in December means last December.

Timewords of the form this monthname is interpreted as if it refers to the future, i.e. in December means next December.

Timeword which is only a name of a weekday, e.g. Monday, is interpreted as if it refers to the past, i.e. Monday means the same as last Monday.

Timeword of the form next weekday means the first day in the future which which weekday is the one mentioned, e.g. next Monday means the first Monday to come. If today is Monday and we are parsing next Monday then it means a date after 7 days.

Timeword of a form this weekday, e.g. this Monday, is interpreted as if it refers to the future, i.e. this Monday means the same as next Monday.

TODO

TODO:

  • relative Lithuanian dates.

License

Copyright © 2019 TokenMill UAB.

Distributed under the The Apache License, Version 2.0.

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory