Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Giehl <stefan@matomo.org>2020-12-10 05:18:07 +0300
committerGitHub <noreply@github.com>2020-12-10 05:18:07 +0300
commit7cde69f763f2cbf2b9a27c8a7dcf7bcaa950c3bd (patch)
treeda719a778d96e167ee4ba55c89a529c1c3bb0dce /plugins/CoreHome/angularjs/common
parent06918eea4d2ca01298200348b40f57817433b931 (diff)
Allow using last (week|month|year) as date param (#16830)
* Allow using last (week|month|year) as date param * Adds some unit tests * improve tests * Make it possible to use last (week|month|year) for api requests * improve test
Diffstat (limited to 'plugins/CoreHome/angularjs/common')
-rw-r--r--plugins/CoreHome/angularjs/common/services/periods.js20
1 files changed, 20 insertions, 0 deletions
diff --git a/plugins/CoreHome/angularjs/common/services/periods.js b/plugins/CoreHome/angularjs/common/services/periods.js
index 8b7283cda3..a6d3896b03 100644
--- a/plugins/CoreHome/angularjs/common/services/periods.js
+++ b/plugins/CoreHome/angularjs/common/services/periods.js
@@ -321,6 +321,8 @@
return strDate;
}
+ strDate = decodeURIComponent(strDate);
+
if (strDate === 'today'
|| strDate === 'now'
) {
@@ -336,6 +338,24 @@
return yesterday;
}
+ if (strDate.match(/last[ -]?week/i)) {
+ var lastWeek = getToday();
+ lastWeek.setDate(lastWeek.getDate() - 7);
+ return lastWeek;
+ }
+
+ if (strDate.match(/last[ -]?month/i)) {
+ var lastMonth = getToday();
+ lastMonth.setMonth(lastMonth.getMonth() - 1);
+ return lastMonth;
+ }
+
+ if (strDate.match(/last[ -]?year/i)) {
+ var lastYear = getToday();
+ lastYear.setFullYear(lastYear.getFullYear() - 1);
+ return lastYear;
+ }
+
try {
return $.datepicker.parseDate('yy-mm-dd', strDate);
} catch (err) {