php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67960 Long/short day names reversed in jddayofweek()
Submitted: 2014-09-04 13:34 UTC Modified: 2015-01-02 09:23 UTC
From: fisharebest at gmail dot com Assigned: tyrael (profile)
Status: Closed Package: Calendar related
PHP Version: 5.6.0 OS: All
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: fisharebest at gmail dot com
New email:
PHP Version: OS:

 

 [2014-09-04 13:34 UTC] fisharebest at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/function.jddayofweek
---

The $mode parameter is an integer (0, 1 or 2) for which
predefined constants are also available.

Numeric parameters work as per the documentation:
0 = numeric
1 = long name
2 = short name

But if the constants CAL_DOW_LONG and CAL_DOW_SHORT are used,
the wrong results are returned.  CAL_DOW_LONG gives the short
name and CAL_DOW_SHORT gives the long name.

The bug is present in all versions of PHP from 5.3 through 5.6.

Test script:
---------------
print_r(jddayofweek(1234567, 1)); // "Saturday"
print_r(jddayofweek(1234567, CAL_DOW_LONG)); // "Sat" (WRONG)
print_r(CAL_DOW_LONG); // 2

print_r(jddayofweek(1234567, 2)); // "Sat"
print_r(CAL_DOW_SHORT); // 1
print_r(jddayofweek(1234567, CAL_DOW_SHORT)); // "Saturday" (WRONG)




Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-09-04 14:07 UTC] tyrael@php.net
-Status: Open +Status: Verified
 [2014-09-04 14:07 UTC] tyrael@php.net
haha, nice catch, this seems to be wrong since the begining:
http://3v4l.org/OXRAC
the fix should be swapping the lines here:
http://lxr.php.net/xref/PHP_5_6/ext/calendar/calendar.c#699
I suppose this could also go into 5.5 as well.
 [2014-09-04 14:07 UTC] tyrael@php.net
-Assigned To: +Assigned To: tyrael
 [2014-09-04 15:29 UTC] fisharebest at gmail dot com
I think you need to:

1) reverse the order in the enum {} declaration
2) reverse the two labels in the case statement

I have a patch/tests, but can't get the latest code to build so can't test it.

I'll try again tonight when I have access to another dev machine.
 [2014-09-04 15:39 UTC] tyrael@php.net
why do you think we should change the order of declaration in the enum?
 [2014-09-04 15:53 UTC] tyrael@php.net
ah, that would keep the previous behavior for the people who are passing numeric values for the mode instead of using the constants.
 [2014-09-04 21:35 UTC] fisharebest at gmail dot com
Pull request available, with updated unit tests...

https://github.com/php/php-src/pull/806
 [2015-01-02 09:22 UTC] tyrael@php.net
-Status: Verified +Status: Closed
 [2015-01-02 09:22 UTC] tyrael@php.net
The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.


 [2015-01-02 09:23 UTC] tyrael@php.net
merged to 5.5 and upwards, will be part of the next release.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Nov 25 17:01:31 2024 UTC