Download the PHP package kachnitel/duration-bundle without Composer
On this page you can find all versions of the php package kachnitel/duration-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package duration-bundle
DurationBundle
A Symfony bundle for handling duration parsing, formatting, and form integration. Parse human-readable duration strings (e.g., "2h 30m", "HH:MM:SS") and format seconds into readable formats.
Features
- Parse multiple duration formats: "2h 30m", "2.5 hours", "90 minutes", "HH:MM", "HH:MM:SS"
- Format durations: Convert seconds to human-readable strings with customizable units
- Symfony Form integration: DurationType for seamless form handling
- Twig filters: Display durations in templates with ease
- Flexible unit configuration: Support for years, months, weeks, days, hours, minutes, seconds
- Production-tested: Extracted from real-world application code
Installation
Install the bundle via Composer:
If you're not using Symfony Flex, enable the bundle in config/bundles.php:
Usage
1. Service Usage
The DurationUtil service provides static methods for duration manipulation:
2. Form Integration
Use DurationType in your forms to handle duration input:
In your entity, store the duration as an integer (seconds):
The form type automatically:
- Converts seconds to human-readable format for display (e.g., "2h 30m")
- Parses user input back to seconds for storage
Supported Input Formats:
2h 30mor2h30m- Hours and minutes with short units2.5 hours- Decimal with long unit names90 minutesor90m- Minutes only02:30- HH:MM format (interpreted as hours:minutes)02:30:45- HH:MM:SS format9000- Plain seconds
3. Twig Filters
Display durations in your templates using the provided Twig filters:
Advanced Configuration
Custom Unit Selection
You can specify which units to include when formatting:
Available Units
The bundle supports the following units (defined in DurationUtil::UNIT_CONFIG):
| Unit | Short | Long | Seconds |
|---|---|---|---|
y |
y | year/years | 31,536,000 |
mo |
mo | month/months | 2,592,000 |
w |
w | week/weeks | 604,800 |
d |
d | day/days | 86,400 |
h |
h | hour/hours | 3,600 |
m |
m | minute/minutes | 60 |
s |
s | second/seconds | 1 |
Examples
Example 1: Time Tracking Application
Example 2: Task Estimation
Example 3: Service Layer
Requirements
- PHP 8.2 or higher
- Symfony 6.4 or 7.0+
Testing
Run the test suite:
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This bundle is released under the MIT License. See the LICENSE file for details.
Credits
Developed by Mr. Duck
Extracted from production code and open-sourced for the Symfony community.
Support
If you encounter any issues or have questions:
- Open an issue on GitHub
- Check existing issues for solutions
Changelog
1.0.0 (Initial Release)
- Duration parsing from multiple formats
- Duration formatting with customizable units
- Symfony Form integration (DurationType)
- Twig filters (duration, toSeconds, hhmm)
- DateInterval conversion utilities
- Full test coverage
All versions of duration-bundle with dependencies
symfony/form Version ^6.4|^7.0
symfony/twig-bundle Version ^6.4|^7.0
twig/twig Version ^3.0