Edit report at https://bugs.php.net/bug.php?id=64681&edit=1
ID: 64681 Updated by: a...@php.net Reported by: Uwe at Familie-Loyal dot de Summary: Fix Win / Linux problems with strftime -Status: Open +Status: Feedback Type: Bug Package: *Web Server problem Operating System: Win32 PHP Version: Irrelevant Block user comment: N Private report: N New Comment: Could you please be more specific about the issue you're trying to report? Is it possible to reduce your snippet to the essential small part and to state how it's expected to work and which error you get? Thanks. Previous Comments: ------------------------------------------------------------------------ [2013-04-20 06:56:40] Uwe at Familie-Loyal dot de Description: ------------ --- >From manual page: http://www.php.net/function.strftime --- I develope an function to fix Problems/bug of strftime in Windows (XAMPP). Test script: --------------- function strftime_win32($format, $ts = null) { if (!$ts) $ts = time(); $mapping = array( '%C' => sprintf("%02d", date("Y", $ts) / 100), '%D' => '%m/%d/%y', '%e' => sprintf("%' 2d", date("j", $ts)), '%h' => '%b', '%n' => "\n", '%r' => date("h:i:s", $ts) . " %p", '%R' => date("H:i", $ts), '%t' => "\t", '%T' => '%H:%M:%S', '%u' => ($w = date("w", $ts)) ? $w : 7 ); $format = str_replace( array_keys($mapping), array_values($mapping), $format ); if($format=='%V' or $format=='%G' or $format=='%g'){ // When strftime("%V") fails, some unoptimized workaround // // http://en.wikipedia.org/wiki/ISO_8601 : week 1 is "the week with the year's first Thursday in it (the formal ISO definition)" $year = strftime("%Y", $ts); $isoyear=$year; $first_day = strftime("%w", mktime(0, 0, 0, 1, 1, $year)); $last_day = strftime("%w", mktime(0, 0, 0, 12, 31, $year)); $number = $isonumber = strftime("%W", $ts); // According to strftime("%W"), 1st of january is in week 1 if and only if it is a monday if ($first_day == 1) { $isonumber--; } // 1st of january is between monday and thursday; starting (now) at 0 when it should be 1 if ($first_day >= 1 && $first_day <= 4){ $isonumber++; $isoyear=$year; }elseif ($number == 0){ $isonumber = mktime(0, 0, 0, 12, 31, $year - 1); $isoyear=$year; } if ($isonumber == 53 && ($last_day == 1 || $last_day == 2 || $last_day == 3)){ $isonumber = 1; $isoyear=$year+1; } if ($format=='%V') { return sprintf("%02d", $isonumber); }elseif ($format=='%G'){ return sprintf("%04d", $isoyear); }elseif ($format=='%g'){ return substr(sprintf("%04d", $isoyear),-2); } }else{ return strftime($format, $ts); } } ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=64681&edit=1