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>

Date:
2017-03-07
Version:
0.1.5
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’ 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’ comparisons; if not specified, datetime.datetime.now() 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.

Source Distribution

datecond-0.1.5.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

datecond-0.1.5-py2.py3-none-any.whl (9.9 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file datecond-0.1.5.tar.gz.

File metadata

  • Download URL: datecond-0.1.5.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for datecond-0.1.5.tar.gz
Algorithm Hash digest
SHA256 7e81352e7a2a04515e76ae07f84b30e52370eb656fbfaf8dc1f5570ece861128
MD5 d569aede195295ffd688461d188a80c2
BLAKE2b-256 70b2525d5c4e9b6e3fc2118512129a3b92f4cbc6296d64668155776b3368e4b8

See more details on using hashes here.

File details

Details for the file datecond-0.1.5-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for datecond-0.1.5-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 534431b19236bc0a10b3397724896d1984e6b2c1d17c8a1140b79f90928e1a2e
MD5 d927aae54f43eaad258d04b118eb843e
BLAKE2b-256 27a184d776d08239dda533b4fd5fd7bf8cd943d4ee11033464cd64efca6ac39b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page