Skip to content

Commit d4c8aad

Browse files
committed
zero-pad hours, minutes and seconds in the time Timelines and Reports views
closes mtierltd#54
1 parent 3b5f97d commit d4c8aad

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

js/reports.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@
158158

159159
function getReport(){
160160
var baseUrl = OC.generateUrl('/apps/timetracker/ajax/report?name=&from='+start.unix()+'&to='+end.unix()+'&group1='+group1+'&group2='+group2+'&timegroup='+group3+'&filterProjectId='+filterProjectId+'&filterClientId='+filterClientId);
161+
function pad(n, width, z) {
162+
z = z || '0';
163+
n = n + '';
164+
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
165+
}
161166
var table = new Tabulator("#report", {
162167
ajaxURL:baseUrl,
163168
layout:"fitColumns",
@@ -179,7 +184,7 @@
179184
var m = Math.floor( (duration/60) % 60 );
180185
var h = Math.floor( (duration/(60*60)));
181186

182-
return h + ':' + m + ':' + s;
187+
return pad(h,2) + ':' + pad(m,2) + ':' + pad(s,2);
183188

184189
},bottomCalc:"sum", bottomCalcParams:{
185190
precision:1,
@@ -192,7 +197,7 @@
192197
var m = Math.floor( (duration/60) % 60 );
193198
var h = Math.floor( (duration/(60*60)));
194199

195-
return h + ':' + m + ':' + s;
200+
return pad(h,2) + ':' + pad(m,2) + ':' + pad(s,2);
196201

197202
}}, //column will be allocated 1/5 of the remaining space
198203
],

js/timelines.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,11 @@
173173

174174
function getReport(){
175175
var baseUrl = OC.generateUrl('/apps/timetracker/ajax/report?name=&from='+start.unix()+'&to='+end.unix()+'&group1='+group1+'&group2='+group2+'&timegroup='+group3+'&filterProjectId='+filterProjectId+'&filterClientId='+filterClientId);
176+
function pad(n, width, z) {
177+
z = z || '0';
178+
n = n + '';
179+
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
180+
}
176181
var table = new Tabulator("#report", {
177182
ajaxURL:baseUrl,
178183
layout:"fitColumns",
@@ -193,7 +198,7 @@
193198
var m = Math.floor( (duration/60) % 60 );
194199
var h = Math.floor( (duration/(60*60)));
195200

196-
return h + ':' + m + ':' + s;
201+
return pad(h,2) + ':' + pad(m,2) + ':' + pad(s,2);
197202

198203
},}, //column will be allocated 1/5 of the remaining space
199204
],
@@ -322,4 +327,4 @@
322327

323328

324329
} );
325-
}());
330+
}());

0 commit comments

Comments
 (0)