? ? ? Success

User tests: Successful: Unsuccessful:

avatar SharkyKZ
SharkyKZ
5 Oct 2020

Summary of Changes

Removes use of strtotime() in favor of string comparison for dates.

Testing Instructions

Use 32-bit version of PHP 8.0.0 RC1 or newer dev build.
Create an article. Don't set Finish Publishing date.
View article list/blog/featured view containing the article in frontend.
View the article in frontend.

Actual result BEFORE applying this Pull Request

Warning: strtotime(): Epoch doesn't fit in a PHP integer

Expected result AFTER applying this Pull Request

No warnings.

Documentation Changes Required

No.

avatar SharkyKZ SharkyKZ - open - 5 Oct 2020
avatar SharkyKZ SharkyKZ - change - 5 Oct 2020
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 5 Oct 2020
Category Front End com_content Layout Templates (site)
avatar richard67
richard67 - comment - 11 Oct 2020

Unfortunately I don't have the required testing environment, 32-bit version of PHP 8.0.0 RC1 or newer dev build.

But from code review it's absolutely clear what this PR does, and it makes sense, first check for the null date and then to a strtotime for the other check, and not vice versa.

@HLeithner What do you think? Would you count a good code review as a good test, too?

avatar infograf768
infograf768 - comment - 11 Oct 2020

@SharkyKZ
Can you also fix it here

<?php if (strtotime($item->publish_up) > strtotime(Factory::getDate())) : ?>
<div>
<span class="list-published badge badge-warning">
<?php echo Text::_('JNOTPUBLISHEDYET'); ?>
</span>
</div>
<?php endif; ?>
<?php if (!is_null($item->publish_down) && strtotime($item->publish_down) < strtotime(Factory::getDate())) : ?>
<div>
<span class="list-published badge badge-warning">
<?php echo Text::_('JEXPIRED'); ?>
</span>
</div
<?php endif; ?>

avatar SharkyKZ
SharkyKZ - comment - 11 Oct 2020

@infograf768 Will do. But I'm starting to question the validity of this fix. It has a limited range:

The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 UTC to Tue, 19 Jan 2038 03:14:07 UTC. (These are the dates that correspond to the minimum and maximum values for a 32-bit signed integer.)

I guess we should account for values outside this range?

avatar infograf768
infograf768 - comment - 11 Oct 2020

I was born after 1901 and 2038 would mean I would be 90. Can't project so far. ;)
But this says that anyway code will have to be modified in 2038.
https://www.unixtimestamp.com/ (unix starts in 1970 btw)

https://en.wikipedia.org/wiki/Year_2038_problem

avatar SharkyKZ
SharkyKZ - comment - 12 Oct 2020

Do we even need strtotime() here? Looks like we could be comparing date strings instead.

avatar richard67
richard67 - comment - 12 Oct 2020

Do we even need strtotime() here? Looks like we could be comparing date strings instead.

@SharkyKZ Where do you mean? For the greater than or lower than comparisons we can only use strings if we can 100% be sure that they are in ISO format.

avatar SharkyKZ
SharkyKZ - comment - 13 Oct 2020

Dates returned from the databases should always be the same format, right?

avatar richard67
richard67 - comment - 13 Oct 2020

@SharkyKZ Yes, but the question is not if it is the same format always but if this format means that alphabetical sorting is equal to sorting by date and time, and this is not given for a format like e.g. "DD.MM.YYYY hh:nn:ss". Alphabetical sorting is only equal to sorting by date and time if the order of the time periods "year, month, day ... seconds" is either ascending or descending with the length of these periods, and if the number of digits used for each period is always the same, i.e. it will not work when using only 1 digit for months 1 to 9.

So the ISO formats (short or long) fulfil this, they go from year down to second: "YYYY-MM-DD hh:mm:ss".

It would theoretically also work with "ss:mm:hh DD-MM-YYYY", but nobody really uses that.

So if you can be 100% sure that the string representation is always the same ISO format, then you can compare strings like times.

But if not, then you have to force this format.

avatar SharkyKZ
SharkyKZ - comment - 13 Oct 2020

But dates from the database are always going to be in YYYY-MM-DD hh:mm:ss (or Y-m-d H:i:s in PHP terms) format across all supported databases and locales?

avatar richard67
richard67 - comment - 13 Oct 2020

But dates from the database are always going to be in YYYY-MM-DD hh:mm:ss (or Y-m-d H:i:s in PHP terms) format across all supported databases and locales?

@SharkyKZ Exactly that's what I'm not 100% sure about. At least on MS SQL Server it might be different.

avatar richard67
richard67 - comment - 13 Oct 2020

@SharkyKZ I'd stay with the strtotime to play safe.

avatar SharkyKZ
SharkyKZ - comment - 27 Oct 2020

We can't use strtotime() because of the limitations. And we do only support Y-m-d H:i:s format for database dates. Database API can support different formats but this doesn't concern the CMS.

avatar SharkyKZ SharkyKZ - change - 27 Oct 2020
The description was changed
avatar SharkyKZ SharkyKZ - edited - 27 Oct 2020
avatar SharkyKZ SharkyKZ - change - 27 Oct 2020
The description was changed
avatar SharkyKZ SharkyKZ - edited - 27 Oct 2020
avatar infograf768
infograf768 - comment - 27 Oct 2020
avatar SharkyKZ
SharkyKZ - comment - 27 Oct 2020

I'll do that later. It's for 4.0 anyways. There's also same issue in calendar field on 4.0.

avatar roland-d
roland-d - comment - 21 Nov 2020

Like Richard I don have a 32-bit environment either, who does 🤔 However code review looks good.

avatar HLeithner
HLeithner - comment - 21 Nov 2020

@roland-d can you test on a 64bit system?

avatar bayareajenn
bayareajenn - comment - 21 Nov 2020

also @roland-d will you see if Patch Tester gives you this PR in PHP8? :)

avatar bayareajenn bayareajenn - test_item - 4 Dec 2020 - Tested successfully
avatar bayareajenn
bayareajenn - comment - 4 Dec 2020

I have tested this item ✅ successfully on bbcb7bf

I tested on 64 bit PHP8. Added article. Added cat blog, cat list, single article, featured on the frontend. No errors. Couldn't find it broke anything.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/30921.

avatar gostn gostn - test_item - 5 Dec 2020 - Tested successfully
avatar gostn
gostn - comment - 5 Dec 2020

I have tested this item ✅ successfully on bbcb7bf


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/30921.

avatar richard67
richard67 - comment - 5 Dec 2020

@gostn Which PHP version did you use? 8? If so: 32 or 64 bit?

avatar gostn
gostn - comment - 5 Dec 2020

ups i forgot i'm a troll #30716 (comment)

avatar HLeithner
HLeithner - comment - 5 Dec 2020

ups i forgot i'm a troll #30716 (comment)

not sure what you mean with this but in this case it's important to know which version you tested. (I mean it's always a useful information)

avatar gostn
gostn - comment - 5 Dec 2020

if you read the comment you wll understand that asking by one who call you a troll is …

avatar HLeithner
HLeithner - comment - 5 Dec 2020

ok @gostn but still no answer for the version

avatar richard67
richard67 - comment - 5 Dec 2020

Exactly this behaviour was what I've meant.

avatar gostn
gostn - comment - 6 Dec 2020

ok @gostn but still no answer for the version

as long as i´m called a troll and no apologize for that …

avatar richard67 richard67 - change - 7 Dec 2020
Status Pending Ready to Commit
avatar richard67
richard67 - comment - 7 Dec 2020

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/30921.

avatar HLeithner HLeithner - close - 7 Dec 2020
avatar HLeithner HLeithner - merge - 7 Dec 2020
avatar HLeithner HLeithner - change - 7 Dec 2020
Status Ready to Commit Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2020-12-07 16:06:32
Closed_By HLeithner
Labels Added: ?
avatar HLeithner
HLeithner - comment - 7 Dec 2020

Thanks

Add a Comment

Login with GitHub to post a comment