From:             Uwe at Familie-Loyal dot de
Operating system: Win32
PHP version:      Irrelevant
Package:          *Web Server problem
Bug Type:         Bug
Bug description:Fix Win / Linux problems with strftime

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 bug report at https://bugs.php.net/bug.php?id=64681&edit=1
-- 
Try a snapshot (PHP 5.4):   
https://bugs.php.net/fix.php?id=64681&r=trysnapshot54
Try a snapshot (PHP 5.3):   
https://bugs.php.net/fix.php?id=64681&r=trysnapshot53
Try a snapshot (trunk):     
https://bugs.php.net/fix.php?id=64681&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=64681&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=64681&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=64681&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=64681&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=64681&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=64681&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=64681&r=notwrong
Not enough info:            
https://bugs.php.net/fix.php?id=64681&r=notenoughinfo
Submitted twice:            
https://bugs.php.net/fix.php?id=64681&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=64681&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=64681&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=64681&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=64681&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=64681&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=64681&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=64681&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=64681&r=mysqlcfg

Reply via email to