Skip to main content

A simple date helper library.

Project description

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

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

  1. pip:
pip install datehelper
  1. Import the functions into your code:
from datehelper import days_between, add_days, is_weekend, next_weekday

Usage Examples

  1. 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))
    
  2. 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)))
    
  3. 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))
    
  4. 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

  1. Clone the Repository

First, clone the repository to your local machine:

git clone datehelper repository 
  1. Next cd into where the repository folder is located on your local machine:
cd local/path/to/datehelper
  1. Thirdly install pipenv if you have not already using and then activate the virtual environment:
pip install pipenv 
pipenv shell
  1. Install the dependencies
pipenv install --dev
  1. Build the package
python -m build
  1. If you have already built the package make sure to clean it:
rm -rf dist src/*.egg-info
  1. To run tests:
pipenv run pytest

Team Members


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

datehelper_now_youre_unemployed-0.1.6.tar.gz (15.6 kB view details)

Uploaded Source

Built Distribution

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

File details

Details for the file datehelper_now_youre_unemployed-0.1.6.tar.gz.

File metadata

File hashes

Hashes for datehelper_now_youre_unemployed-0.1.6.tar.gz
Algorithm Hash digest
SHA256 1a8574dec36d46947336d5f00d4e9cd2a4732ff4d9e43e1371f5a7be5319bc40
MD5 f82feb26fad61d66879ed768c076d99f
BLAKE2b-256 fbc6634cc0c71e0991b75cd64913004c31dbd4ffed87251b005cd3644f4681d2

See more details on using hashes here.

File details

Details for the file datehelper_now_youre_unemployed-0.1.6-py3-none-any.whl.

File metadata

File hashes

Hashes for datehelper_now_youre_unemployed-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 24c70c17e9b78eb4388a7641f93d9dc3e5406873e90ae5bf489d0bd0a886409a
MD5 ab52618233f18e89aa0e94294f5727c6
BLAKE2b-256 d23685f48fea8b829ddf93e0995a593f31167a59614f9ca6678b52029d3c5bbc

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