PHP
PHP copied to clipboard
Add ConvertTime Class with Time Conversion Functionality and Unit Tests
Description:
This pull request introduces the ConvertTime class, providing a robust time conversion function alongside a complete suite of unit tests to ensure accurate and reliable operation.
Key Features:
convertTimeFunction: Converts a specified value between various time units (e.g., seconds, minutes, hours, days, weeks, months, and years) using predefined conversion factors.- Exception Handling: Throws clear exceptions for invalid input units, enhancing user feedback and preventing errors.
- PSR-12 Compliance: The code adheres to PSR-12 standards, ensuring readability and maintainability.
Unit Tests:
The ConvertTimeTest class covers the following:
- Basic Conversion Tests: Verifies correct conversions between time units.
- Edge Case Handling: Tests zero-value conversions for non-negative results.
- Invalid Unit Handling: Tests exception handling for invalid
fromandtounits with descriptive error messages.
This addition enhances functionality by enabling easy and accurate time conversions while ensuring reliability through comprehensive testing.