Skip to main content

A package used to render opening hours in a human-friendly format

Project description

Human Friendly Opening Hours - Display Opening Hours in a human-friendly way

This is a work-in-progress package. Any contributions and suggestions, especially for a more Pythonic solution are welcome.

Human Friendly Opening Hours is a Python 3 module which takes as input raw opening hours and allows you to display them in a human friendly way.

from human_friendly_opening_hours import OpeningHours, Opening, Weekdays, Options
from datetime import time, datetime

shopOpeningHours = OpeningHours()

shopOpeningHours.add_opening(Opening(Weekdays.thu, time(8, 0), time(12, 0)))
shopOpeningHours.add_opening(Opening(Weekdays.wed, time(8, 0), time(12, 0)))
shopOpeningHours.add_opening(Opening(Weekdays.tue, time(8, 0), time(12, 0)))
shopOpeningHours.add_opening(Opening(Weekdays.mon, time(8, 0), time(12, 0)))
shopOpeningHours.add_opening(Opening(Weekdays.mon, time(15, 0), time(17, 0)))
shopOpeningHours.add_opening(Opening(Weekdays.fri, time(8, 0), time(14, 0)))

result = shopOpeningHours.opening_hours_description()

print('\n'.join(map(lambda x: str(x), result)))

The above will print the following string:

Monday: 08:00 to 12:00, 15:00 to 17:00
Tuesday - Thursday: 08:00 to 12:00
Friday: 08:00 to 14:00

You can also pass options to the opening_hours_description() as such:

options = Options()
options.time_format = '%I:%M %p' # Show dates in 12hr format
options.days_of_the_week = ["Mon", "Tue", "Wed", "Thur", "Fri", "Sat", "Sun"]
result = shopOpeningHours.opening_hours_description(options)

The above will instead result in:

Mon: 08:00 AM to 12:00 PM, 03:00 PM to 05:00 PM
Tue - Thur: 08:00 AM to 12:00 PM
Fri: 08:00 AM to 02:00 PM

Additionally you can use

is_open = shopOpeningHours.is_open(datetime.now())

to check if the time passed matches the opening hours.

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

human-friendly-opening-hours-0.0.6.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

human_friendly_opening_hours-0.0.6-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file human-friendly-opening-hours-0.0.6.tar.gz.

File metadata

  • Download URL: human-friendly-opening-hours-0.0.6.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.3

File hashes

Hashes for human-friendly-opening-hours-0.0.6.tar.gz
Algorithm Hash digest
SHA256 f022de1abeb7907375279752cef84fbbb519cb91e311e77aaa86e6110577abdb
MD5 7c0e733b9cefab81f9ea985c45641ca4
BLAKE2b-256 d2c710f806f03ba2b49daab1324cc3542885c53e87282ed85ef95255ed86c71a

See more details on using hashes here.

File details

Details for the file human_friendly_opening_hours-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: human_friendly_opening_hours-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.3

File hashes

Hashes for human_friendly_opening_hours-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 53bbebee94aaf3b5efdbc2e67d71184bfae4edac565233d8ed793ddb0eae9d82
MD5 b31ae9b45a88fb3abff1ed2224b4a4a6
BLAKE2b-256 5d8ed9c77d76fa05956dd3b48de620d0447135e75cea1fa93e7f6bff87e656b0

See more details on using hashes here.

Supported by

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