예제 #1
0
    private function formatMonths(\IntlDateFormatter $formatter, array $months)
    {
        $pattern = $formatter->getPattern();
        $timezone = $formatter->getTimezoneId();

        $formatter->setTimezoneId(\DateTimeZone::UTC);

        if (preg_match('/M+/', $pattern, $matches)) {
            $formatter->setPattern($matches[0]);

            foreach ($months as $key => $value) {
                $months[$key] = $formatter->format(gmmktime(0, 0, 0, $key, 15));
            }

            // I'd like to clone the formatter above, but then we get a
            // segmentation fault, so let's restore the old state instead
            $formatter->setPattern($pattern);
        }

        $formatter->setTimezoneId($timezone);

        return $months;
    }
 private function formatTimestamps(\IntlDateFormatter $formatter, $regex, array $timestamps)
 {
     $pattern = $formatter->getPattern();
     $timezone = $formatter->getTimezoneId();
     $formatter->setTimezoneId(\DateTimeZone::UTC);
     if (preg_match($regex, $pattern, $matches)) {
         $formatter->setPattern($matches[0]);
         foreach ($timestamps as $key => $timestamp) {
             $timestamps[$key] = $formatter->format($timestamp);
         }
         // I'd like to clone the formatter above, but then we get a
         // segmentation fault, so let's restore the old state instead
         $formatter->setPattern($pattern);
     }
     $formatter->setTimezoneId($timezone);
     return $timestamps;
 }