Bug 125656
Summary: | PHP Date Functions not working properly | ||
---|---|---|---|
Product: | [Fedora] Fedora | Reporter: | Robert Frew <robert.frew> |
Component: | php | Assignee: | Joe Orton <jorton> |
Status: | CLOSED WONTFIX | QA Contact: | David Lawrence <dkl> |
Severity: | medium | Docs Contact: | |
Priority: | medium | ||
Version: | 1 | CC: | dgunchev, redhat-bugzilla |
Target Milestone: | --- | ||
Target Release: | --- | ||
Hardware: | i386 | ||
OS: | Linux | ||
URL: | http://www.swingular.com/timetest.php | ||
Whiteboard: | |||
Fixed In Version: | Doc Type: | Bug Fix | |
Doc Text: | Story Points: | --- | |
Clone Of: | Environment: | ||
Last Closed: | 2005-06-21 15:47:07 UTC | Type: | --- |
Regression: | --- | Mount Type: | --- |
Documentation: | --- | CRM: | |
Verified Versions: | Category: | --- | |
oVirt Team: | --- | RHEL 7.3 requirements from Atomic Host: | |
Cloudforms Team: | --- | Target Upstream Version: | |
Embargoed: |
Description
Robert Frew
2004-06-09 19:13:17 UTC
Correction: Just updated my Fedora Core 1 to the latest releases using Yum. My website is a dating site that relies on the date functions heavily for converting timestamps to ages and vice versa. Up until the latest update, everything worked correctly (for 2 plus years). I did nothing to the code or system except for the update. Now, when converting a timestamp using the date() function for any date beyond the month of june (year doesn't matter), it converts it to a day earlier than what it actually is. See the example at the included URL. But if converting a date from january to june, it converts correctly. Also, if I try to get the age using a timestamp for a birthday of june 9, 1974 and todays date is june 9th, it shows the correct age of 30. But if my birthday is june 11, 1974, it still says my age is 30. Please confirm the version of PHP in use: $ rpm -q php php-4.3.6-1.3 I found a new age converting function that seems to convert the age correctly now but the date() function still has an error. function GetAge($dob) { $date_of_birth = date("Ymd", $dob); $now = date("Ymd", time()); $age = (int) (($now - $date_of_birth)/10000); return $age; } Ok, supposedly, Redhat versions since 7.3 do not support negative timestamps in glibc. This prompted me to use a library that takes over negative timestamp conversions. I'm assuming the timestamp of 0 equals 12/31/1969. Prior to the update, I think the timestamp of 0 may have been 01/01/1970. Using the library that was basing 0 off the latter, the calculations were one day off. I found an updated library that calculates the negative timestamps correctly and this seems to have fixed the problem. You can get this library here: http://php.weblogs.com/adodb_date_time_library I can't reproduce the original problem you reported here: <?php date("m/d/Y", 156146400); //shows 12/12/1974. ?> what $TZ do you have? Maybe try something like this: $ echo '<?php print date("m/d/Y U", 156146400) . "\n"; ?>' | TZ=GMT php -q Namesake, I'm able to reproduce the same problem using php 4.3.8, my timezone is CEST for this example: --- snipp --- 3. The following code converts a timestamp to an age: Age: 30 <-- Wrong, should be 29 Age without Floor 30.112983479198 Date: 06/11/1974 --- snapp --- But Joe's example works, if the TZ is set to GMT... --- snipp --- # echo '<?php print date("m/d/Y U", 156146400) . "\n"; ?>' | TZ=GMT php -q 12/13/1974 156146400 # --- snapp --- ...so I think it's a PHP timezone problem?! [This is a mass bug update] Fedora Core 1 is now maintained by the Fedora Legacy project for security updates only. If this problem is a security issue, please reopen and reassign to the Fedora Legacy product. If it is not a security issue and hasn't been resolved in the current FC3 or FC4 updates, reopen and change the version to match. |