Automatically exported from code.google.com/p/planningalerts
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

modifier.date_format.php 1.5 KiB

18 anni fa
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * Smarty plugin
  4. * @package Smarty
  5. * @subpackage plugins
  6. */
  7. /**
  8. * Include the {@link shared.make_timestamp.php} plugin
  9. */
  10. require_once $smarty->_get_plugin_filepath('shared','make_timestamp');
  11. /**
  12. * Smarty date_format modifier plugin
  13. *
  14. * Type: modifier<br>
  15. * Name: date_format<br>
  16. * Purpose: format datestamps via strftime<br>
  17. * Input:<br>
  18. * - string: input date string
  19. * - format: strftime format for output
  20. * - default_date: default date if $string is empty
  21. * @link http://smarty.php.net/manual/en/language.modifier.date.format.php
  22. * date_format (Smarty online manual)
  23. * @author Monte Ohrt <monte at ohrt dot com>
  24. * @param string
  25. * @param string
  26. * @param string
  27. * @return string|void
  28. * @uses smarty_make_timestamp()
  29. */
  30. function smarty_modifier_date_format($string, $format="%b %e, %Y", $default_date=null)
  31. {
  32. if (substr(PHP_OS,0,3) == 'WIN') {
  33. $hours = strftime('%I', $string);
  34. $short_hours = ( $hours < 10 ) ? substr( $hours, -1) : $hours;
  35. $_win_from = array ('%e', '%T', '%D', '%l');
  36. $_win_to = array ('%#d', '%H:%M:%S', '%m/%d/%y', $short_hours);
  37. $format = str_replace($_win_from, $_win_to, $format);
  38. }
  39. if($string != '') {
  40. return strftime($format, smarty_make_timestamp($string));
  41. } elseif (isset($default_date) && $default_date != '') {
  42. return strftime($format, smarty_make_timestamp($default_date));
  43. } else {
  44. return;
  45. }
  46. }
  47. /* vim: set expandtab: */
  48. ?>