Metadata-Version: 2.4
Name: total-time-formatter
Version: 1.0.2
Summary: A flexible library to convert various time inputs into a total duration format (HH:MM:SS).
Author-email: Cibelle Maciel da Costa <cibellemaciel02@gmail.com>
License: # LICENSE
        Copyright (c) 2025 Cibelle Maciel da Costa
        
        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.
Project-URL: Homepage, https://github.com/cibellemc/total-time-formatter/
Project-URL: Bug Tracker, https://github.com/cibellemc/total-time-formatter/issues
Keywords: datetime,timedelta,formatter,time,duration,hours,precision
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Utilities
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# Total Time Formatter

![PyPI Version](https://img.shields.io/pypi/v/total-time-formatter)

A simple yet powerful Python library to convert various time inputs into a total duration format (`HH:MM:SS`), where hours can exceed 24.

This tool is perfect for applications that need to calculate and display total durations, such as project time tracking, equipment runtime, or simply formatting time data consistently.

### Key Features

* **Flexible Inputs**: Handles `datetime` strings, time-only strings (`HH:MM:SS`), and native `timedelta` objects.
* **Total Hour Calculation**: Correctly calculates total hours from inputs that include date information, allowing hour counts beyond 24.
* **High Precision Control**: Offers precise control over how fractional seconds are handled: truncate, round up, or keep the exact original precision down to the microsecond.
* **Dependency-Free**: Pure Python with no external dependencies.

### Installation

Install the library directly from PyPI:

```bash
pip install total-time-formatter
```

### How to Use

Import the main function and the precision mode constants to get started.

```python
from total_time_formatter import format_total_hours, TRUNCATE, ROUND_UP, KEEP_PRECISION
from datetime import timedelta
```

#### 1. Converting a Datetime String

When you provide a full datetime string, the library calculates the total duration from a default reference date (`1900-01-01`).

```python
date_str = "1900-01-03 10:30:15" 
# Duration = 2 full days (48h) + 10h = 58 hours

duration = format_total_hours(date_str)

print(f"Input: '{date_str}'")
print(f"Total Duration: {duration}")
# Expected Output: Total Duration: 58:30:15
```

#### 2. Converting a Time-Only String (Duration)

If you provide a string that already represents a duration, it will be formatted correctly.

```python
duration_str = "48:25:10"
formatted = format_total_hours(duration_str)

print(f"Input: '{duration_str}'")
print(f"Formatted Duration: {formatted}")
# Expected Output: Formatted Duration: 48:25:10
```

#### 3. Converting a `timedelta` Object

The function can also directly format `timedelta` objects.

```python
td_object = timedelta(hours=75, minutes=5, seconds=22)
formatted = format_total_hours(td_object)

print(f"Input: {td_object}")
print(f"Formatted Duration: {formatted}")
# Expected Output: Formatted Duration: 75:05:22
```

#### 4. Controlling Precision

This is where the library shines. You can control how to handle fractional seconds using the `precision_mode` argument.

```python
time_with_ms = "10:20:30.789123"

# a) Truncate (default behavior)
truncated = format_total_hours(time_with_ms, precision_mode=TRUNCATE)
print(f"Truncated: {truncated}")
# Expected Output: Truncated: 10:20:30

# b) Round Up
rounded = format_total_hours(time_with_ms, precision_mode=ROUND_UP)
print(f"Rounded Up: {rounded}")
# Expected Output: Rounded Up: 10:20:31

# c) Keep Exact Precision
precise = format_total_hours(time_with_ms, precision_mode=KEEP_PRECISION)
print(f"Precise: {precise}")
# Expected Output: Precise: 10:20:30.789123
```

### License

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