Tools\Utility\Time::monthName PHP Method

monthName() public static method

Return the translation to a specific week day
public static monthName ( integer $month, boolean $abbr = false, array $options = [] ) : string
$month integer 1..12
$abbr boolean (if abbreviation should be returned)
$options array - appendDot (only for 3 letter abbr; defaults to false)
return string translatedText
    public static function monthName($month, $abbr = false, array $options = [])
    {
        $months = ['long' => ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'], 'short' => ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']];
        $month = (int) ($month - 1);
        if (!$abbr) {
            return __d('tools', $months['long'][$month]);
        }
        $monthName = __d('tools', $months['short'][$month]);
        if (!empty($options['appendDot']) && strlen(__d('tools', $months['long'][$month])) > 3) {
            $monthName .= '.';
        }
        return $monthName;
    }

Usage Example

コード例 #1
0
ファイル: TimeTest.php プロジェクト: alescx/cakephp-tools
 /**
  * TimeTest::testMonth()
  *
  * @return void
  */
 public function testMonthName()
 {
     //$this->out($this->_header(__FUNCTION__), true);
     $ret = $this->Time->monthName('11');
     $this->assertEquals(__d('tools', 'November'), $ret);
     $ret = $this->Time->monthName(1);
     $this->assertEquals(__d('tools', 'January'), $ret);
     $ret = $this->Time->monthName(2, true, ['appendDot' => true]);
     $this->assertEquals(__d('tools', 'Feb') . '.', $ret);
     $ret = $this->Time->monthName(5, true, ['appendDot' => true]);
     $this->assertEquals(__d('tools', 'May'), $ret);
 }