Changeset 28981 for trunk


Ignore:
Timestamp:
Jul 7, 2014, 11:54:15 AM (10 years ago)
Author:
mistic100
Message:

feature 2807: nicer display of "from to" dates (required changes in "format_date" function)

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/picture_modify.php

    r28678 r28981  
    284284$intro_vars = array(
    285285  'file' => l10n('Original file : %s', $row['file']),
    286   'add_date' => l10n('Posted %s on %s', time_since($row['date_available'], 'year'), format_date($row['date_available'], false, false)),
     286  'add_date' => l10n('Posted %s on %s', time_since($row['date_available'], 'year'), format_date($row['date_available'], array('day', 'month', 'year'))),
    287287  'added_by' => l10n('Added by %s', $row['added_by']),
    288288  'size' => $row['width'].'×'.$row['height'].' pixels, '.sprintf('%.2f', $row['filesize']/1024).'MB',
  • trunk/include/category_cats.inc.php

    r28587 r28981  
    337337        if (!empty($from))
    338338        {
    339           $info = '';
    340 
    341           if (date('Y-m-d', strtotime($from)) == date('Y-m-d', strtotime($to)))
    342           {
    343             $info = format_date($from);
    344           }
    345           else
    346           {
    347             $info = l10n(
    348               'from %s to %s',
    349               format_date($from),
    350               format_date($to)
    351               );
    352           }
    353           $tpl_var['INFO_DATES'] = $info;
     339          $tpl_var['INFO_DATES'] = format_fromto($from, $to);
    354340        }
    355341      }
    356     }//fromto
     342    }
    357343
    358344    $tpl_thumbnails_var[] = $tpl_var;
  • trunk/include/functions.inc.php

    r28914 r28981  
    550550    return false;
    551551  }
     552 
     553  if ($original instanceof DateTime)
     554  {
     555    return $original;
     556  }
    552557
    553558  if (!empty($format) && version_compare(PHP_VERSION, '5.3.0') >= 0)// from known date format
     
    589594 *
    590595 * @param int|string timestamp or datetime string
    591  * @param bool $show_time
    592  * @param bool $show_day_name
     596 * @param array $show list of components displayed, default is ['day_name', 'day', 'month', 'year']
     597 *    THIS PARAMETER IS PLANNED TO CHANGE
    593598 * @param string $format input format respecting date() syntax
    594599 * @return string
    595600 */
    596 function format_date($original, $show_time=false, $show_day_name=true, $format=null)
     601function format_date($original, $show=null, $format=null)
    597602{
    598603  global $lang;
     
    605610  }
    606611
     612  if ($show === null)
     613  {
     614    $show = array('day_name', 'day', 'month', 'year');
     615  }
     616
     617  // TODO use IntlDateFormatter for proper i18n
     618
    607619  $print = '';
    608   if ($show_day_name)
    609   {
     620  if (in_array('day_name', $show))
    610621    $print.= $lang['day'][ $date->format('w') ].' ';
    611   }
    612 
    613   $print.= $date->format('j');
    614   $print.= ' '.$lang['month'][ $date->format('n') ];
    615   $print.= ' '.$date->format('Y');
    616 
    617   if ($show_time)
     622
     623  if (in_array('day', $show))
     624    $print.= $date->format('j').' ';
     625
     626  if (in_array('month', $show))
     627    $print.= $lang['month'][ $date->format('n') ].' ';
     628
     629  if (in_array('year', $show))
     630    $print.= $date->format('Y').' ';
     631
     632  if (in_array('time', $show))
    618633  {
    619634    $temp = $date->format('H:i');
    620635    if ($temp != '00:00')
    621636    {
    622       $print.= ' '.$temp;
     637      $print.= $temp.' ';
    623638    }
    624639  }
    625640
    626641  return trim($print);
     642}
     643
     644/**
     645 * Format a "From ... to ..." string from two dates
     646 * @param string $from
     647 * @param string $to
     648 * @param boolean $full
     649 * @return string
     650 */
     651function format_fromto($from, $to, $full=false)
     652{
     653  $from = str2DateTime($from);
     654  $to = str2DateTime($to);
     655
     656  if ($from->format('Y-m-d') == $to->format('Y-m-d'))
     657  {
     658    return format_date($from);
     659  }
     660  else
     661  {
     662    if ($full || $from->format('Y') != $to->format('Y'))
     663    {
     664      $from_str = format_date($from);
     665    }
     666    else if ($from->format('m') != $to->format('m'))
     667    {
     668      $from_str = format_date($from, array('day_name', 'day', 'month'));
     669    }
     670    else
     671    {
     672      $from_str = format_date($from, array('day_name', 'day'));
     673    }
     674    $to_str = format_date($to);
     675
     676    return l10n('from %s to %s', $from_str, $to_str);
     677  }
    627678}
    628679
  • trunk/include/ws_functions/pwg.users.php

    r27811 r28981  
    197197      foreach ($users as $cur_user)
    198198      {
    199         $users[$cur_user['id']]['registration_date_string'] = format_date($cur_user['registration_date'], false, false);
     199        $users[$cur_user['id']]['registration_date_string'] = format_date($cur_user['registration_date'], array('day', 'month', 'year'));
    200200      }
    201201    }
     
    241241        if (isset($params['display']['last_visit_string']))
    242242        {
    243           $users[ $row['user_id'] ]['last_visit_string'] = format_date($last_visit, false, false);
     243          $users[ $row['user_id'] ]['last_visit_string'] = format_date($last_visit, array('day', 'month', 'year'));
    244244        }
    245245       
Note: See TracChangeset for help on using the changeset viewer.