diff options
Diffstat (limited to '')
-rw-r--r-- | admin/picture_modify.php | 2 | ||||
-rw-r--r-- | include/category_cats.inc.php | 18 | ||||
-rw-r--r-- | include/functions.inc.php | 73 | ||||
-rw-r--r-- | include/ws_functions/pwg.users.php | 4 |
4 files changed, 67 insertions, 30 deletions
diff --git a/admin/picture_modify.php b/admin/picture_modify.php index 57d98276a..0c7910357 100644 --- a/admin/picture_modify.php +++ b/admin/picture_modify.php @@ -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']), diff --git a/include/category_cats.inc.php b/include/category_cats.inc.php index 2e90a9441..4cab63d27 100644 --- a/include/category_cats.inc.php +++ b/include/category_cats.inc.php @@ -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; } diff --git a/include/functions.inc.php b/include/functions.inc.php index 65c248cf6..cc6dae20c 100644 --- a/include/functions.inc.php +++ b/include/functions.inc.php @@ -549,6 +549,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 { @@ -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,22 +609,32 @@ 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 + + $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 ($show_time) + 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.' '; } } @@ -627,6 +642,42 @@ function format_date($original, $show_time=false, $show_day_name=true, $format=n } /** + * 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 * * @param int|string timestamp or datetime string diff --git a/include/ws_functions/pwg.users.php b/include/ws_functions/pwg.users.php index d3c676df1..e007dd111 100644 --- a/include/ws_functions/pwg.users.php +++ b/include/ws_functions/pwg.users.php @@ -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'])) |