Skip to content

Commit ee6e1ff

Browse files
authored
Merge pull request #3 from flintweather/fix-bug-14413
Fix Bug 14413
2 parents 68803e5 + ac0e772 commit ee6e1ff

File tree

3 files changed

+39
-16
lines changed

3 files changed

+39
-16
lines changed

Date.php

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -465,18 +465,41 @@ class Date
465465
*
466466
* @param mixed $date optional ISO 8601 date/time to initialize;
467467
* or, a Unix time stamp
468-
* @param bool $pb_countleapseconds whether to count leap seconds
468+
* @param mixed $options optional with backwards compatibility;
469+
* accept bool whether to count leap seconds
469470
* (defaults to
470-
* {@link DATE_COUNT_LEAP_SECONDS})
471+
* {@link DATE_COUNT_LEAP_SECONDS});
472+
* accept array options with default options:
473+
* 'pb_countleapseconds' to count leap seconds
474+
* (defaults to
475+
* {@link DATE_COUNT_LEAP_SECONDS});
476+
* 'format' (DATE_FORMAT_*) of the input date.
477+
* This option is not needed, except to force
478+
* the setting of the date from a Unix
479+
* time-stamp (for which use
480+
* {@link DATE_FORMAT_UNIXTIME}).
481+
* (Defaults to
482+
* {@link DATE_FORMAT_ISO}.)
471483
*
472484
* @return void
473485
* @access public
474486
* @see Date::setDate()
475487
*/
476-
function Date($date = null,
477-
$pb_countleapseconds = DATE_COUNT_LEAP_SECONDS)
488+
function Date($date = null, $options = null)
478489
{
479-
$this->ob_countleapseconds = $pb_countleapseconds;
490+
$default = array(
491+
"pb_countleapseconds" => DATE_COUNT_LEAP_SECONDS,
492+
"format" => DATE_FORMAT_ISO
493+
);
494+
if (is_null($options)) {
495+
$options = array();
496+
}
497+
if (is_bool($options)) {
498+
$options["pb_countleapseconds"] = $options;
499+
}
500+
$args = array_merge($default, $options);
501+
502+
$this->ob_countleapseconds = $args["pb_countleapseconds"];
480503

481504
if (is_a($date, 'Date')) {
482505
$this->copy($date);
@@ -485,7 +508,7 @@ function Date($date = null,
485508
// 'setDate()' expects a time zone to be already set:
486509
//
487510
$this->_setTZToDefault();
488-
$this->setDate($date);
511+
$this->setDate($date, $args["format"]);
489512
} else {
490513
$this->setNow();
491514
}

tests/bugs/bug-2378-1.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Bug #2378: Date::getDate(DATE_FORMAT_UNIXTIME) doesn't convert to GMT
66
require_once "Date.php";
77

88

9-
$date =& new Date(1095935549);
9+
$date =& new Date(1095935549, array('format' => DATE_FORMAT_UNIXTIME));
1010
echo $date->getTime()."\n";
1111
$date->convertTZbyID('America/Los_Angeles');
1212
echo $date->getTime()."\n";

tests/bugs/bug-8912.phpt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ $originalTimezone = new Date_TimeZone('Australia/Adelaide');
2525
$d = new Date("2007-08-31 11:59:59Z");
2626
$hn_time = $d->getTime();
2727
foreach ($states as $state) {
28-
$new_date = new Date($hn_time);
28+
$new_date = new Date($hn_time, array('format' => DATE_FORMAT_UNIXTIME));
2929
print 'Original Time (Australia/Adelaide): ' . $new_date->formatLikeSQL("TZH:TZM") . " " . $new_date->getTime() . "\n";
3030
$timezone = new Date_TimeZone($state);
3131
$new_date->convertTZ($timezone);
@@ -38,49 +38,49 @@ foreach ($states as $state) {
3838
}
3939
?>
4040
--EXPECT--
41-
Original Time (Australia/Adelaide): 01:00 1188561599
41+
Original Time (Australia/Adelaide): 00:00 1188561599
4242
Australia/Adelaide: 1188561599
4343
Difference: 0
4444
Australia/Adelaide: 1188561599
4545
Difference: 0
4646

47-
Original Time (Australia/Adelaide): 01:00 1188561599
47+
Original Time (Australia/Adelaide): 00:00 1188561599
4848
Australia/Canberra: 1188561599
4949
Difference: 0
5050
Australia/Canberra: 1188563399
5151
Difference: 1800
5252

53-
Original Time (Australia/Adelaide): 01:00 1188561599
53+
Original Time (Australia/Adelaide): 00:00 1188561599
5454
Australia/Darwin: 1188561599
5555
Difference: 0
5656
Australia/Darwin: 1188561599
5757
Difference: 0
5858

59-
Original Time (Australia/Adelaide): 01:00 1188561599
59+
Original Time (Australia/Adelaide): 00:00 1188561599
6060
Australia/Brisbane: 1188561599
6161
Difference: 0
6262
Australia/Brisbane: 1188563399
6363
Difference: 1800
6464

65-
Original Time (Australia/Adelaide): 01:00 1188561599
65+
Original Time (Australia/Adelaide): 00:00 1188561599
6666
Australia/Hobart: 1188561599
6767
Difference: 0
6868
Australia/Hobart: 1188563399
6969
Difference: 1800
7070

71-
Original Time (Australia/Adelaide): 01:00 1188561599
71+
Original Time (Australia/Adelaide): 00:00 1188561599
7272
Australia/Melbourne: 1188561599
7373
Difference: 0
7474
Australia/Melbourne: 1188563399
7575
Difference: 1800
7676

77-
Original Time (Australia/Adelaide): 01:00 1188561599
77+
Original Time (Australia/Adelaide): 00:00 1188561599
7878
Australia/Perth: 1188561599
7979
Difference: 0
8080
Australia/Perth: 1188556199
8181
Difference: -5400
8282

83-
Original Time (Australia/Adelaide): 01:00 1188561599
83+
Original Time (Australia/Adelaide): 00:00 1188561599
8484
Australia/Sydney: 1188561599
8585
Difference: 0
8686
Australia/Sydney: 1188563399

0 commit comments

Comments
 (0)