Skip to content

Commit d11703d

Browse files
Mic92McSinyx
authored andcommitted
move format_progress to mpd module
The function is not used by any other module and is only really useful for formatting durations as exposed by mpd.
1 parent a902a23 commit d11703d

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed

helpers.lua

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -136,25 +136,6 @@ function helpers.uformat(array, key, value, unit)
136136
end
137137
-- }}}
138138

139-
-- {{{ Format playing progress
140-
function helpers.format_progress(elapsed, duration)
141-
local em, es = elapsed / 60, elapsed % 60
142-
local dm, ds = duration / 60, duration % 60
143-
144-
if dm < 10 then
145-
return ("%d:%02d"):format(em, es), ("%d:%02d"):format(dm, ds)
146-
elseif dm < 60 then
147-
return ("%02d:%02d"):format(em, es), ("%02d:%02d"):format(dm, ds)
148-
elseif dm < 600 then
149-
return ("%d:%02d:%02d"):format(em / 60, em % 60, es),
150-
("%d:%02d:%02d"):format(dm / 60, dm % 60, ds)
151-
else
152-
return ("%02d:%02d:%02d"):format(em / 60, em % 60, es),
153-
("%02d:%02d:%02d"):format(dm / 60, dm % 60, ds)
154-
end
155-
end
156-
-- }}}
157-
158139
-- {{{ Escape a string
159140
function helpers.escape(text)
160141
local xml_entities = {

widgets/mpd_all.lua

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,24 @@ local function cbool(number)
2323
end
2424
-- }}}
2525

26+
-- {{{ Format playing progress
27+
function format_progress(elapsed, duration)
28+
local em, es = elapsed / 60, elapsed % 60
29+
local dm, ds = duration / 60, duration % 60
30+
31+
if dm < 10 then
32+
return ("%d:%02d"):format(em, es), ("%d:%02d"):format(dm, ds)
33+
elseif dm < 60 then
34+
return ("%02d:%02d"):format(em, es), ("%02d:%02d"):format(dm, ds)
35+
elseif dm < 600 then
36+
return ("%d:%02d:%02d"):format(em / 60, em % 60, es),
37+
("%d:%02d:%02d"):format(dm / 60, dm % 60, ds)
38+
else
39+
return ("%02d:%02d:%02d"):format(em / 60, em % 60, es),
40+
("%02d:%02d:%02d"):format(dm / 60, dm % 60, ds)
41+
end
42+
end
43+
-- }}}
2644

2745
-- {{{ MPD widget type
2846
local function worker(format, warg)
@@ -72,7 +90,7 @@ local function worker(format, warg)
7290
f:close()
7391

7492
-- Formatted elapsed and duration
75-
mpd_state["{Elapsed}"], mpd_state["{Duration}"] = helpers.format_progress(
93+
mpd_state["{Elapsed}"], mpd_state["{Duration}"] = format_progress(
7694
mpd_state["{elapsed}"], mpd_state["{duration}"])
7795

7896
return mpd_state

0 commit comments

Comments
 (0)