/** * Sets the pattern to format against. The default patterns * are retrieved from the sfNumberFormatInfo instance. * * @param string $pattern the requested patterns. * @return string a number format pattern. */ protected function setPattern($pattern) { switch ($pattern) { case 'c': case 'C': $this->formatInfo->setPattern(sfNumberFormatInfo::CURRENCY); break; case 'd': case 'D': $this->formatInfo->setPattern(sfNumberFormatInfo::DECIMAL); break; case 'e': case 'E': $this->formatInfo->setPattern(sfNumberFormatInfo::SCIENTIFIC); break; case 'p': case 'P': $this->formatInfo->setPattern(sfNumberFormatInfo::PERCENTAGE); break; default: $this->formatInfo->setPattern($pattern); break; } }
/** * Get the era. i.e. in gregorian, year > 0 is AD, else BC. * @todo How to support multiple Eras?, e.g. Japanese. * @param array getdate format. * @param string a pattern. * @return string era */ protected function getEra($date, $pattern = 'G') { if ($pattern != 'G') { throw new Exception('The pattern for era is "G".'); } $year = $date['year']; if ($year > 0) { return $this->formatInfo->getEra(1); } else { return $this->formatInfo->getEra(0); } }
function testGetInstance() { $format = DateTimeFormatInfo::getInstance('zh_CN'); $pattern = 'yyyy-M-d'; $this->assertEqual($pattern, $format->MediumDatePattern); }