Fixed daylight saving change error using new egw_time class:

At the date when the change occured - yesterday ;-) - starttimes where
wrong by one hour, because difference of timestamp of daystart and
current time was one hour more (because of the switch)
This commit is contained in:
Ralf Becker 2009-10-26 08:17:06 +00:00
parent 6d3bf02d1c
commit 8d2194f191
4 changed files with 41 additions and 195 deletions

View File

@ -50,19 +50,6 @@ class timesheet_bo extends so_sql_cf
var $timestamps = array(
'ts_start','ts_modified'
);
/**
* Offset in secconds between user and server-time, it need to be add to a server-time to get the user-time
* or substracted from a user-time to get the server-time
*
* @var int
*/
var $tz_offset_s;
/**
* Current time as timestamp in user-time
*
* @var int
*/
var $now;
/**
* Start of today in user-time
*
@ -127,15 +114,17 @@ class timesheet_bo extends so_sql_cf
* Array with substatus of label configuration
*/
var $status_labels_substatus = array();
/**
* Name of the timesheet table storing custom fields
*/
var $historylog;
/**
* Instance of the timesheet_tracking object
*
* @var timesheet_tracking
*/
var $tracking;
/**
* Translates field / acl-names to labels
*
* @var array
*/
var $field2label = array(
'ts_project' => 'Project',
'ts_title' => 'Title',
@ -154,21 +143,13 @@ class timesheet_bo extends so_sql_cf
'customfields' => 'Custom fields',
);
/**
* Translates field / acl-names to labels
* setting field-name from DB to history status
*
* @var array
*/
var $field2history = array();
/**
* setting field-name from DB to history status
*
* @var array
*/
var $tracking;
/**
* Names of all config vars
*
* @var array
* Name of the timesheet table storing custom fields
*/
const EXTRA_TABLE = 'egw_timesheet_extra';
@ -220,8 +201,6 @@ class timesheet_bo extends so_sql_cf
}
}
}
$this->tz_offset_s = $GLOBALS['egw']->datetime->tz_offset;
$this->now = time() + $this->tz_offset_s; // time() is server-time and we need a user-time
$this->today = mktime(0,0,0,date('m',$this->now),date('d',$this->now),date('Y',$this->now));
// save us in $GLOBALS['timesheet_bo'] for ExecMethod used in hooks
@ -232,9 +211,8 @@ class timesheet_bo extends so_sql_cf
$this->grants = $GLOBALS['egw']->acl->get_grants(TIMESHEET_APP);
//set fields for tracking
$this->field2history = array_keys($this->db_cols);
$this->field2history = array_diff(array_combine($this->field2history,$this->field2history),
array('ts_modified'));
$this->field2history = $this->field2history +array('customfields' => '#c'); //add custom fields for history
$this->field2history = array_diff(array_combine($this->field2history,$this->field2history),array('ts_modified'));
$this->field2history += array('customfields' => '#c'); //add custom fields for history
}
/**
@ -616,50 +594,6 @@ class timesheet_bo extends so_sql_cf
return $ret;
}
/**
* changes the data from the db-format to your work-format
*
* reimplemented to adjust the timezone of the timestamps (adding $this->tz_offset_s to get user-time)
* Please note, we do NOT call the method of the parent so_sql !!!
*
* @param array $data if given works on that array and returns result, else works on internal data-array
* @return array with changed data
*/
function db2data($data=null)
{
if (!is_array($data))
{
$data = &$this->data;
}
foreach($this->timestamps as $name)
{
if (isset($data[$name]) && $data[$name]) $data[$name] += $this->tz_offset_s;
}
return $data;
}
/**
* changes the data from your work-format to the db-format
*
* reimplemented to adjust the timezone of the timestamps (subtraction $this->tz_offset_s to get server-time)
* Please note, we do NOT call the method of the parent so_sql !!!
*
* @param array $data if given works on that array and returns result, else works on internal data-array
* @return array with changed data
*/
function data2db($data=null)
{
if ($intern = !is_array($data))
{
$data = &$this->data;
}
foreach($this->timestamps as $name)
{
if (isset($data[$name]) && $data[$name]) $data[$name] -= $this->tz_offset_s;
}
return $data;
}
/**
* Get the time- and pricesum for the given timesheet entries
*
@ -807,6 +741,4 @@ class timesheet_bo extends so_sql_cf
}
return array();
}
}

View File

@ -78,7 +78,7 @@ class timesheet_ui extends timesheet_bo
{
$this->data = array(
'ts_start' => $this->today,
'end_time' => $this->now - $this->today,
'end_time' => egw_time::to($this->now,'H:i'),
'ts_owner' => $GLOBALS['egw_info']['user']['account_id'],
'cat_id' => (int) $_REQUEST['cat_id'],
);
@ -98,7 +98,6 @@ class timesheet_ui extends timesheet_bo
else
{
//echo "<p>ts_start=$content[ts_start], start_time=$content[start_time], end_time=$content[end_time], ts_duration=$content[ts_duration], ts_quantity=$content[ts_quantity]</p>\n";
// we only need 2 out of 3 values from start-, end-time or duration (the date in ts_start is always required!)
if (!isset($GLOBALS['egw_info']['user']['apps']['admin']) && $content['ts_status'])
{
if ($this->status_labels_config[$content['ts_status']]['admin'])
@ -109,17 +108,30 @@ class timesheet_ui extends timesheet_bo
}
}
if ($content['start_time']) // start-time specified
// we only need 2 out of 3 values from start-, end-time or duration (the date in ts_start is always required!)
if ($content['start_time'] != '00:00') // start-time specified
{
$content['ts_start'] += $content['start_time'];
//$content['ts_start'] += $content['start_time'];
$start = new egw_time($content['ts_start']);
$start_time = explode(':',$content['start_time']);
$start->setTime($start_time[0],$start_time[1]);
$content['ts_start'] = $start->format('ts');
}
if ($content['end_time'] && $content['start_time']) // start- & end-time --> calculate the duration
if ($content['end_time'] != '00:00') // end-time specified
{
$content['ts_duration'] = ($content['end_time'] - $content['start_time']) / 60;
$end = new egw_time($content['ts_start']);
$end_time = explode(':',$content['end_time']);
$end->setTime($end_time[0],$end_time[1]);
}
elseif ($content['ts_duration'] && $content['end_time']) // no start, calculate from end and duration
if ($end && $start) // start- & end-time --> calculate the duration
{
$content['ts_start'] += $content['end_time'] - 60*$content['ts_duration'];
$content['ts_duration'] = ($end->format('ts') - $start->format('ts')) / 60;
//echo "<p>end_time=$content[end_time], start_time=$content[start_time] --> duration=$content[ts_duration]</p>\n";
}
elseif ($content['ts_duration'] && $end) // no start, calculate from end and duration
{
$content['ts_start'] = $end->format('ts') - 60*$content['ts_duration'];
//echo "<p>end_time=$content[end_time], duration=$content[ts_duration] --> ts_start=$content[ts_start]=".egw_time::to($content['ts_start'])."</p>\n";
}
if ($content['ts_duration'] > 0) unset($content['end_time']);
// now we only deal with start (date+time) and duration
@ -262,7 +274,7 @@ class timesheet_ui extends timesheet_bo
),
'js' => "<script>\n$js\n</script>\n",
'ts_quantity_blur' => $this->data['ts_duration'] ? round($this->data['ts_duration'] / 60.0,3) : '',
'start_time' => $this->datetime2time($this->data['ts_start']),
'start_time' => egw_time::to($this->data['ts_start'],'H:i'),
'pm_integration' => $this->pm_integration,
'ts_status' => ($preserv['ts_status'] !='')? $preserv['ts_status'] : $GLOBALS['egw_info']['user']['preferences']['timesheet']['predefined_status'],
));

File diff suppressed because one or more lines are too long

View File

@ -1,8 +1,8 @@
<?xml version="1.0"?>
<!-- $Id$ -->
<overlay>
<template id="timesheet.edit.general" template="" lang="" group="0" version="1.7.001">
<grid width="100%" height="250" overflow="auto">
<template id="timesheet.edit.general" template="" lang="" group="0" version="1.7.002">
<grid width="100%" height="150">
<columns>
<column width="95"/>
<column width="120"/>
@ -32,13 +32,13 @@
<description options=",,,ts_start" value="Date"/>
<date id="ts_start" needed="1" options=",8"/>
<description value="Starttime"/>
<date-timeonly id="start_time"/>
<date-timeonly id="start_time" options="H:i"/>
</row>
<row class="row">
<description options=",,,ts_duration" value="Duration"/>
<date-duration id="ts_duration" options=",hm"/>
<description value="or endtime" class="noWrap"/>
<date-timeonly id="end_time"/>
<date-timeonly id="end_time" options="H:i"/>
</row>
<row class="row" disabled="@ts_viewtype">
<description options=",,,ts_quantity" value="Quantity"/>
@ -56,7 +56,7 @@
</grid>
</template>
<template id="timesheet.edit.notes" template="" lang="" group="0" version="1.5.001">
<grid width="100%" height="450" overflow="auto">
<grid width="100%" height="150">
<columns>
<column/>
</columns>
@ -68,7 +68,7 @@
</grid>
</template>
<template id="timesheet.edit.links" template="" lang="" group="0" version="0.1.001">
<grid width="100%" height="150">
<grid width="100%" height="150" overflow="auto">
<columns>
<column width="100"/>
<column/>
@ -90,7 +90,7 @@
</grid>
</template>
<template id="timesheet.edit.customfields" template="" lang="" group="0" version="1.5.001">
<grid width="100%" height="150">
<grid width="100%" height="150" overflow="auto">
<columns>
<column/>
</columns>