• Stars
    star
    29
  • Rank 832,140 (Top 17 %)
  • Language
    Clojure
  • License
    Other
  • Created over 7 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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 Repositories

1

accelerated-text

Accelerated Text is a no-code natural language generation platform. It will help you construct document plans which define how your data is converted to textual descriptions varying in wording and structure.
JavaScript
384
star
2

beagle

Beagle helps you identify keywords, phrases, regexes, and complex search queries of interest in streams of text documents.
Clojure
51
star
3

clojure-graalvm-aws-lambda-template

Leiningen template for AWS Lambda custom runtime with GraalVM native image compiled Clojure projects.
Clojure
43
star
4

crawling-framework

Easily crawl news portals or blog sites using Storm Crawler.
Java
21
star
5

docx-utils

Easily work with .docx files from Clojure (a wrapper on Apache POI library).
Clojure
11
star
6

fast-url-access-checker

Easily run HTTP GET requests against a list of URLs to check their HTTP status.
Clojure
10
star
7

reaction-acc-text-demo

Integration between Reaction ECommerce and Accelerated Text to provide product descriptions for an e-shop.
JavaScript
10
star
8

dictionary-annotator

Fast and configurable UIMA dictionary annotator.
Java
7
star
9

snowball

Snowball version of the Porter stemmer for the Lithuanian language.
7
star
10

common-crawl-utils

Various Common Crawl utilities in Clojure.
Clojure
6
star
11

accelerated-text-project-template

Text generation project template to be used with Accelerated Text
Makefile
6
star
12

docker-images

Docker configurations, images, and examples of Dockerfiles for various TokenMill products and projects.Official source for Docker configurations, images, and examples of Dockerfiles for TokenMill products and projects
Dockerfile
5
star
13

crawling-framework-example

Demonstration on how to use the Crawling Framework to setup a simple science news crawler and store results in ElasticSearch. Use this configuration to set up your own crawler.
Java
3
star
14

reaction-acc-text-import

Plugin connecting ReactionCommerce and AcceleratedText by allowing to import products and generate their descriptions
JavaScript
2
star
15

beagle-performance-benchmarks

Performance benchmarks for the Beagle library, and comparisons with other stored-query solutions.
Clojure
1
star
16

es-utils

Clojure helper functions for Elasticsearch.
Clojure
1
star