Bug #64681 [Fbk->NoF]: Fix Win / Linux problems with strftime
| From: | php-bugs at lists dot php dot net | Date: | Tue, 15 Oct 2013 11:54:42 +0000 |
| Subject: | Bug #64681 [Fbk->NoF]: Fix Win / Linux problems with strftime | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-182238@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=64681&edit=1
ID: 64681
Updated by: php-bugs@lists.php.net
Reported by: Uwe at Familie-Loyal dot de
Summary: Fix Win / Linux problems with strftime
-Status: Feedback
+Status: No Feedback
Type: Bug
Package: *Web Server problem
Operating System: Win32
PHP Version: Irrelevant
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2013-04-20 09:25:47] 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 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