mirror of
https://github.com/Piwigo/Piwigo.git
synced 2025-04-28 12:19:57 +03:00
feature 2807: nicer display of "from to" dates (required changes in "format_date" function)
git-svn-id: http://piwigo.org/svn/trunk@28981 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
parent
fb4237b786
commit
8a1ea2ad0a
4 changed files with 67 additions and 30 deletions
|
@ -283,7 +283,7 @@ while ($user_row = pwg_db_fetch_assoc($result))
|
|||
|
||||
$intro_vars = array(
|
||||
'file' => l10n('Original file : %s', $row['file']),
|
||||
'add_date' => l10n('Posted %s on %s', time_since($row['date_available'], 'year'), format_date($row['date_available'], false, false)),
|
||||
'add_date' => l10n('Posted %s on %s', time_since($row['date_available'], 'year'), format_date($row['date_available'], array('day', 'month', 'year'))),
|
||||
'added_by' => l10n('Added by %s', $row['added_by']),
|
||||
'size' => $row['width'].'×'.$row['height'].' pixels, '.sprintf('%.2f', $row['filesize']/1024).'MB',
|
||||
'stats' => l10n('Visited %d times', $row['hit']),
|
||||
|
|
|
@ -336,24 +336,10 @@ if (count($categories) > 0)
|
|||
|
||||
if (!empty($from))
|
||||
{
|
||||
$info = '';
|
||||
|
||||
if (date('Y-m-d', strtotime($from)) == date('Y-m-d', strtotime($to)))
|
||||
{
|
||||
$info = format_date($from);
|
||||
}
|
||||
else
|
||||
{
|
||||
$info = l10n(
|
||||
'from %s to %s',
|
||||
format_date($from),
|
||||
format_date($to)
|
||||
);
|
||||
}
|
||||
$tpl_var['INFO_DATES'] = $info;
|
||||
$tpl_var['INFO_DATES'] = format_fromto($from, $to);
|
||||
}
|
||||
}
|
||||
}
|
||||
}//fromto
|
||||
|
||||
$tpl_thumbnails_var[] = $tpl_var;
|
||||
}
|
||||
|
|
|
@ -550,6 +550,11 @@ function str2DateTime($original, $format=null)
|
|||
return false;
|
||||
}
|
||||
|
||||
if ($original instanceof DateTime)
|
||||
{
|
||||
return $original;
|
||||
}
|
||||
|
||||
if (!empty($format) && version_compare(PHP_VERSION, '5.3.0') >= 0)// from known date format
|
||||
{
|
||||
return DateTime::createFromFormat('!'.$format, $original); // ! char to reset fields to UNIX epoch
|
||||
|
@ -588,12 +593,12 @@ function str2DateTime($original, $format=null)
|
|||
* returns a formatted and localized date for display
|
||||
*
|
||||
* @param int|string timestamp or datetime string
|
||||
* @param bool $show_time
|
||||
* @param bool $show_day_name
|
||||
* @param array $show list of components displayed, default is ['day_name', 'day', 'month', 'year']
|
||||
* THIS PARAMETER IS PLANNED TO CHANGE
|
||||
* @param string $format input format respecting date() syntax
|
||||
* @return string
|
||||
*/
|
||||
function format_date($original, $show_time=false, $show_day_name=true, $format=null)
|
||||
function format_date($original, $show=null, $format=null)
|
||||
{
|
||||
global $lang;
|
||||
|
||||
|
@ -604,28 +609,74 @@ function format_date($original, $show_time=false, $show_day_name=true, $format=n
|
|||
return l10n('N/A');
|
||||
}
|
||||
|
||||
$print = '';
|
||||
if ($show_day_name)
|
||||
if ($show === null)
|
||||
{
|
||||
$print.= $lang['day'][ $date->format('w') ].' ';
|
||||
$show = array('day_name', 'day', 'month', 'year');
|
||||
}
|
||||
|
||||
$print.= $date->format('j');
|
||||
$print.= ' '.$lang['month'][ $date->format('n') ];
|
||||
$print.= ' '.$date->format('Y');
|
||||
// TODO use IntlDateFormatter for proper i18n
|
||||
|
||||
if ($show_time)
|
||||
$print = '';
|
||||
if (in_array('day_name', $show))
|
||||
$print.= $lang['day'][ $date->format('w') ].' ';
|
||||
|
||||
if (in_array('day', $show))
|
||||
$print.= $date->format('j').' ';
|
||||
|
||||
if (in_array('month', $show))
|
||||
$print.= $lang['month'][ $date->format('n') ].' ';
|
||||
|
||||
if (in_array('year', $show))
|
||||
$print.= $date->format('Y').' ';
|
||||
|
||||
if (in_array('time', $show))
|
||||
{
|
||||
$temp = $date->format('H:i');
|
||||
if ($temp != '00:00')
|
||||
{
|
||||
$print.= ' '.$temp;
|
||||
$print.= $temp.' ';
|
||||
}
|
||||
}
|
||||
|
||||
return trim($print);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a "From ... to ..." string from two dates
|
||||
* @param string $from
|
||||
* @param string $to
|
||||
* @param boolean $full
|
||||
* @return string
|
||||
*/
|
||||
function format_fromto($from, $to, $full=false)
|
||||
{
|
||||
$from = str2DateTime($from);
|
||||
$to = str2DateTime($to);
|
||||
|
||||
if ($from->format('Y-m-d') == $to->format('Y-m-d'))
|
||||
{
|
||||
return format_date($from);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($full || $from->format('Y') != $to->format('Y'))
|
||||
{
|
||||
$from_str = format_date($from);
|
||||
}
|
||||
else if ($from->format('m') != $to->format('m'))
|
||||
{
|
||||
$from_str = format_date($from, array('day_name', 'day', 'month'));
|
||||
}
|
||||
else
|
||||
{
|
||||
$from_str = format_date($from, array('day_name', 'day'));
|
||||
}
|
||||
$to_str = format_date($to);
|
||||
|
||||
return l10n('from %s to %s', $from_str, $to_str);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Works out the time since the given date
|
||||
*
|
||||
|
|
|
@ -196,7 +196,7 @@ SELECT user_id, group_id
|
|||
{
|
||||
foreach ($users as $cur_user)
|
||||
{
|
||||
$users[$cur_user['id']]['registration_date_string'] = format_date($cur_user['registration_date'], false, false);
|
||||
$users[$cur_user['id']]['registration_date_string'] = format_date($cur_user['registration_date'], array('day', 'month', 'year'));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -240,7 +240,7 @@ SELECT
|
|||
|
||||
if (isset($params['display']['last_visit_string']))
|
||||
{
|
||||
$users[ $row['user_id'] ]['last_visit_string'] = format_date($last_visit, false, false);
|
||||
$users[ $row['user_id'] ]['last_visit_string'] = format_date($last_visit, array('day', 'month', 'year'));
|
||||
}
|
||||
|
||||
if (isset($params['display']['last_visit_since']))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue