Skip to content
Snippets Groups Projects
Commit ae422bb7 authored by Peter Rotich's avatar Peter Rotich
Browse files

reports: Convert user time to database time

'strtotime' uses local timezone without taking into consideration the user's
timezone. This pull requests simply makes sure user's entered timeframe
range is converted to db time before it's used in a query.
parent ef98afc6
No related branches found
No related tags found
No related merge requests found
...@@ -35,13 +35,19 @@ class OverviewReport { ...@@ -35,13 +35,19 @@ class OverviewReport {
$start = $this->start ?: 'last month'; $start = $this->start ?: 'last month';
$stop = $this->end ?: 'now'; $stop = $this->end ?: 'now';
$start = strtotime($start); // Convert user time to db time
$start = Misc::dbtime($start);
if (substr($stop, 0, 1) == '+') // Stop time can be relative.
$stop = strftime('%Y-%m-%d ', $start) . $stop; if ($stop[0] == '+') {
// $start time + time(X days)
$now = time();
$stop = $start + (strtotime($stop, $now)-$now);
} else {
$stop = Misc::dbtime($stop);
}
$start = 'FROM_UNIXTIME('.$start.')'; $start = 'FROM_UNIXTIME('.$start.')';
$stop = 'FROM_UNIXTIME('.strtotime($stop).')'; $stop = 'FROM_UNIXTIME('.$stop.')';
return array($start, $stop); return array($start, $stop);
} }
......
...@@ -18,8 +18,10 @@ $plots = $report->getPlotData(); ...@@ -18,8 +18,10 @@ $plots = $report->getPlotData();
<?php echo csrf_token(); ?> <?php echo csrf_token(); ?>
<label> <label>
<?php echo __( 'Report timeframe'); ?>: <?php echo __( 'Report timeframe'); ?>:
<input type="text" class="dp input-medium search-query" name="start" placeholder="<?php echo __('Last month');?>"i <input type="text" class="dp input-medium search-query"
value="<?php echo Format::htmlchars($_POST['start']); ?>" /> name="start" placeholder="<?php echo __('Last month');?>"i
value="<?php echo $_POST['start'] ?
Format::htmlchars($_POST['start']) : ''; ?>" />
</label> </label>
<label> <label>
<?php echo __( 'period');?>: <?php echo __( 'period');?>:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment