/** * @covers \php_rutils\Dt::ruStrFTime */ public function testRuStrFTimeFixed() { $testData = array('d.m.Y' => '01.01.1988', 'тест D' => 'тест пт', 'тест l' => 'тест пятница', 'тест M' => 'тест янв', 'тест F' => 'тест январь', 'd M Y' => '1 янв 1988', 'd F Y' => '1 январь 1988'); $params = $this->_defaultParams; foreach ($testData as $format => $expected) { $params['format'] = $format; $strTime = $this->_object->ruStrFTime(TimeParams::create($params)); $this->assertEquals($expected, $strTime); } }
/** * Russian \DateTime::format * @param array|\php_rutils\struct\TimeParams $params Params structure * @return string Date/time string representation */ public function ruStrFTime($params = null) { //Params handle if ($params === null) { $params = new TimeParams(); } elseif (is_array($params)) { $params = TimeParams::create($params); } else { $params = clone $params; } if ($params->date === null) { $params->date = new \DateTime(); } else { $params->date = $this->_processDateTime($params->date); } if (is_string($params->timezone)) { $params->timezone = new \DateTimeZone($params->timezone); } if ($params->timezone) { $params->date->setTimezone($params->timezone); } //Format processing $weekday = $params->date->format('N') - 1; $month = $params->date->format('n') - 1; $prepos = $params->preposition ? self::$_DAY_NAMES[$weekday][3] : ''; $monthIdx = $params->monthInflected ? 2 : 1; $dayIdx = $params->dayInflected || $params->preposition ? 2 : 1; $search = array('D', 'l', 'M', 'F'); $replace = array($prepos . self::$_DAY_NAMES[$weekday][0], $prepos . self::$_DAY_NAMES[$weekday][$dayIdx], self::$_MONTH_NAMES[$month][0], self::$_MONTH_NAMES[$month][$monthIdx]); //for russian typography standard, //1 April 2007, but 01.04.2007 if (strpos($params->format, 'F') !== false || strpos($params->format, 'M') !== false) { $search[] = 'd'; $replace[] = 'j'; } $params->format = str_replace($search, $replace, $params->format); //Create date/time string return $params->date->format($params->format); }