dateutil functions for Datasette
Project description
datasette-dateutil
dateutil functions for Datasette
Installation
Install this plugin in the same environment as Datasette.
$ datasette install datasette-dateutil
Usage
This function adds custom SQL functions that expose functionality from the dateutil Python library.
Once installed, the following SQL functions become available:
dateutil_parse(text)
- returns an ISO8601 date string parsed from the text, ornull
if the input could not be parsed.dateutil_parse("10 october 2020 3pm")
returns2020-10-10T15:00:00
.dateutil_parse_fuzzy(text)
- same asdateutil_parse()
but this also works against strings that contain a date somewhere within them - that date will be returned, ornull
if no dates could be found.dateutil_parse_fuzzy("This is due 10 september")
returns2020-09-10T00:00:00
(but will start returning the 2021 version of that if the year is 2021).dateutil_easter(year)
- returns the date for Easter in that year, for exampledateutil_easter("2020")
returns2020-04-12
.
The dateutil_parse()
and dateutil_parse_fuzzy()
functions both follow the American convention of assuming that 1/2/2020
lists the month first, evaluating this example to the 2nd of January.
If you want to assume that the day comes first, use these two functions instead:
dateutil_parse_dayfirst(text)
dateutil_parse_fuzzy_dayfirst(text)
Development
To set up this plugin locally, first checkout the code. Then create a new virtual environment:
cd datasette-dateutil
python3 -mvenv venv
source venv/bin/activate
Or if you are using pipenv
:
pipenv shell
Now install the dependencies and tests:
pip install -e '.[test]'
To run the tests:
pytest
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
Built Distribution
Hashes for datasette_dateutil-0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a8c50e8960f0b16b20e4121117204d0c2e3cf2728edef9fb0c588eccf800c2dc |
|
MD5 | fcae5535eb83e1fa4c4517550e561084 |
|
BLAKE2b-256 | 06623b0b8b4fa8819470b8207bffe3f72865ee87e90727fc5afbed37ed98b026 |