datepulator


Namedatepulator JSON
Version 0.1.1 PyPI version JSON
download
home_pagehttps://github.com/yourusername/datepulator
SummaryA powerful Python library for date manipulation and formatting
upload_time2024-11-23 10:56:23
maintainerNone
docs_urlNone
authorAshutosh Bele
requires_python>=3.7
licenseMIT License Copyright (c) 2024 Ashutosh Bele Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords date time manipulation formatting timezone business days
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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](https://badge.fury.io/py/datepulator.svg)](https://pypi.org/project/datepulator/)
[![Python Support](https://img.shields.io/pypi/pyversions/datepulator.svg)](https://pypi.org/project/datepulator/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/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 📦

```bash
pip install datepulator
```

## Quick Start 🚀

```python
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

```python
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

```python
# 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

```python
# 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

```python
# 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

```python
# 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

```python
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](LICENSE) file for details.

## Support 💬

If you have any questions or run into issues, please:
1. Check the [Issues](https://github.com/Ashlo/Datepulator/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 🙏

- Built with [Python](https://www.python.org/)
- Timezone support by [pytz](https://pythonhosted.org/pytz/)
- Date parsing by [python-dateutil](https://dateutil.readthedocs.io/)

---

Made with ❤️ by Ashutosh Bele

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/yourusername/datepulator",
    "name": "datepulator",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "date, time, manipulation, formatting, timezone, business days",
    "author": "Ashutosh Bele",
    "author_email": "Ashutosh Bele <your.email@example.com>",
    "download_url": "https://files.pythonhosted.org/packages/18/77/859869f6c4321ac8b75c5b8045ac9b6c37cf3285d2f86ab1218e048ee4ab/datepulator-0.1.1.tar.gz",
    "platform": null,
    "description": "# Datepulator \ud83d\udcc5\n\nA 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.\n\n[![PyPI version](https://badge.fury.io/py/datepulator.svg)](https://pypi.org/project/datepulator/)\n[![Python Support](https://img.shields.io/pypi/pyversions/datepulator.svg)](https://pypi.org/project/datepulator/)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n## Features \ud83c\udf1f\n\n- \ud83d\udcc5 **Date Arithmetic**: Add or subtract years, months, days, hours, minutes, and seconds\n- \ud83c\udf0d **Timezone Support**: Convert dates between any timezone using pytz\n- \ud83d\udcbc **Business Days**: Calculate business days considering weekends and holidays\n- \ud83d\udcca **Date Ranges**: Generate sequences of dates with custom intervals\n- \ud83c\udf82 **Age Calculation**: Calculate age with detailed breakdown\n- \ud83d\udd04 **Format Conversion**: Convert between different date formats\n- \u26a1 **Performance**: Optimized for speed and efficiency\n- \ud83d\udc0d **Type Hints**: Full typing support for better IDE integration\n\n## Installation \ud83d\udce6\n\n```bash\npip install datepulator\n```\n\n## Quick Start \ud83d\ude80\n\n```python\nfrom datepulator import DateManager\n\n# Initialize DateManager\ndm = DateManager(default_timezone=\"UTC\")\n\n# Convert date format\nresult = dm.convert(\"2023/12/25\", from_format=\"%Y/%m/%d\", to_format=\"%d-%b-%Y\")\nprint(result)  # Output: 25-Dec-2023\n\n# Add time to a date\nnew_date = dm.add_time(\"2023-01-15\", \n                       years=1, \n                       months=2, \n                       days=10)\nprint(new_date)  # Output: 2024-03-25T00:00:00\n\n# Calculate age\nage = dm.calculate_age(\"1990-05-20\")\nprint(age)  # Output: {'years': 33, 'months': 7, 'days': 15, 'total_days': 12271}\n```\n\n## Detailed Usage \ud83d\udcda\n\n### 1. Date Arithmetic\n\n```python\ndm = DateManager()\n\n# Add time\nfuture_date = dm.add_time(\"2023-01-15\",\n                         years=1,\n                         months=2,\n                         days=3,\n                         hours=4,\n                         minutes=30)\n\n# Subtract time\npast_date = dm.subtract_time(\"2023-01-15\",\n                           months=3,\n                           days=5)\n```\n\n### 2. Timezone Conversions\n\n```python\n# Convert from UTC to New York time\nny_time = dm.convert_timezone(\"2023-01-15 10:00:00\",\n                            from_tz=\"UTC\",\n                            to_tz=\"America/New_York\")\n\n# Convert from Tokyo to London time\nlondon_time = dm.convert_timezone(\"2023-01-15 15:00:00\",\n                                from_tz=\"Asia/Tokyo\",\n                                to_tz=\"Europe/London\")\n```\n\n### 3. Business Days\n\n```python\n# Define holidays\nholidays = [\n    \"2023-12-25\",  # Christmas\n    \"2023-12-26\",  # Boxing Day\n    \"2024-01-01\"   # New Year's Day\n]\n\n# Check if it's a business day\nis_working = dm.is_business_day(\"2023-12-25\", holidays=holidays)\n\n# Add business days\nnext_working_day = dm.add_business_days(\"2023-12-24\", \n                                      days=3,\n                                      holidays=holidays)\n```\n\n### 4. Date Ranges\n\n```python\n# Get daily dates\ndaily_dates = dm.get_date_range(\"2023-01-01\",\n                               \"2023-01-10\",\n                               interval=\"days\")\n\n# Get weekly dates\nweekly_dates = dm.get_date_range(\"2023-01-01\",\n                                \"2023-03-01\",\n                                interval=\"weeks\")\n\n# Get monthly dates\nmonthly_dates = dm.get_date_range(\"2023-01-01\",\n                                 \"2023-12-31\",\n                                 interval=\"months\")\n```\n\n### 5. Age Calculation\n\n```python\n# Calculate age as of today\ncurrent_age = dm.calculate_age(\"1990-05-20\")\n\n# Calculate age as of a specific date\npast_age = dm.calculate_age(\"1990-05-20\", \n                          reference_date=\"2010-01-01\")\n```\n\n## API Reference \ud83d\udcd6\n\n### DateManager Class\n\n#### Constructor\n\n```python\nDateManager(default_timezone: str = \"UTC\")\n```\n\n#### Methods\n\n1. `convert(date_str: str, from_format: str = None, to_format: str = \"%Y-%m-%d\") -> str`\n   - Convert date string from one format to another\n   - Auto-detects format if `from_format` is None\n\n2. `add_time(date_str: str, years: int = 0, months: int = 0, days: int = 0, hours: int = 0, minutes: int = 0, seconds: int = 0) -> str`\n   - Add specified time duration to a date\n   - Returns ISO format string\n\n3. `subtract_time(date_str: str, years: int = 0, months: int = 0, days: int = 0, hours: int = 0, minutes: int = 0, seconds: int = 0) -> str`\n   - Subtract specified time duration from a date\n   - Returns ISO format string\n\n4. `convert_timezone(date_str: str, from_tz: str, to_tz: str) -> str`\n   - Convert date from one timezone to another\n   - Uses pytz timezones\n\n5. `get_date_range(start_date: str, end_date: str, interval: str = 'days') -> List[str]`\n   - Get list of dates between start_date and end_date\n   - Interval options: 'days', 'weeks', 'months'\n\n6. `calculate_age(birth_date: str, reference_date: str = None) -> Dict[str, int]`\n   - Calculate age and related information\n   - Returns dict with years, months, days, and total_days\n\n7. `is_business_day(date_str: str, holidays: List[str] = None) -> bool`\n   - Check if given date is a business day\n   - Considers weekends and optional holidays\n\n8. `add_business_days(date_str: str, days: int, holidays: List[str] = None) -> str`\n   - Add specified number of business days\n   - Skips weekends and holidays\n\n## Error Handling \ud83d\udea8\n\nAll methods include comprehensive error handling and will raise `ValueError` with descriptive messages when:\n- Invalid date strings are provided\n- Invalid formats are specified\n- Invalid timezone names are used\n- Other validation errors occur\n\n## Contributing \ud83e\udd1d\n\nContributions 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.\n\n1. Fork the repository\n2. Create your feature branch (`git checkout -b feature/AmazingFeature`)\n3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)\n4. Push to the branch (`git push origin feature/AmazingFeature`)\n5. Open a Pull Request\n\n## License \ud83d\udcc4\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## Support \ud83d\udcac\n\nIf you have any questions or run into issues, please:\n1. Check the [Issues](https://github.com/Ashlo/Datepulator/issues) page\n2. Create a new issue if your problem isn't already listed\n3. Provide as much detail as possible about your problem\n\n## Acknowledgments \ud83d\ude4f\n\n- Built with [Python](https://www.python.org/)\n- Timezone support by [pytz](https://pythonhosted.org/pytz/)\n- Date parsing by [python-dateutil](https://dateutil.readthedocs.io/)\n\n---\n\nMade with \u2764\ufe0f by Ashutosh Bele\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2024 Ashutosh Bele  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "A powerful Python library for date manipulation and formatting",
    "version": "0.1.1",
    "project_urls": {
        "Bug Tracker": "https://github.com/yourusername/datepulator/issues",
        "Documentation": "https://github.com/yourusername/datepulator#readme",
        "Homepage": "https://github.com/yourusername/datepulator",
        "Repository": "https://github.com/yourusername/datepulator.git"
    },
    "split_keywords": [
        "date",
        " time",
        " manipulation",
        " formatting",
        " timezone",
        " business days"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "15b3d840b9606b2d9fae2d2f432f8cd3f204eaf0a5cc1ada97881a1e9bf6b325",
                "md5": "d223285a62c5b32815a18f90c90d88f9",
                "sha256": "80af6549596fe76eb45fd34472dc20939ea3d99c4b343cc981b3c8886890cc36"
            },
            "downloads": -1,
            "filename": "datepulator-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d223285a62c5b32815a18f90c90d88f9",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 8530,
            "upload_time": "2024-11-23T10:56:22",
            "upload_time_iso_8601": "2024-11-23T10:56:22.402778Z",
            "url": "https://files.pythonhosted.org/packages/15/b3/d840b9606b2d9fae2d2f432f8cd3f204eaf0a5cc1ada97881a1e9bf6b325/datepulator-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1877859869f6c4321ac8b75c5b8045ac9b6c37cf3285d2f86ab1218e048ee4ab",
                "md5": "1efabb46273b527b4a5c5197178ee515",
                "sha256": "895d351ed6dec8b0be444ce75125e26d83b67614c61ae5d26daa9e5c4a927d9b"
            },
            "downloads": -1,
            "filename": "datepulator-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "1efabb46273b527b4a5c5197178ee515",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 9363,
            "upload_time": "2024-11-23T10:56:23",
            "upload_time_iso_8601": "2024-11-23T10:56:23.490932Z",
            "url": "https://files.pythonhosted.org/packages/18/77/859869f6c4321ac8b75c5b8045ac9b6c37cf3285d2f86ab1218e048ee4ab/datepulator-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-23 10:56:23",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "yourusername",
    "github_project": "datepulator",
    "github_not_found": true,
    "lcname": "datepulator"
}
        
Elapsed time: 0.68189s