This module provides a convenient way to calculate the difference between two dates in days, months, and years. It also offers the ability to calculate the difference between two times in hours, minutes, and seconds. It offers a simple and effective solution for performing date and time calculations in Crystal applications.
-
Add the
dtd
dependency to yourshard.yml
file:dependencies: dtd: github: danielcoderx/dtd
-
Run
shards install
to fetch the dependency.
require "dtd"
date1 = "2022/04/30"
date2 = "2022/05/01"
result = Dtd.date_diff(date1, date2)
puts "Difference: #{result["years"]} years, #{result["months"]} months, #{result["days"]} days"
require "dtd"
time1 = "2022/05/01 10:30:00"
time2 = "2022/05/01 12:45:30"
result = Dtd.time_diff(time1, time2)
puts "Difference: #{result["hours"]} hours, #{result["minutes"]} minutes, #{result["seconds"]} seconds"
- Calculates the difference between two dates in days, months, and years.
- Calculates the difference between two times in hours, minutes, and seconds.
- Supports custom time zones for accurate calculations.
- Returns a Hash that provides the difference in years, months, days, hours, minutes, and seconds.
- Handles scenarios where the second date or time is before the first date or time.
- Provides error messages when necessary.
- Enhance error handling and error messages.
- Add support for accepting various input formats.
- Improve overall performance and efficiency.
- Fork the repository from https://github.com/danielcoderx/dtd.
- Create your feature branch:
git checkout -b my-new-feature
. - Commit your changes:
git commit -am 'Add some feature'
. - Push the branch to your forked repository:
git push origin my-new-feature
. - Create a new Pull Request.
- danielcoderx - Creator and maintainer
Your contributions to this project are highly appreciated! If you have any suggestions, bug reports, or feature requests, please don't hesitate to open an issue or submit a pull request. Let's work together to make dtd
even better!