module Dtd
Overview
Module Dtd provides methods for calculating the difference between two dates.
Defined in:
dtd.crConstant Summary
-
VERSION =
"0.1.1"
-
The current version of the Dtd module.
Class Method Summary
-
.date_diff(date1 : String, date2 : String, time_zone : String = "UTC") : Hash(String, Int32) | Hash(String, String)
Calculates the difference between two dates in days, months, and years.
-
.time_diff(time1 : String, time2 : String, time_zone : String = "UTC") : Hash(String, Int32 | Int64) | Hash(String, Int32) | Hash(String, String)
Calculates the difference between two times in hours, minutes, and seconds.
Class Method Detail
Calculates the difference between two dates in days, months, and years.
date1 - The first date in the format YYYY/MM/DD (String). date2 - The second date in the format YYYY/MM/DD (String). time_zone - The time zone in which the dates are specified (String, default: "UTC").
Examples: Dtd.date_diff("2022/04/30", "2022/05/01") => {"years" => 0, "months" => 0, "days" => 1}
Returns a Hash containing the difference in years, months, and days, or an error Hash. If the difference is positive, the Hash contains the keys "years", "months", and "days" with their respective integer values. If date2 is before date1, the Hash contains the key "error" with the value "Date 2 is before date 1." If the difference is 0, the Hash contains the keys "years", "months", and "days" with the value 0 for each.
Calculates the difference between two times in hours, minutes, and seconds.
time1 - The first time in the format YYYY/MM/DD HH:MM:SS (String). time2 - The second time in the format YYYY/MM/DD HH:MM:SS (String). time_zone - The time zone in which the times are specified (String, default: "UTC").
Examples: Dtd.time_diff("2022/01/01 08:45:00", "2022/01/01 11:30:15") => {"hours" => 2, "minutes" => 45, "seconds" => 15}
Returns a Hash containing the difference in hours, minutes, and seconds, or an error Hash. If the difference is positive, the Hash contains the keys "hours", "minutes", and "seconds" with their respective integer values. If time2 is before time1, the Hash contains the key "error" with the value "Time 2 is before time 1." If the difference is 0, the Hash contains the keys "hours", "minutes", and "seconds" with the value 0 for each.