Skip to main content

A powerful Python library for date manipulation and formatting

Project description

Datepulator 📅

A powerful and flexible Python library for advanced date and time manipulation. Datepulator provides an intuitive interface for working with dates, including timezone conversions, business day calculations, date arithmetic, and more.

PyPI version Python Support License: MIT

Features 🌟

  • 📅 Date Arithmetic: Add or subtract years, months, days, hours, minutes, and seconds
  • 🌍 Timezone Support: Convert dates between any timezone using pytz
  • 💼 Business Days: Calculate business days considering weekends and holidays
  • 📊 Date Ranges: Generate sequences of dates with custom intervals
  • 🎂 Age Calculation: Calculate age with detailed breakdown
  • 🔄 Format Conversion: Convert between different date formats
  • Performance: Optimized for speed and efficiency
  • 🐍 Type Hints: Full typing support for better IDE integration

Installation 📦

pip install datepulator

Quick Start 🚀

from datepulator import DateManager

# Initialize DateManager
dm = DateManager(default_timezone="UTC")

# Convert date format
result = dm.convert("2023/12/25", from_format="%Y/%m/%d", to_format="%d-%b-%Y")
print(result)  # Output: 25-Dec-2023

# Add time to a date
new_date = dm.add_time("2023-01-15", 
                       years=1, 
                       months=2, 
                       days=10)
print(new_date)  # Output: 2024-03-25T00:00:00

# Calculate age
age = dm.calculate_age("1990-05-20")
print(age)  # Output: {'years': 33, 'months': 7, 'days': 15, 'total_days': 12271}

Detailed Usage 📚

1. Date Arithmetic

dm = DateManager()

# Add time
future_date = dm.add_time("2023-01-15",
                         years=1,
                         months=2,
                         days=3,
                         hours=4,
                         minutes=30)

# Subtract time
past_date = dm.subtract_time("2023-01-15",
                           months=3,
                           days=5)

2. Timezone Conversions

# Convert from UTC to New York time
ny_time = dm.convert_timezone("2023-01-15 10:00:00",
                            from_tz="UTC",
                            to_tz="America/New_York")

# Convert from Tokyo to London time
london_time = dm.convert_timezone("2023-01-15 15:00:00",
                                from_tz="Asia/Tokyo",
                                to_tz="Europe/London")

3. Business Days

# Define holidays
holidays = [
    "2023-12-25",  # Christmas
    "2023-12-26",  # Boxing Day
    "2024-01-01"   # New Year's Day
]

# Check if it's a business day
is_working = dm.is_business_day("2023-12-25", holidays=holidays)

# Add business days
next_working_day = dm.add_business_days("2023-12-24", 
                                      days=3,
                                      holidays=holidays)

4. Date Ranges

# Get daily dates
daily_dates = dm.get_date_range("2023-01-01",
                               "2023-01-10",
                               interval="days")

# Get weekly dates
weekly_dates = dm.get_date_range("2023-01-01",
                                "2023-03-01",
                                interval="weeks")

# Get monthly dates
monthly_dates = dm.get_date_range("2023-01-01",
                                 "2023-12-31",
                                 interval="months")

5. Age Calculation

# Calculate age as of today
current_age = dm.calculate_age("1990-05-20")

# Calculate age as of a specific date
past_age = dm.calculate_age("1990-05-20", 
                          reference_date="2010-01-01")

API Reference 📖

DateManager Class

Constructor

DateManager(default_timezone: str = "UTC")

Methods

  1. convert(date_str: str, from_format: str = None, to_format: str = "%Y-%m-%d") -> str

    • Convert date string from one format to another
    • Auto-detects format if from_format is None
  2. add_time(date_str: str, years: int = 0, months: int = 0, days: int = 0, hours: int = 0, minutes: int = 0, seconds: int = 0) -> str

    • Add specified time duration to a date
    • Returns ISO format string
  3. subtract_time(date_str: str, years: int = 0, months: int = 0, days: int = 0, hours: int = 0, minutes: int = 0, seconds: int = 0) -> str

    • Subtract specified time duration from a date
    • Returns ISO format string
  4. convert_timezone(date_str: str, from_tz: str, to_tz: str) -> str

    • Convert date from one timezone to another
    • Uses pytz timezones
  5. get_date_range(start_date: str, end_date: str, interval: str = 'days') -> List[str]

    • Get list of dates between start_date and end_date
    • Interval options: 'days', 'weeks', 'months'
  6. calculate_age(birth_date: str, reference_date: str = None) -> Dict[str, int]

    • Calculate age and related information
    • Returns dict with years, months, days, and total_days
  7. is_business_day(date_str: str, holidays: List[str] = None) -> bool

    • Check if given date is a business day
    • Considers weekends and optional holidays
  8. add_business_days(date_str: str, days: int, holidays: List[str] = None) -> str

    • Add specified number of business days
    • Skips weekends and holidays

Error Handling 🚨

All methods include comprehensive error handling and will raise ValueError with descriptive messages when:

  • Invalid date strings are provided
  • Invalid formats are specified
  • Invalid timezone names are used
  • Other validation errors occur

Contributing 🤝

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License 📄

This project is licensed under the MIT License - see the LICENSE file for details.

Support 💬

If you have any questions or run into issues, please:

  1. Check the Issues page
  2. Create a new issue if your problem isn't already listed
  3. Provide as much detail as possible about your problem

Acknowledgments 🙏


Made with ❤️ by [Your Name/Organization]

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

datepulator-0.1.0.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

datepulator-0.1.0-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file datepulator-0.1.0.tar.gz.

File metadata

  • Download URL: datepulator-0.1.0.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.7

File hashes

Hashes for datepulator-0.1.0.tar.gz
Algorithm Hash digest
SHA256 518ac2f11033b572eb3483f3e75b66312e9395480e59b459bf25e1d8a2561775
MD5 630ba357c6a143c3644c1df09c019500
BLAKE2b-256 52edb4f70dc0c1c347729510e06a186a8822a5d6987106ec4828ea39f146d76e

See more details on using hashes here.

File details

Details for the file datepulator-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: datepulator-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.7

File hashes

Hashes for datepulator-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fcfe95ff97d88d1200cd58d95c467ba916331a1b4dda033923bed27bbfb26163
MD5 68bd14adef1f191f6360fdf99f49edd7
BLAKE2b-256 4a8100a062c8a57a7333b83aaee9f1a670a8cd10f1948a1f4263c0f0cff9c69a

See more details on using hashes here.

Supported by

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