gui: Allow to translate and fix incorrect Versions date filter ranges (#8162)

* gui: Allow to translate and fix incorrect Versions date filter ranges

Translate the previously English-only ranges used in Versions date
filter. In the process, fix the currently incorrect range calculation.

For instance, let us say it is 08:05. Selecting "today" should set the
range to start at 00:00 and end at 08:05. However, what really happens
is that both start and end are set to 08:05, and as a result "today" is
never shown to the user. The case is the same for "yesterday", which in
contrary to "today" is shown, but its range is fixed at 08:05 on the
previous day.

This commit fixes the above by always calculating "today" starting at
00:00 up to the current moment, and calculating "yesterday" from 00:00
on the previous to 00:00 on the current day.

When it comes to "last x days", the commit fixes the calculation so that
it actually covers the whole day, which is done by moving the start date
to 00:00 on the first day.

Signed-off-by: Tomasz Wilczyński <twilczynski@naver.com>
This commit is contained in:
tomasz1986
2022-02-07 21:41:05 +01:00
committed by GitHub
parent 1c74944cca
commit 2738735321
2 changed files with 17 additions and 9 deletions
@@ -2599,15 +2599,14 @@ angular.module('syncthing.core')
$scope.restoreVersions.filters['start'] = minDate;
$scope.restoreVersions.filters['end'] = maxDate;
var ranges = {
'All time': [minDate, maxDate],
'Today': [moment(), moment()],
'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
'Last 7 Days': [moment().subtract(6, 'days'), moment()],
'Last 30 Days': [moment().subtract(29, 'days'), moment()],
'This Month': [moment().startOf('month'), moment().endOf('month')],
'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
};
var ranges = {};
ranges[$translate.instant("All Time")] = [minDate, maxDate];
ranges[$translate.instant("Today")] = [moment().startOf('day'), moment()];
ranges[$translate.instant("Yesterday")] = [moment().subtract(1, 'days').startOf('day'), moment().startOf('day')];
ranges[$translate.instant("Last 7 Days")] = [moment().subtract(6, 'days').startOf('day'), moment()];
ranges[$translate.instant("Last 30 Days")] = [moment().subtract(29, 'days').startOf('day'), moment()];
ranges[$translate.instant("This Month")] = [moment().startOf('month'), moment()];
ranges[$translate.instant("Last Month")] = [moment().subtract(1, 'month').startOf('month'), moment().startOf('month')];
// Filter out invalid ranges.
$.each(ranges, function (key, range) {
@@ -2628,6 +2627,7 @@ angular.module('syncthing.core')
maxDate: maxDate,
ranges: ranges,
locale: {
customRangeLabel: $translate.instant("Custom Range"),
format: 'YYYY/MM/DD HH:mm:ss',
}
}).on('apply.daterangepicker', function (ev, picker) {