Skip to main content

Parser for date range conditionals.

Project description

Info:This is the README file for Date Conditionals.
Author: Chris Warrick <chris@chriswarrick.com>
Copyright: © 2016-2018, Chris Warrick.
Date: 2020-07-01
Version: 0.1.7
https://travis-ci.org/Kwpolska/datecond.svg?branch=master

PURPOSE

This is a minimalistic (and slightly hacky) parser for date range conditionals.

INSTALLATION

pip install datecond

FORMAT

  • comma-separated clauses (AND)
  • clause: attribute comparison_operator value (spaces optional)
    • attribute: year, month, day, hour, month, second, weekday, isoweekday or empty for full datetime
    • comparison_operator: == != <= >= < >
    • value: integer, ‘now’, ‘today’, or dateutil-compatible date input

API

The library exposes only one function:

date_in_range(date_range, date, debug=True, now=None)

Where date_range is the date conditional (see FORMAT above), date is a datetime object, and now is the current date (used for ‘now’/’today’ comparisons; if not specified, datetime.datetime.now() or datetime.date.today() is used)

CLI USAGE

$ python -m datecond
Date range to accept: year == 2016
Date to test: 2016-01-01
    Date parsed: 2016-01-01 00:00:00
    <2016 == 2016>
    In range: True
Date to test: 2016-02-02
    Date parsed: 2016-02-02 00:00:00
    <2016 == 2016>
    In range: True
Date to test: 2017-01-01
    Date parsed: 2017-01-01 00:00:00
    <2017 == 2016>
    In range: False

$ python -m datecond
Date range to accept: year == 2016, month > 06, day >= 07
Date to test: 2016-06-07
    Date parsed: 2016-06-07 00:00:00
    <2016 == 2016>
    <6 > 6>
    <7 >= 7>
    In range: False
Date to test: 2016-07-07
    Date parsed: 2016-07-07 00:00:00
    <2016 == 2016>
    <7 > 6>
    <7 >= 7>
    In range: True
Date to test: 2016-08-08
    Date parsed: 2016-08-08 00:00:00
    <2016 == 2016>
    <8 > 6>
    <8 >= 7>
    In range: True
Date to test: 2015-07-07
    Date parsed: 2015-07-07 00:00:00
    <2015 == 2016>
    <7 > 6>
    <7 >= 7>
    In range: False

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for datecond, version 0.1.7
Filename, size File type Python version Upload date Hashes
Filename, size datecond-0.1.7-py2.py3-none-any.whl (8.9 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size datecond-0.1.7.tar.gz (10.7 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page