summaryrefslogtreecommitdiffstats
path: root/README.md
blob: e4d4bc7d023bcca06463c8ddb8b40eb0911e3d0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Kairos

Calculate times with chrono "plain text like" in Rust.

[![Build Status](https://travis-ci.org/matthiasbeyer/kairos.svg?branch=master)](https://travis-ci.org/matthiasbeyer/kairos)
[![license](https://img.shields.io/github/license/matthiasbeyer/kairos.svg?maxAge=2592000?style=flat-square)]()
[![Tokei](https://tokei.rs/b1/github/matthiasbeyer/kairos)](https://github.com/matthiasbeyer/kairos)

From Wikipedia:

> Kairos (καιρός) is an Ancient Greek word meaning the right, critical or
> opportune moment.

This library offers an abstraction over the awesome `chrono` crate to
calculate dates almost like one would write plain text:

```rust
use kairos::timetype::TimeType as TT;

// get the end of the month of the day 5 days ago
let _ = (TT::today() - TT::weeks(1) + TT::days(2)).end_of_month();

// alternative to above
let _ = (TT::today() - TT::days(5)).end_of_month();

// NOTE: The following features are not yet included

// get a vector of dates for the next 4 weeks, starting today
let _ = TT::today()
    .every(TT::week(1))
    .take(4);

// get an iterator of dates for the next year, in a weekly fashion, starting
// today but skipping october
let _ = TT::today()
    .every(TT::week(1))
    .skip(Month::October)
    .until(Mark::END_OF_YEAR);

// and finally, a complex one

let _ = (TT::today() - TT::years(1))       // exactly one year ago
  .every(Day::Monday)                      // and then every Monday
  .skip(Month::October)                    // but not in october
  .skip(|date| date.is(Mark::MONTH_START)) // and not if the day is the 1st of a month
  .until(Mark::Moment(today()));           // until today
```

## Parsing User-Input

kairos ships a user input parser, so you can include kairos in your
commandline applications.

Have a look at [the example CLI utility](./examples/main.rs)
or the [language documentation](./doc/language.md).

# License

MPL 2.0