diff options
author | diosmosis <diosmosis@users.noreply.github.com> | 2018-07-27 00:27:18 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-27 00:27:18 +0300 |
commit | 70d1b446778909b3beda16ff4dc50fdd968d63ea (patch) | |
tree | 742ad8383621817a8b9ac2c19ba7b804d49d3912 /plugins/CoreHome/angularjs/common | |
parent | 35bd641d69235420f69da986d77437af700a6164 (diff) |
Couple more period selector related improvements (#12326)
* Changing semantics of piwik.currentDateString, making it always the value of date query param instead of that or the first date str in a range period.
* Use site timezone in getting todays date client side.
* For slightly smoother rendering, override jquery UI event handler in date-picker directive.
* Just to be comprehensive, handle yesterdaySameTime client side as well.
* Simplify additions based on existing code & reuse in scheduled reports.
Diffstat (limited to 'plugins/CoreHome/angularjs/common')
-rw-r--r-- | plugins/CoreHome/angularjs/common/services/periods.js | 16 | ||||
-rw-r--r-- | plugins/CoreHome/angularjs/common/services/piwik-api.js | 5 | ||||
-rw-r--r-- | plugins/CoreHome/angularjs/common/services/piwik.js | 15 |
3 files changed, 17 insertions, 19 deletions
diff --git a/plugins/CoreHome/angularjs/common/services/periods.js b/plugins/CoreHome/angularjs/common/services/periods.js index 487812804b..d1b50917bd 100644 --- a/plugins/CoreHome/angularjs/common/services/periods.js +++ b/plugins/CoreHome/angularjs/common/services/periods.js @@ -274,7 +274,10 @@ return getToday(); } - if (strDate === 'yesterday') { + if (strDate === 'yesterday' + // note: ignoring the 'same time' part since the frontend doesn't care about the time + || strDate === 'yesterdaySameTime' + ) { var yesterday = getToday(); yesterday.setDate(yesterday.getDate() - 1); return yesterday; @@ -290,8 +293,15 @@ } function getToday() { - var date = new Date(); - date.setHours(0); + var date = new Date(Date.now()); + + // undo browser timezone + date.setTime(date.getTime() + date.getTimezoneOffset() * 60 * 1000); + + // apply piwik site timezone (if it exists) + date.setHours((piwik.timezoneOffset || 0) / 3600); + + // get rid of minutes/seconds/etc. date.setMinutes(0); date.setSeconds(0); date.setMilliseconds(0); diff --git a/plugins/CoreHome/angularjs/common/services/piwik-api.js b/plugins/CoreHome/angularjs/common/services/piwik-api.js index 1fc9dbf8fe..54c07dc0d8 100644 --- a/plugins/CoreHome/angularjs/common/services/piwik-api.js +++ b/plugins/CoreHome/angularjs/common/services/piwik-api.js @@ -228,10 +228,7 @@ var hasBlockedContent = false; // handle default date & period if not already set if (!getParamsToMixin.date && !postParams.date) { - getParamsToMixin.date = piwik.currentDateString || piwik.broadcast.getValueFromUrl('date'); - if (getParamsToMixin.period == 'range' && piwik.currentDateString) { - getParamsToMixin.date = piwik.startDateString + ',' + getParamsToMixin.date; - } + getParamsToMixin.date = piwik.currentDateString; } return getParamsToMixin; diff --git a/plugins/CoreHome/angularjs/common/services/piwik.js b/plugins/CoreHome/angularjs/common/services/piwik.js index d6816f498f..680a44bfa4 100644 --- a/plugins/CoreHome/angularjs/common/services/piwik.js +++ b/plugins/CoreHome/angularjs/common/services/piwik.js @@ -44,22 +44,13 @@ updateDateInTitle(date, period); - // do not set anything to previous7/last7, as piwik frontend code does not - // expect those values. + // do not set anything to previousN/lastN, as it's more useful to plugins + // to have the dates than previousN/lastN. if (piwik.period === 'range') { date = piwik.startDateString + ',' + piwik.endDateString; } - if (date && date.indexOf(',') > -1) { - var dateParts = date.split(','); - if (dateParts[1]) { - piwik.currentDateString = dateParts[1]; - } else if (dateParts[0]) { - piwik.currentDateString = dateParts[0]; - } - } else { - piwik.currentDateString = date; - } + piwik.currentDateString = date; } function isValidPeriod(periodStr, dateStr) { |