improved support for the american date/time formats

This commit is contained in:
Ralf Becker 2006-06-20 19:55:06 +00:00
parent a018b89b84
commit 28e9219017
2 changed files with 49 additions and 12 deletions

View File

@ -1197,11 +1197,12 @@ class bocal
* Formats one or two dates (range) as long date (full monthname), optionaly with a time
*
* @param mixed $first first date
* @param mixed $last last date if != 0 (default)
* @param boolean $display_time should a time be displayed too
* @param mixed $last=0 last date if != 0 (default)
* @param boolean $display_time=false should a time be displayed too
* @param boolean $display_day=false should a day-name prefix the date, eg. monday June 20, 2006
* @return string with formated date
*/
function long_date($first,$last=0,$display_time=false)
function long_date($first,$last=0,$display_time=false,$display_day=false)
{
$first = $this->date2array($first);
if ($last)
@ -1214,6 +1215,10 @@ class bocal
$month_before_day = strtolower($datefmt[0]) == 'm' ||
strtolower($datefmt[2]) == 'm' && $datefmt[4] == 'd';
if ($display_day)
{
$range = lang(adodb_date('l',$first['raw'])).($this->common_prefs['dateformat']{0} != 'd' ? ' ' : ', ');
}
for ($i = 0; $i < 5; $i += 2)
{
switch($datefmt[$i])
@ -1265,7 +1270,10 @@ class bocal
$range .= ' '.lang(strftime('%B',$month_before_day ? $first['raw'] : $last['raw'])) . ' ';
break;
case 'Y':
$range .= ($datefmt[0] == 'm' ? ', ' : ' ') . ($datefmt[0] == 'Y' ? $first['year'].($datefmt[2] == 'd' ? ', ' : ' ') : $last['year'].' ');
if ($datefmt[0] != 'm')
{
$range .= ' ' . ($datefmt[0] == 'Y' ? $first['year'].($datefmt[2] == 'd' ? ', ' : ' ') : $last['year'].' ');
}
break;
}
}
@ -1273,8 +1281,40 @@ class bocal
{
$range .= ' '.adodb_date($timefmt,$last['raw']);
}
if ($datefmt[4] == 'Y' && $datefmt[0] == 'm')
{
$range .= ', ' . $last['year'];
}
return $range;
}
/**
* Displays a timespan, eg. $both ? "10:00 - 13:00: 3h" (10:00 am - 1 pm: 3h) : "10:00 3h" (10:00 am 3h)
*
* @param int $start_m start time in minutes since 0h
* @param int $end_m end time in minutes since 0h
* @param boolean $both=false display the end-time too, duration is always displayed
*/
function timespan($start_m,$end_m,$both=false)
{
$duration = $end_m - $start_m;
if ($end_m == 24*60-1) ++$duration;
$duration = floor($duration/60).lang('h').($duration%60 ? $duration%60 : '');
$timespan = $t = $GLOBALS['egw']->common->formattime(sprintf('%02d',$start_m/60),sprintf('%02d',$start_m%60));
if ($both) // end-time too
{
$timespan .= ' - '.$GLOBALS['egw']->common->formattime(sprintf('%02d',$end_m/60),sprintf('%02d',$end_m%60));
// dont double am/pm if they are the same in both times
if ($this->common_prefs['timeformat'] == 12 && substr($timespan,-2) == substr($t,-2))
{
$timespan = str_replace($t,substr($t,0,-3),$timespan);
}
$timespan .= ':';
}
return $timespan . ' ' . $duration;
}
/**
* Converts a participant into a (readable) user- or resource-name

View File

@ -440,7 +440,7 @@ class uiviews extends uical
if ($this->debug > 0) $this->bo->debug_message('uiviews::day() date=%1',True,$this->date);
$this->last = $this->first = $this->bo->date2ts((string)$this->date);
$GLOBALS['egw_info']['flags']['app_header'] .= ': '.lang(adodb_date('l',$this->first)).', '.$this->bo->long_date($this->first);
$GLOBALS['egw_info']['flags']['app_header'] .= ': '.$this->bo->long_date($this->first,0,false,true);
$this->use_time_grid = true; // day-view always uses a time-grid, independent what's set in the prefs!
@ -832,7 +832,8 @@ class uiviews extends uical
// Creation of the header-column with date, evtl. holiday-names and a matching background-color
$ts = $this->bo->date2ts((string)$day_ymd);
$title = is_bool($short_title) ? (lang(adodb_date('l',$ts)).', '.($short_title ? adodb_date('d.',$ts) : $this->bo->long_date($ts))) : $short_title;
$title = !is_bool($short_title) ? $short_title :
($short_title ? lang(adodb_date('l',$ts)).' '.adodb_date('d.',$ts) : $this->bo->long_date($ts,0,false,true));
$day_view = array(
'menuaction' => 'calendar.uiviews.day',
'date' => $day_ymd,
@ -994,11 +995,7 @@ class uiviews extends uical
}
else
{
$mins = $event['end_m'] - $event['start_m'];
if ($event['end_m'] == 24*60-1) ++$mins;
$timespan = $timespan2 = $GLOBALS['egw']->common->formattime(sprintf('%02d',$event['start_m']/60),sprintf('%02d',$event['start_m']%60)).
' '.floor($mins/60).lang('h').($mins%60 ? $mins%60 : '');
$timespan2 = str_replace(' ',' - '.$GLOBALS['egw']->common->formattime(sprintf('%02d',$event['end_m']/60),sprintf('%02d',$event['end_m']%60)).': ',$timespan);
$timespan = $this->bo->timespan($event['start_m'],$event['end_m']);
}
$is_private = !$this->bo->check_perms(EGW_ACL_READ,$event);
@ -1052,7 +1049,7 @@ class uiviews extends uical
'description' => !$is_private ? nl2br($this->html->htmlspecialchars($event['description'])) : '',
'location' => !$is_private ? $this->add_nonempty($event['location'],lang('Location')) : '',
'participants' => $participants,
'times' => !$event['multiday'] ? $this->add_nonempty($timespan2,lang('Time')) :
'times' => !$event['multiday'] ? $this->add_nonempty($this->bo->timespan($event['start_m'],$event['end_m'],true),lang('Time')) :
$this->add_nonempty($this->bo->format_date($event['start']),lang('Start')).
$this->add_nonempty($this->bo->format_date($event['end']),lang('End')),
'multidaytimes' => !$event['multiday'] ? '' :