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
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/winrm/helpers/iso8601_duration.rb', line 7 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 |