User tests: Successful: Unsuccessful:
If you call JDate->format and no timezone is set, you'll get the error:
Warning: DateTime::setTimezone() expects parameter 1 to be DateTimeZone, null given‏
Hi
What code we need to run in order to seeing the error? Look at JDate class, I see $gmt property is already initialized in contructor https://github.com/joomla/joomla-cms/blob/staging/libraries/joomla/date/date.php#L84, so I don't know when it is empty and cause the warning?
Labels |
Added:
?
|
Category | ⇒ | Libraries |
Status | New | ⇒ | Pending |
Hello,
don't ask me why, but the PHP class "DatePeriod" delivers a JDate object when you use the Traversable property (=> foreach ($dateperiod ...)) and the first parameter (http://php.net/manual/en/dateperiod.construct.php) is a JDate object. If you try to use ->format(...), the JDate method will be used and then this error appears...
Hi
As I mentioned before, the self::$gmt is initialized when a JDate object is created, so I don't know in what case it is empty. Could you provide sample code which we can run to prove this error?
Status | Pending | ⇒ | Information Required |
After several months without further reply to the request for further information this issue is being closed. It can always be re-opened
Status | Information Required | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2015-07-19 17:59:24 |
Closed_By | ⇒ | brianteeman |
I can confirm issue, use this gist code
You will see something like this:
object(JDate)#341 (4) { ["tz":protected]=> NULL ["date"]=> string(26) "2015-10-08 10:00:26.000000" ["timezone_type"]=> int(2) ["timezone"]=> string(3) "GMT" }
Warning: DateTime::setTimezone() expects parameter 1 to be DateTimeZone, null given in pathwww/libraries/joomla/date/date.php on line 321
Edit: added a fix without need to change core code (eg: JDate class); see comments in gist.
Thank you - sorry that I did not post the code which caused the warning for me, it is too much. Could you please test with bembelimen's patch? It worked for me also when I updated to 3.4.4 and solves the problem for me.
@test patch fix the notice
object(JDate)#324 (4) { ["tz":protected]=> NULL ["date"]=> string(26) "2015-10-08 08:30:00.000000" ["timezone_type"]=> int(2) ["timezone"]=> string(3) "GMT" }
Warning: DateTime::setTimezone() expects parameter 1 to be DateTimeZone, null given in pathwww/libraries/joomla/date/date.php on line 321
object(JDate)#324 (4) { ["tz":protected]=> NULL ["date"]=> string(26) "2015-10-08 08:30:00.000000" ["timezone_type"]=> int(2) ["timezone"]=> string(3) "GMT" }
Just want to point out, after patch tz can be null, did this really good?
Status | Closed | ⇒ | New |
Closed_Date | 2015-07-19 17:59:24 | ⇒ | |
Closed_By | brianteeman | ⇒ |
@chmst see that to a workaround: how JHtml date handle date
-> set timezone based on user config or general config
@Devportobello - thank you! I'll try this.
It works. I put the example code of the gist code and write it in index.php of the template. After saving I got [Warning: DateTime::setTimezone() expects parameter 1 to be DateTimeZone] and after patch the warning disappears.
Restarted Travis build to see if tests pass (I expect them to pass). Looks fine from review.
Milestone |
Added: |
I have tested this item successfully on bc71688
Tested with the provided instructions / code - workes as described.
Status | New | ⇒ | Ready to Commit |
Thanks. --> RTC for 3.4.6
Labels |
Added:
?
|
Travis don't fails on this PR is fails on different
Status | Ready to Commit | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2015-10-27 21:03:38 |
Closed_By | ⇒ | rdeutz |
Labels |
Removed:
?
|
Milestone |
Milestone |
Added: |
Milestone |
Added: |
Milestone |
@test successful and thank you, bembelimen! Before the patch I got "Warning: DateTime::setTimezone() expects parameter 1 to be DateTimeZone, null given" when using the DatePeriod in my component.
After applying the patch, the Warning disappeared