(0006687)
matthiasblaesing
04-22-16 12:07
|
Ok - attaching files fails - so here the patch and reproducer:
------- test.php: ----------
<?php
$rollover = mktime(30, 0, 0, 4, 21, 2016);
print(strftime("mktime(30, 0, 0, 4, 21, 2016) => Should be: 2016-04-22 06:00:00 -- %Y-%m-%d %H:%M:%S", $rollover));
print("\n");
$rollover = mktime(-1, 0, 0, 4, 21, 2016);
print(strftime("mktime(-1, 0, 0, 4, 21, 2016) => Should be: 2016-04-20 23:00:00 -- %Y-%m-%d %H:%M:%S", $rollover));
print("\n");
------- Broken (current): ----------
matthias@athena:~/src/quercus$ java -jar /home/matthias/src/quercus/dist/quercus-with-dependencies.jar test.php
mktime(30, 0, 0, 4, 21, 2016) => Should be: 2016-04-22 06:00:00 -- 2016-04-21 06:00:00
mktime(-1, 0, 0, 4, 21, 2016) => Should be: 2016-04-20 23:00:00 -- 2016-04-21 23:00:00
matthias@athena:~/src/quercus$
------- Patch: ----------
diff --git a/modules/quercus/src/com/caucho/quercus/lib/date/DateModule.java b/modules/quercus/src/com/caucho/quercus/lib/date/DateModule.java
index 49c1ec4..41e58df 100644
--- a/modules/quercus/src/com/caucho/quercus/lib/date/DateModule.java
+++ b/modules/quercus/src/com/caucho/quercus/lib/date/DateModule.java
@@ -925,6 +925,35 @@
Value dayV,
Value yearV)
{
+ if (! yearV.isDefault()) {
+ int year = yearV.toInt();
+
+ if (year >= 1000) {
+ date.setYear(year);
+ }
+ else if (year >= 70) {
+ date.setYear(year + 1900);
+ }
+ else if (year >= 0) {
+ date.setYear(year + 2000);
+ }
+ else if (year < 0) {
+ date.setYear(1969);
+ }
+ }
+
+ if (! monthV.isDefault()) {
+ int month = monthV.toInt();
+
+ date.setMonth(month - 1);
+ }
+
+ if (! dayV.isDefault()) {
+ int day = dayV.toInt();
+
+ date.setDayOfMonth(day);
+ }
+
if (! hourV.isDefault()) {
int hour = hourV.toInt();
@@ -941,35 +970,6 @@
int second = secondV.toInt();
date.setSecond(second);
- }
-
- if (! monthV.isDefault()) {
- int month = monthV.toInt();
-
- date.setMonth(month - 1);
- }
-
- if (! dayV.isDefault()) {
- int day = dayV.toInt();
-
- date.setDayOfMonth(day);
- }
-
- if (! yearV.isDefault()) {
- int year = yearV.toInt();
-
- if (year >= 1000) {
- date.setYear(year);
- }
- else if (year >= 70) {
- date.setYear(year + 1900);
- }
- else if (year >= 0) {
- date.setYear(year + 2000);
- }
- else if (year < 0) {
- date.setYear(1969);
- }
}
}
------- Result: ----------
matthias@athena:~/src/quercus$ java -jar /home/matthias/src/quercus/dist/quercus-with-dependencies.jar test.php
mktime(30, 0, 0, 4, 21, 2016) => Should be: 2016-04-22 06:00:00 -- 2016-04-22 06:00:00
mktime(-1, 0, 0, 4, 21, 2016) => Should be: 2016-04-20 23:00:00 -- 2016-04-20 23:00:00
matthias@athena:~/src/quercus$ |