Skip to main content

Python Opening Hours parser

CircleCI codecov Downloads

This library parses opening hours from various human-readable strings such as "Mon- Fri 9:00am - 5:30pm" into a more standard JSON format that can be processed more easily.

The format

opening_hours = [
	{
		"day": "monday",
		"opens": "9:00",
		"closes": "17:00"
	},
	//..
]

Installation

pip install parse-opening-hours

Usage

The simplest example is just printing the JSON for an opening hours string:

from opening_hours import OpeningHours

print(OpeningHours.parse("Mon- Fri 9:00am - 5:30pm").json())

This should give you the below output:

[
	{'day': 'monday', 'opens': '9:00', 'closes': '17:30'},
	{'day': 'tuesday', 'opens': '9:00', 'closes': '17:30'},
	{'day': 'wednesday', 'opens': '9:00', 'closes': '17:30'},
	{'day': 'thursday', 'opens': '9:00', 'closes': '17:30'},
	{'day': 'friday', 'opens': '9:00', 'closes': '17:30'}
]

This has been tested using Python 3.8.5

Documentation

In addition to this README, there is some documentation generated from inline documentation comments. This is available at https://moralcode.github.io/parse-opening-hours/

Environment variables

Setting the environment variable OH_DEBUG to a value of Y will set the root logging level to debug and will cause log entries to appear in stdout for debugging purposes

Troubleshooting

Assumptions

When specifying a time without AM or PM indicators, you may get an error that reads TypeError: Cannot convert a time of unknown type (AM, PM or 24H) without assuming its type.. To resolve this, pass assume_type=TimeType.AM when calling the parse() function. This will use AM in place of an unknown AM or PM designation. In cases like the string "9-5", if the second value in the range (in this case the 5 is smaller than the first (i.e. the 9) then it will be converted to PM automatically

Tests and Coverage

run pytet and generate coverage database pipenv run pytest --cov=./

show coverage report: pipenv run coverage report

Metadata

Release files for parse-opening-hours 0.4.2

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

Source distribution (sdist)

Source distribution for parse-opening-hours 0.4.2
File Size Uploaded
parse-opening-hours-0.4.2.tar.gz 10.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for parse-opening-hours 0.4.2
File Interpreter ABI Platform
parse_opening_hours-0.4.2-py3-none-any.whl Python 3 none any Details

Total release size: 23.8 kB

Release files / parse-opening-hours-0.4.2.tar.gz

Download URL parse-opening-hours-0.4.2.tar.gz
Size 10.7 kB
Tags Source
SHA-256 checksum
How to use checksums
6bf7dfee5f48c2e428fe31d810961d3347b5e2465ccb8249cd91f50295d2feaf
BLAKE2b-256 checksum
How to use checksums
a9fed752774dcea719e07b828382712f541ade7e713527ed83c24f6023829185
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.4.2 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.5

Release files / parse_opening_hours-0.4.2-py3-none-any.whl

Download URL parse_opening_hours-0.4.2-py3-none-any.whl
Size 13.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
72aed5c4e4b655d49f03d5284933c3e3394c3d27b217cfedeb2e226ae61a8c03
BLAKE2b-256 checksum
How to use checksums
bc465cd1950bcc5a41292b8b213dcb08c9e3fa04d2496b3f846c27c96e4d16e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.4.2 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.5

Release history Release notifications | RSS feed

This release

0.4.2 This release

2 release files

0.4.1

2 release files

0.4.0

2 release files

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