feat: add time unit conversion#996
Merged
siriak merged 1 commit intoTheAlgorithms:masterfrom Jan 16, 2026
Merged
Conversation
Contributor
Author
|
@siriak, this is ready to be merged. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #996 +/- ##
=======================================
Coverage 95.96% 95.97%
=======================================
Files 364 365 +1
Lines 24810 24888 +78
=======================================
+ Hits 23810 23887 +77
- Misses 1000 1001 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
siriak
approved these changes
Jan 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR adds a new module for converting between different time units (seconds, minutes, hours, days, weeks, months, and years).
Features Added
convert_time: Convert time values between any two supported unitsTimeUnitenum for type-safe time unit representationType of Change
Testing
All tests pass:
cargo test time_units::testsResults:
Algorithm Complexity
Implementation Details
Conversion Algorithm
Time Unit Values
All conversions use these standardized values:
Enum-Based Design
TimeUnitenum instead of string dictionaries for type safetyCopytrait for efficient passingCase Handling
TimeUnit::from_str()normalizes input with.to_lowercase()"HOURS","Hours","hours", etc.Error Handling
Returns
Result<f64, String>with descriptive error messages:"'time_value' must be a non-negative number."NaNandInfinityvalues"Invalid unit {unit} is not in seconds, minutes, hours, days, weeks, months, years."Example error handling:
References
Checklist
TimeUnit)src/conversions/mod.rsExample Usage
Additional Notes
std