Format a time (duration) in seconds
Note: values are limited in range:
- days: 000-365
- hours: 00-24
- minutes: 00-59
- seconds: 00-59
Note: years and days are based starting Jan. 1, 1970
:d |
[R] |
|
:h |
[R] |
|
:m |
[R] |
|
:s |
[R] |
|
:secs |
[R] |
|
:t |
[R] |
|
:y |
[R] |
|
Create UTC time and extract individual values.
# File util/tmdisplay.rb, line 54
def initialize(secs)
@secs = secs
@t = Time.at(secs)
@t.utc
vals = @t.strftime("%Y:%j:%H:%M:%S").split(":")
@y = (vals.shift.to_i - 1970).to_s
@d = sprintf("%03d", (vals.shift.to_i - 1))
@h = vals.shift
@m = vals.shift
@s = vals.shift
end
Return time as MM:SS, truncating hours, days, and years.
# File util/tmdisplay.rb, line 69
def ms()
"#{@m}:#{@s}"
end
Return time as HH:MM:SS, truncating days and years.
# File util/tmdisplay.rb, line 73
def hms()
"#{@h}:#{@m}:#{@s}"
end
Format time according to format string fmt.
- fmt
- Format string using %y, %d, %h, %m, %s, and %% to represent years, days,
hours, minutes, seconds, and literal '%' character;
# File util/tmdisplay.rb, line 81
def format(fmt)
s = fmt.gsub(/%[Yy]/, @y).gsub(/%[Dd]/, @d)
s.gsub(/%[Hh]/, @h).gsub(/%[Mm]/, @m).gsub(/%[Ss]/, @s).gsub("%%", "%")
end