Looking for Review: kairos - a chrono frontend for convenient time calculations


#1

Hi.

I’m working on kairos for some days now and I’m looking for review (API-wise).

The goal of kairos is that you can write “plain-text-like” expressions to calculate times and dates. There are some things I avoid for the sake of API-niceness, so this is not intended to do 100%-accurate time calculations, but rather for writing user-facing APIs/Interfaces.

For example:

let days = (today() + days(2))
    .weekly()
    .without(Month::Novemer)
    .until(year(2020));

would return a iterator which yields days in weekly fashion, starting the day after tomorrow, leaving out November and stops at year 2020. That’s roughly how the interface works/should work.

I also plan on adding a parser frontend, so one can pass actual strings - like user input and such - for doing these calculations.

Feel free to open issues, add tests and start discussion. As said: I do not intend to make this a highly-precise time calculation library, but a simple and convenient API over chrono for user-input.

The project is in very early stage (no release yet). Expect breaking changes and everything - do not use before we release a first version!

Kind regards! :slight_smile:


#2

To me the example you gave is hard to read, because the weekly and without functions made no sense without your additional information. I’d be more comfortable with regular iterator names like step_by (or step_by_weeks) and filter but I’m probably alone on this one. :smile:

The frontend sounds useful, though! Will it accept relative dates and other complex user input, and if so, how will it do that?


#3

Thanks for your reply.
What do you mean by “relative dates”?


#4

Things like “19 years ago”, or “2 days from now”, or “tomorrow”, or other inputs handled by (as an example) the Javascript library named chrono.


#5

Ah.

Well sure, that’s exactly the idea. The Rust library won’t be that minimalistic (as in “in rust code you’d have to write it a bit more verbose”) but I don’t see why the parser wouldn’t be able to accept things like that.

In Rust code it would be

let _ = today() - years(19);
let _ = today() + days(2);
let _ = tomorrow();

whereas tomorrow() would be a shortcut for today() + day(1). One could think of a lot of such shortcuts. For example: in(days(4)) == (today() + days(4)) or something like that.

Some things also already work. Adding and subtracting works so far, and I merged an iterator interface just today where you can do today().monthly(1) for getting an endless Iterator which yields a date for every month after today… of course things are still highly experimental,… so you’re more than welcome to join and add tests as much as you can! I want this to be 150% tested before even considering a 0.1.0 release!