Python Package Exercise
An exercise to create a Python package, build it, test it, distribute it, and use it. See instructions for details.
datehelper
![Event Logger Workflow](https://github.com/software-students-fall2024/3-python-package-now-youre-unemployed/actions/workflows/event-logger.yml/badge.svg)
A Python utility package for date manipulation
Overview
datehelper
is a Python package to help with simple date manipulation tasks. The functions included can help calculate date differences, check for weekends, and help find the date of the next requested weekday. This package can streamline date-related logic in Python projects.
Features
- days_between(date1, date2): Returns the number of days between two dates.
- add_days(date, days): Returns a new date given a date and a number of days.
- is_weekend(date): Checks if a given date is a weekend (Saturday or Sunday).
- next_weekday(date, weekday): Returns the date of the next given weekday.
Installation
pip
:
pip install datehelper
- Import the functions into your code:
from datehelper import days_between, add_days, is_weekend, next_weekday
Usage Examples
next_weekday(given_date: date, weekday: int) -> date
Returns the next occurrence of a specified weekday from a given date. Weekdays are represented by integers where Monday is 0 and Sunday is 6.
print(next_weekday(date(2024, 11, 4), 3))
days_between(date1: date, date2: date) -> int
Calculates the absolute number of days between two dates.
print(days_between(date(2023, 1, 1), date(2023, 1, 10)))
add_days(start_date: date, days: int) -> date
Returns a new date that is a specified number of days after the given start date.
print(add_days(date(2023, 1, 1), 10))
is_weekend(check_date: datetime) -> bool
Checks if a given date falls on a weekend (Saturday or Sunday).
print(is_weekend(datetime(2024, 11, 3)))
For a complete example, see example_date.py
.
Setup
- Clone the Repository
First, clone the repository to your local machine:
git clone datehelper repository
- Next cd into where the repository folder is located on your local machine:
cd local/path/to/datehelper
- Thirdly install pipenv if you have not already using and then activate the virtual environment:
pip install pipenv
pipenv shell
- Install the dependencies
pipenv install --dev
- Build the package
python -m build
- If you have already built the package make sure to clean it:
rm -rf dist src/*.egg-info
- To run tests:
pipenv run pytest
Team Members