Skip to content

Commit 16afb73

Browse files
committed
try to show localized dates and times in reports as well
1 parent 5a0d245 commit 16afb73

File tree

3 files changed

+61
-12
lines changed

3 files changed

+61
-12
lines changed

js/src/dateformat.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,40 @@ exports.tformat = function () {
1414
exports.dtformat = function () {
1515
return dformat + ' ' + tformat;
1616
};
17+
18+
exports.mformat = function () {
19+
var sample;
20+
21+
try {
22+
sample = window.Intl ? new Intl.DateTimeFormat((document.documentElement.getAttribute("data-locale") || undefined), {
23+
numberingSystem: 'latn',
24+
calendar: 'gregory',
25+
}).format(new Date(1970, 11, 31)) : '';
26+
} catch {
27+
sample = window.Intl ? new Intl.DateTimeFormat(undefined, {
28+
numberingSystem: 'latn',
29+
calendar: 'gregory',
30+
}).format(new Date(1970, 11, 31)) : '';
31+
}
32+
33+
let mm = 0,
34+
mi = sample.indexOf(12);
35+
let dd = 1,
36+
di = sample.indexOf(31);
37+
let yy = 2,
38+
yi = sample.indexOf(1970);
39+
40+
// IE 10 or earlier, iOS 9 or earlier, non-Latin numbering system
41+
// or non-Gregorian calendar; fall back to mm/dd/yyyy
42+
if (yi >= 0 && mi >= 0 && di >= 0) {
43+
mm = (mi > yi) + (mi > di);
44+
dd = (di > yi) + (di > mi);
45+
yy = (yi > mi) + (yi > di);
46+
}
47+
48+
let r = [];
49+
r[yy] = 'YYYY';
50+
r[mm] = 'MM';
51+
52+
return r.join(sample.match(/[-.]/) || '/').replace('//','/');
53+
};

js/src/reports.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,19 @@ var dtf = require("./dateformat.js");
216216
{title:"User", field:"userUid", widthGrow:1}, //column will be allocated 1/5 of the remaining space
217217
{title:"Project", field:"project", widthGrow:1}, //column will be allocated 1/5 of the remaining space
218218
{title:"Client", field:"client", widthGrow:1}, //column will be allocated 1/5 of the remaining space
219-
{title:"When", field:"time", widthGrow:1}, //column will be allocated 1/5 of the remaining space
219+
{title:"When", field:"time", widthGrow:1,formatter:function(cell, formatterParams, onRendered){
220+
var t = cell.getValue();
221+
switch(group3) {
222+
case 'day':
223+
return moment.unix(t).format(dtf.dformat());
224+
case 'month':
225+
return moment(t).format(dtf.mformat());
226+
case '':
227+
return moment.unix(t).format(dtf.dtformat());
228+
default:
229+
return t;
230+
}
231+
}},
220232
{title:"Total Duration", field:"totalDuration",formatter:function(cell, formatterParams, onRendered){
221233
//cell - the cell component
222234
//formatterParams - parameters set for the column

lib/Db/ReportItemMapper.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,30 +56,30 @@ public function report($user, $from, $to, $filterProjectId, $filterClientId, $fi
5656
$pg = 1;
5757
if(empty($timegroup)){
5858
if (!$aggregation) {
59-
$selectFields[]= "to_char(to_timestamp(min(start))::date,'YYYY-MM-DD HH24:MI') as time";
59+
$selectFields[]= "start as time";
6060
} else {
61-
$selectFields[]= "to_timestamp(min(start))::date as time";
61+
$selectFields[]= "min(start) as time";
6262
}
6363
} elseif ($timegroup == 'week') {
64-
$selectFields[]= "to_char(to_timestamp(start)::date, 'YYYY-WW') as time";
64+
$selectFields[]= "concat(date_part(\'year\', to_timestamp(start)), 'W', to_char(to_timestamp(start), 'IW')) as time";
6565
}elseif ($timegroup == 'day') {
66-
$selectFields[]= "to_timestamp(start)::date as time";
66+
$selectFields[]= "start as time";
6767
}elseif ($timegroup == 'year') {
68-
$selectFields[]= 'date_part(\'year\', to_timestamp(start)::date) as time';
68+
$selectFields[]= 'date_part(\'year\', to_timestamp(start)) as time';
6969
}elseif ($timegroup == 'month') {
70-
$selectFields[]= "to_char(to_timestamp(start)::date, 'YYYY-MM') as time";
70+
$selectFields[]= "to_char(to_timestamp(start), 'YYYY-MM') as time";
7171
}
7272
} else {
7373
if(empty($timegroup)){
7474
if (!$aggregation) {
75-
$selectFields[]= "DATE_FORMAT(FROM_UNIXTIME(start),'%Y-%m-%d %H:%i') as time";
75+
$selectFields[]= "start as time";
7676
} else {
77-
$selectFields[]= "DATE_FORMAT(FROM_UNIXTIME(min(start)),'%Y-%m-%d') as time";
77+
$selectFields[]= "min(start) as time";
7878
}
7979
} elseif ($timegroup == 'week') {
80-
$selectFields[]= "STR_TO_DATE(CONCAT(YEARWEEK(FROM_UNIXTIME(start), 1),' Monday'), '%x%v %W') as time";
80+
$selectFields[]= "CONCAT(YEAR(FROM_UNIXTIME(start)), 'W', WEEK(FROM_UNIXTIME(start))) as time";
8181
}elseif ($timegroup == 'day') {
82-
$selectFields[]= "DATE_FORMAT(FROM_UNIXTIME(start),'%Y-%m-%d') as time";
82+
$selectFields[]= "start as time";
8383
}elseif ($timegroup == 'year') {
8484
$selectFields[]= 'YEAR(FROM_UNIXTIME(start)) as time';
8585
}elseif ($timegroup == 'month') {
@@ -249,4 +249,4 @@ public function report($user, $from, $to, $filterProjectId, $filterClientId, $fi
249249

250250

251251

252-
}
252+
}

0 commit comments

Comments
 (0)