Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#11 2020-06-08 15:24:34

gaekwad
Admin
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 2,989

Re: strftime unix %s doesn't works on localhost

I’m building out a full strftime testing scaffold for posted, should be ready in 15 mins.

Offline

#12 2020-06-08 15:32:47

gaekwad
Admin
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 2,989

Re: strftime unix %s doesn't works on localhost

Basic strftime testing output for posted, I’ll tabulate it and edit:

*time()*
|_. PHP |_. Output |
| @<txp:php>echo time();</txp:php>@ | <txp:php>echo time();</txp:php> |

*Day*
|_. Format |_. Description |_. Output |
| @%a@ | An abbreviated textual representation of the day | <txp:posted format="%a" /> |
| @%A@ | A full textual representation of the day | <txp:posted format="%A" /> |
| @%d@ | Two-digit day of the month (with leading zeros) | <txp:posted format="%d" /> |
| @%e@ | Day of the month, with a space preceding single digits. | <txp:posted format="%e" /> |
| @%j@ | Day of the year, 3 digits with leading zeros | <txp:posted format="%j" /> |
| @%u@ | ISO-8601 numeric representation of the day of the week | <txp:posted format="%u" /> |
| @%w@ | Numeric representation of the day of the week | <txp:posted format="%w" /> |

*Week*
|_. Format |_. Description |_. Output |
| @%U@ | Week number of the given year, starting with the first Sunday as the first week | <txp:posted format="%U" /> |
| @%V@ | ISO-8601:1988 week number of the given year, starting with the first week of the year with at least 4 weekdays, with Monday being the start of the week | <txp:posted format="%V" /> |
| @%W@ | A numeric representation of the week of the year, starting with the first Monday as the first week | <txp:posted format="%W" /> |

*Month*
|_. Format |_. Description |_. Output |
| @%b@ | Abbreviated month name, based on the locale | <txp:posted format="%b" /> |
| @%B@ | Full month name, based on the locale | <txp:posted format="%B" /> |
| @%h@ | Abbreviated month name, based on the locale (an alias of %b) | <txp:posted format="%h" /> |
| @%m@ | Two digit representation of the month | <txp:posted format="%m" /> |

*Year*
|_. Format |_. Description |_. Output |
| @%c@ | Two digit representation of the century (year divided by 100, truncated to an integer) | <txp:posted format="%c" /> |
| @%g@ |  Two digit representation of the year going by ISO-8601:1988 standards (see %V) | <txp:posted format="%g" /> |
| @%G@ | The full four-digit version of %g | <txp:posted format="%G" /> |
| @%y@ | Two digit representation of the year | <txp:posted format="%y" /> |
| @%Y@ | Four digit representation for the year | <txp:posted format="%Y" /> |

*Time*
|_. Format |_. Description |_. Output |
| @%H@ | Two digit representation of the hour in 24-hour format | <txp:posted format="%H" /> |
| @%k@ | Hour in 24-hour format, with a space preceding single digits | <txp:posted format="%k" /> |
| @%I@ | Two digit representation of the hour in 12-hour format | <txp:posted format="%I" /> |
| @%l@ | Hour in 12-hour format, with a space preceding single digits | <txp:posted format="%l" /> |
| @%M@ | Two digit representation of the minute | <txp:posted format="%M" /> |
| @%p@ | UPPER-CASE 'AM' or 'PM' based on the given time | <txp:posted format="%p" /> |
| @%P@ | lower-case 'am' or 'pm' based on the given time | <txp:posted format="%P" /> |
| @%r@ | Same as "%I:%M:%S %p" | <txp:posted format="%r" /> |
| @%R@ | Same as "%H:%M" | <txp:posted format="%R" /> |
| @%S@ | Two digit representation of the second | <txp:posted format="%S" /> |
| @%T@ | Same as "%H:%M:%S" | <txp:posted format="%T" /> |
| @%X@ | Preferred time representation based on locale, without the date | <txp:posted format="%X" /> |
| @%z@ | The time zone offset. | <txp:posted format="%z" /> |
| @%Z@ | The time zone abbreviation. | <txp:posted format="%Z" /> |

*Time and Date Stamps*
|_. Format |_. Description |_. Output |
| @%c@ | Preferred date and time stamp based on locale | <txp:posted format="%c" /> |
| @%D@: | Same as "%m/%d/%y" |<txp:posted format="%D" /> |
| @%F@ | Same as "%Y-%m-%d" (commonly used in database datestamps) | <txp:posted format="%F" /> |
| @%s@ | Unix Epoch Time timestamp (same as the time() function) | <txp:posted format="%s" /> |
| @%x@ | Preferred date representation based on locale, without the time | <txp:posted format="%x" /> |

Last edited by gaekwad (2020-06-08 15:55:07)

Offline

#13 2020-06-08 15:49:41

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 9,469
Website

Re: strftime unix %s doesn't works on localhost

Thanks for the tabulation, Pete.

This is crazy.

On any article page/form under a MySQL 8 environment:

<txp:php>
echo strftime('%s', 1591628404);
</txp:php>

EXPECTED: 1591628404
ACTUAL: -1

That’s a direct PHP function call, not even going through any of our tag code. If you use any other format than %s, it works fine and converts it.

Question is: why?

EDIT: being purist about it, asking strftime() to return the unix timestamp and passing in the unix timestamp is pretty useless. We already know it, as we’re passing it in! So, worst case scenario is we detect %s as a format string and just return the direct article timestamp + timezone offset.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#14 2020-06-08 15:54:36

gaekwad
Admin
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 2,989

Re: strftime unix %s doesn't works on localhost

Running this…:

<txp:php>echo time();</txp:php>

…returns the epoch (expected). I can switch one or more of the demo servers to PHP 7.3, any good?

Offline

#15 2020-06-08 16:00:08

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 9,469
Website

Re: strftime unix %s doesn't works on localhost

gaekwad wrote #323643:

I can switch one or more of the demo servers to PHP 7.3, any good?

Perhaps so we can rule out or confirm PHP 7.4, that might be useful. Thank you.

I can’t see why the MySQL version would have any bearing on this since using the PHP strftime() function directly wth a fixed value (string or int) triggers the -1 output. That has nothing to do with MySQL at all.

Last edited by Bloke (2020-06-08 16:00:57)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#16 2020-06-08 16:04:53

gaekwad
Admin
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 2,989

Re: strftime unix %s doesn't works on localhost

Bloke wrote #323644:

Perhaps so we can rule out or confirm PHP 7.4, that might be useful. Thank you.

OK, I’ll wait until the latest compile has finished, then push a 7.3 latest compile through, and I’ll update this thread. ETA: within the hour.

Offline

#17 2020-06-08 16:07:53

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 9,469
Website

Re: strftime unix %s doesn't works on localhost

This particular issue is easy to work around as I mentioned in a previous post. Just return the posted + time zone value directly. The only time that wouldn’t work is if somebody used %s as part of a wider format string, e.g.:

<txp:posted format="%s (%F %T)" />

Can’t see anybody doing that, but to guard against that, it might be prudent to just do a str_replace() of ‘%s’ for the time+timezone, so it never passes %s through the strftime() function. I can’t see any downside to doing that and if it is a PHP bug, we won’t care when they fix it as we won’t be using that feature anyway.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#18 2020-06-08 16:08:14

gaekwad
Admin
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 2,989

Re: strftime unix %s doesn't works on localhost

Actually, PHP 7.3 is already latest – release-demo now on PHP 7.3.18

Last edited by gaekwad (2020-06-08 16:08:25)

Offline

#19 2020-06-08 16:13:47

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 9,469
Website

Re: strftime unix %s doesn't works on localhost

Even more bizarre:

dmp('DIRECT', strftime('%s', '1591628404'));
dmp('GM DIRECT', gmstrftime('%s', '1591628404'));

Expected:
DIRECT 1591628404
GM DIRECT 1591628404

Actual:
DIRECT -1
GM DIRECT 1591628404

?!!?!?!?!?

So if you add the gmt attribute to your <txp:posted /> tag, it works fine.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#20 2020-06-08 16:20:00

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 9,469
Website

Re: strftime unix %s doesn't works on localhost

gaekwad wrote #323648:

Actually, PHP 7.3 is already latest – release-demo now on PHP 7.3.18

In which case, short of heavy caching getting in the way, this issue occurs on PHP 7.3 as well?!

EDIT: but on my DO droplet running PHP 7.3.18-1+ubuntu16.04.1+deb.sury.org+1, it returns correct values. No -1 in sight. *head scratch*

Look at the source of the release-demo welcome article and search it for ‘posted’ to see the debug output. The RESULT is what is returned from the various function calls. Text in ALL CAPS indicates what’s being tested.

Last edited by Bloke (2020-06-08 16:26:13)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

Board footer

Powered by FluxBB