Return the difference between two times using an array of Hour, Minutes, etc

time:diff($time1, $time2) : ARRAY

# note: "negative?" indicates that $time1 - $time2 is a negative number i.e. $time1 is bigger than $time2
time:diff("2021-1-1 10:30 UTC","2020-1-1 10:31 UTC")
#=> [
#=>     "years" => 0,
#=>     "months" => 11,
#=>     "days" => 30,
#=>     "hours" => 23,
#=>     "minutes" => 59,
#=>     "seconds" => 0,
#=>     "microseconds" => 0.0,
#=>     "negative?" => TRUE
#=> ]

time:diff("2020-1-1 10:31 UTC","2021-1-1 10:30 UTC")
#=> [
#=>     "years" => 0,
#=>     "months" => 11,
#=>     "days" => 30,
#=>     "hours" => 23,
#=>     "minutes" => 59,
#=>     "seconds" => 0,
#=>     "microseconds" => 0.0,
#=>     "negative?" => FALSE
#=> ]

# this function considers the timezone when finding the difference
$in_utc = "2020-1-1 10:31 UTC"
$in_pst = time:convert_timezone($in_utc, "PST")
#=> "2020-01-01 02:31:00.000000 PST"

time:diff("2020-1-1 10:31 UTC","2020-01-01 02:31:00.000000 PST")
#=> [
#=>     "years" => 0,
#=>     "months" => 0,
#=>     "days" => 0,
#=>     "hours" => 0,
#=>     "minutes" => 0,
#=>     "seconds" => 0,
#=>     "microseconds" => 0.0,
#=>     "negative?" => FALSE
#=> ]

Copyright ©2013-2022 SunSed®. All rights reserved.