Changeset 28981 for trunk/include/functions.inc.php
- Timestamp:
- Jul 7, 2014, 11:54:15 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/functions.inc.php
r28914 r28981 550 550 return false; 551 551 } 552 553 if ($original instanceof DateTime) 554 { 555 return $original; 556 } 552 557 553 558 if (!empty($format) && version_compare(PHP_VERSION, '5.3.0') >= 0)// from known date format … … 589 594 * 590 595 * @param int|string timestamp or datetime string 591 * @param bool $show_time592 * @param bool $show_day_name596 * @param array $show list of components displayed, default is ['day_name', 'day', 'month', 'year'] 597 * THIS PARAMETER IS PLANNED TO CHANGE 593 598 * @param string $format input format respecting date() syntax 594 599 * @return string 595 600 */ 596 function format_date($original, $show _time=false, $show_day_name=true, $format=null)601 function format_date($original, $show=null, $format=null) 597 602 { 598 603 global $lang; … … 605 610 } 606 611 612 if ($show === null) 613 { 614 $show = array('day_name', 'day', 'month', 'year'); 615 } 616 617 // TODO use IntlDateFormatter for proper i18n 618 607 619 $print = ''; 608 if ($show_day_name) 609 { 620 if (in_array('day_name', $show)) 610 621 $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)) 618 633 { 619 634 $temp = $date->format('H:i'); 620 635 if ($temp != '00:00') 621 636 { 622 $print.= ' '.$temp;637 $print.= $temp.' '; 623 638 } 624 639 } 625 640 626 641 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 */ 651 function 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 } 627 678 } 628 679
Note: See TracChangeset
for help on using the changeset viewer.