php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64681 Fix Win / Linux problems with strftime
Submitted: 2013-04-20 06:56 UTC Modified: 2013-10-15 11:54 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: Uwe at Familie-Loyal dot de Assigned:
Status: No Feedback Package: *Web Server problem
PHP Version: Irrelevant OS: Win32
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: Uwe at Familie-Loyal dot de
New email:
PHP Version: OS:

 

 [2013-04-20 06:56 UTC] 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); 
                } 
        } 




Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-04-20 09:25 UTC] ab@php.net
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.
 [2013-04-20 09:25 UTC] ab@php.net
-Status: Open +Status: Feedback
 [2013-10-15 11:54 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 09:01:28 2024 UTC