Skip to main content

chronocalc

chronocalc is a basic calculator for time and durations. It can:

  • add durations:

    > 1 day + 1445 minutes
    2 days, 5 minutes
  • subtract durations:

    > 1 hour, 5 minutes - 555 seconds
    55 minutes, 45 seconds
  • multiply/divide durations:

    > 40 mins * 4
    2 hours, 40 minutes
    > 1 day / 2
    12 hours
  • add durations to dates:

    > 2015/07/08 + 3 weeks
    2015-07-29 00:00:00
  • subtract durations from dates:

    > 2015/07/08 11pm - 15 hours
    2015-07-08 08:00:00
  • compute duration between two dates:

    > 2015/07/08 - 2015/07/06 12pm
    1 day, 12 hours
  • compute the ratio of two durations:

    > 1 day / 1 minute
    1440.0
  • do all of the above at once:

    > 2 * ((100 days + 2015/07/08) - (2015/07/01 - 48 hours))
    7 months, 1 week, 5 days

Invocation

If given an argument, chronocalc will eval it and exit, else, it will start a REPL (Read-Eval-Print Loop) prompt to eval multiple expressions.

Input format

Grammar

In EBNF format:

digit ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
number ::= [ "-" ], digit, {digit}, [ ".", {digit} ];

unit ::= "milliseconds" | "millisecond" | "ms"
       | "seconds" | "second" | "sec" | "secs" | "s"
       | "minutes" | "minutes" | "mins" | "min"
       | "hours" | "hour" | "hrs" | "hr"
       | "days" | "day" | "d"
       | "weeks" | "week" | "wks" | "wk" | "w"
       | "months" | "month" | "mons" | "mon"
       | "years" | "year" | "yrs" | "yr" | "y";

duration ::= number, unit, { ",", number, unit };

iso8601d ::= digit, digit, digit, digit, "-", digit, digit, "-", digit, digit (* YYYY-MM-DD *)
           | digit, digit, digit, digit, "-", digit, digit, digit (* YYYY-DDD day in year *)
           | digit, digit, digit, digit, "-W", digit, digit, "-", digit (* YYYY-Www-D week in year, day in week *)
           | digit, digit, digit, digit, digit, digit, digit, digit (* YYYYMMDD *)
           | digit, digit, digit, digit, digit, digit, digit (* YYYYDDD day in year *)
           | digit, digit, digit, digit, digit, digit, digit (* YYYYwwD week in year, day in week *);
iso8601t ::= "digit, digit, ":", digit, digit, [ ":", digit, digit ] (* HH:MM:SS *)
           | "digit, digit, digit, digit, [ digit, digit ] (* HHMMSS *);
iso8601 ::= iso8601d, [ ( "T" | ?whitespace? ), iso8601t ];

date ::= digit, digit, digit, digit, ( "/" | "-" ), digit, [ digit ], ( "/", "-" ), digit, [ digit ];
time ::= digit, [ digit ], ( "am" | "pm" )
       | digit, [ digit ], ":", digit, [ digit ], [ ":", digit, [ digit ] ], [ "am" | "pm" ];

datetime ::= date, [ time ] | [ date ], time | iso8601;

factor ::= duration | datetime | number | "(", expression, ")";
term ::= term, [ ( "*" | "/" ), factor ];
expression ::= expression, [ ( "+" | "-" ), term ];

Examples

These are example of the datetimes and durations formats accepted by chronocalc:

now
today
epoch
2015-01-01 01:23
2015-01-01 12:34:56
20150101T123456
2015/01/01
2015/01/01 13:34
2015/01/01 1:34pm
12:34
3am
1 day
1y, 3w, 4hrs, 5s
1 year, 2 months, 3 days, 4 weeks, 5 hours, 6 minutes, 7 seconds, 8 milliseconds

FAQ

  • Q: Are timezones handled?

  • A: Not yet. Using them will return a syntax error.

  • Q: Are leap seconds handled?

  • A: Not at all, and probably won’t be. “2015/07/01 - 2015/06/30 23:59:59” returns “1 second”.

  • Q: Is the format YYYY/MM/DD or YYYY/DD/MM?

  • A: YYYY/MM/DD.

  • Q: When inputting date “20150101”, it is parsed as number “20150101”.

  • A: That’s not a question, and that’s effectively a number. To force a datetime form, use “20150101 00:00” instead.

Dependencies

chronocalc depends on relativedelta for computing durations.

License

chronocalc is licensed under the WTFPLv2. See COPYING.WTFPL file.

Metadata

Release files for chronocalc 0.9.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for chronocalc 0.9.1
File Size Uploaded Provenance
chronocalc-0.9.1.tar.gz 7.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for chronocalc 0.9.1
File Interpreter ABI Platform
chronocalc-0.9.1-py3-none-any.whl Python 3 none any Details

Total release size: 17.6 kB

Release files / chronocalc-0.9.1.tar.gz

Download URL chronocalc-0.9.1.tar.gz
Size 7.5 kB
Tags Source
SHA-256 checksum
How to use checksums
9050fc03f371713d43f57837473cafae43d91187ccb9a491fb82fc0e23b7fb7f
BLAKE2b-256 checksum
How to use checksums
7e8824353606051a0561053ab6d18b7d079e7aa0ef9fc559da2260fa8939064d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Release files / chronocalc-0.9.1-py3-none-any.whl

Download URL chronocalc-0.9.1-py3-none-any.whl
Size 10.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b78c559576cfddf9da6dfb8c9f485a2aaf5c6f66742c8effc6dd1e2443d726a6
BLAKE2b-256 checksum
How to use checksums
2833d7c1da0be11ea6c3340749628ce9c8b7a5eb82ec14c63c9ead0b7eb132d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Security for chronocalc 0.9.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.9.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page