GithubHelp home page GithubHelp logo

dur's Introduction

dur

a library to parse:

  • time specifications and convert them to durations.
  • datetime specifications and convert them to unix timestamps.

Meant to work like Graphite's from/until parsing. which aims to support all at(1) formats also. So do we. see some notes below.

Durations

Similar to time.ParseDuration which has valid time units "ns", "us" (or "µs"), "ms", "s", "m", "h". which allows signed sequences and optional fractions like "300ms", "-1.5h" or "2h45m".

But we work with larger units (and more forgiving ways to specify them) in this range: s/sec/secs/second/seconds, m/min/mins/minute/minutes, h/hour/hours, d/day/days, w/week/weeks, mon/month/months, y/year/years We however do not allow fractions or negative numbers. Note that this library takes a shortcut to provide convenience: a day = 24 hours, week = 7days, mon = 30 times 24 hours, year is 365 days. If these inaccuracies are a problem to you, do your own date math.

E.g.: '7d', '1y6mon', '1hour15min3s'

Datetimes

Functions to convert human specified date time specifications into timestamps. Supported formats:

  • now-<duration> now with duration subtracted. (for duration formats see above)
  • -<duration>: shortcut for the above
  • now+<duration> now with duration added. (for duration formats see above)
  • HH:MM_YYMMDD
  • YYYYMMDD
  • MM/DD/YY
  • integer: unix timestamp
  • <monthname> <num> like january 3 or march 8
  • monday, tuesday last (or current day if matching) day.
  • at formats : now, today, midnight, noon, teatime, midnight yesterday, 6pm tomorrow, 3AM yesterday

See the code and unit tests for details.

Notes on compatibility and implementation.

  • Graphite #1691: monthname+num goes back in time and clears HH/MM fields (unlike at): we follow graphite.
  • Graphite applies the appropriate timezone (given via tz argument or defaulting to what's configured in the config file) to:
    1. the interpretation of datetime specifications where applicable.
    2. the rendering of output timestamps in images (does not apply for metrictank) Though #639 shows (1) doesn't always work (not for at-style patterns). Here we apply this consistently.
  • Graphite #263 shows that patterns like "6pm+yesterday" sometimes don't work. Here it does.
  • Graphite doesn't seem to support all the at syntax, and we aim to support the same as Graphite for now (which is already quite much!). Going 100% is not a high prio for now.

dur's People

Contributors

dieterbe avatar dancech avatar krajorama avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.