Module: Iso8601Duration
- Defined in:
- lib/winrm/helpers/iso8601_duration.rb
Overview
Format an ISO8601 Duration
Class Method Summary collapse
-
.sec_to_dur(seconds) ⇒ Object
Convert the number of seconds to an ISO8601 duration format.
Class Method Details
.sec_to_dur(seconds) ⇒ Object
Convert the number of seconds to an ISO8601 duration format
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/winrm/helpers/iso8601_duration.rb', line 25 def self.sec_to_dur(seconds) seconds = seconds.to_i iso_str = "P" if(seconds > 604800) # more than a week weeks = seconds / 604800 seconds -= (604800 * weeks) iso_str << "#{weeks}W" end if(seconds > 86400) # more than a day days = seconds / 86400 seconds -= (86400 * days) iso_str << "#{days}D" end if(seconds > 0) iso_str << "T" if(seconds > 3600) # more than an hour hours = seconds / 3600 seconds -= (3600 * hours) iso_str << "#{hours}H" end if(seconds > 60) # more than a minute minutes = seconds / 60 seconds -= (60 * minutes) iso_str << "#{minutes}M" end iso_str << "#{seconds}S" end iso_str end |