Skip to content

Latest commit

 

History

History
71 lines (49 loc) · 2.38 KB

README.md

File metadata and controls

71 lines (49 loc) · 2.38 KB

officehours

NPM info Codacy Badge Codacy Badge

Utility to calculate time intervals in working hours

Installation

$ pip install officehours

Usage

Create an instance of officehours.Calculator. You can optionally provide the required opening/closing hours (defaults to 9:00 and 17:00 respectively) and a list of date objects corresponding to bank holidays. You can use other modules such as Workalendar to obtain the list of non-working days.

from datetime import datetime, date
from officehours import Calculator
import workalendar.europe import Germany

germany = Germany()
holidays = [day[0] for day in germany.holidays(2017)]
calculator = Calculator('8:00', '16:00', holidays)

How many working hours transcurred between two dates?

from_day = datetime(2017, 3, 1, 12, 45)  # Wednesday at 12:45
to_day = datetime(2017, 3, 6, 10, 15)  # Monday at 10:45
calculator.working_hours(from_day, to_day)  # Returns 21.5

When is the next office opening time after a given date?

day = date(2017, 4, 29)  # Saturday
calculator.next_office_open(day)  # Returns May 2nd at 8:00, since May 1st is a bank holiday

A deliverable requires X working hours. When will it be ready?

from_day = datetime(2017, 6, 1, 11, 20)
working_hours = 36.5
calculator.due_date(working_hours, from_day)  # Returns June 8th at 15:50

When should work start considering it has to be ready by day D?

deadline = datetime(2017, 6, 15, 12)
working_hours = 15
calculator.start_time(working_hours, deadline)  # Returns June 13th at 13:00

Contributing

In lieu of a formal style guide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.