Method: Azure::ServiceBus::Interval#to_s

Defined in:
lib/azure/service_bus/interval.rb

#to_sObject Also known as: inspect

Public: Return this amount of seconds formatted as an interval.

Returns a String.



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/azure/service_bus/interval.rb', line 76

def to_s
  days    = to_i / 86400
  hours   = (to_i % 86400) / 3600
  minutes = (to_i % 3600) / 60
  seconds = (self % 60)

  days = "%<d>s" % {
    :d => days.zero? ? nil : "#{days}D"
  }

  time = "%<h>s%<m>s%<s>s" % {
    :h => hours.zero?               ? nil : "#{hours}H",
    :m => minutes.zero?             ? nil : "#{minutes}M",
    :s => nonzero? && seconds.zero? ? nil : "#{seconds}S"
  }

  "P#{days}" + (time.empty? ? "" : "T#{time}")
end