Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2020-06-08 11:27:58

THE BLUE DRAGON
Member
From: Israel
Registered: 2007-11-16
Posts: 637
Website

strftime unix %s doesn't works on localhost

Hi, I’m using the <txp:posted /> tag with the strftime format to display the article “Unix Epoch Time timestamp” (%s), but it doesn’t works on my localhost and does not output anything at all, all other strftime formats seems to be working fine, it is just the unix that doesn’t works.

TXP: 4.8
PHP: 7.4
Apach: 2.4.41
MySQL: 8.0.18
running locally on WampServer

<txp:article_custom id="1"><txp:posted format="%s" /></txp:article_custom>

Offline

#2 2020-06-08 13:34:15

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,064
Website GitHub Mastodon Twitter

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

Would it be the MySQL version?


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#3 2020-06-08 13:47:04

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,215
GitHub

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

I just tried <txp:posted format="%s" /> on 4.8.1 (PHP 7.4, Percona Server 8.0) and it returned -1.

Edit: tried the same on 4.7.3, same result: -1.

Edit: tried the same on 4.8.1 with Percona Server 5.7, I get the epoch time. Looks like a possible issue with 8.0 and strftime

Last edited by gaekwad (2020-06-08 13:52:03)

Offline

#4 2020-06-08 14:08:22

THE BLUE DRAGON
Member
From: Israel
Registered: 2007-11-16
Posts: 637
Website

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

Thanks, is there an other way to get the article posted and expires timestamps please, maybe using PHP and store it in a TXP variable?

<txp:article_custom id="1">
    <txp:variable name="article_posted_timestamp" />
    <txp:variable name="article_expires_timestamp" />

    <txp:php>
        global $variable;
        $variable['article_posted_timestamp'] = 'some_magic';
        $variable['article_expires_timestamp'] = 'some_magic';
    </txp:php>

    Posted: <txp:variable name="article_posted_timestamp" />
    <br/>Expired: <txp:variable name="article_expires_timestamp" />
</txp:article_custom>

Offline

#5 2020-06-08 14:26:01

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,215
GitHub

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

Opened github.com/textpattern/textpattern/issues/1497 to track any resolution.

Offline

#6 2020-06-08 14:43:32

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,413
Website GitHub

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

Eeek, what’s this about?! I’ll look into it, if I can somehow set up an environment with file write access that has MySQL 8 installed.

Thanks for the report. In the meantime, this will get you the current article timstamp:

<txp:php>global $thisarticle; echo $thisarticle['posted'];</txp:php>

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

#7 2020-06-08 14:51:21

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,064
Website GitHub Mastodon Twitter

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

THE BLUE DRAGON wrote #323633:

Thanks, is there an other way to get the article posted and expires timestamps please, maybe using PHP and store it in a TXP variable?

Well caught! Would doing it the long way suit you?

<txp:posted format="%B" /> <txp:posted format="%e" />, <txp:posted format="%Y" /> <txp:posted format="%r" />

> Edit – Stef was quicker:)

Last edited by colak (2020-06-08 14:52:33)


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#8 2020-06-08 14:53:22

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,215
GitHub

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

Bloke wrote #323635:

Eeek, what’s this about?! I’ll look into it, if I can somehow set up an environment with file write access that has MySQL 8 installed.

I’ll set you up on the demo server – check your email in 10 mins.

Offline

#9 2020-06-08 15:09:02

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,064
Website GitHub Mastodon Twitter

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

On my setup, PHP: 7.2.31, MySQL: 5.6.48-88.0 <txp:posted format="%s" /> returns 1618051452


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#10 2020-06-08 15:21:17

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,413
Website GitHub

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

colak wrote #323638:

On my setup, PHP: 7.2.31, MySQL: 5.6.48-88.0 <txp:posted format="%s" /> returns 1618051452

Yep. Works on my system too. I have no idea why MySQL 8 has a bearing in this. Perhaps the way dates are stored internally has changed or they’ve deprecated/removed UNIX_TIMESTAMP() or something. Investigating…


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

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

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,215
GitHub

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
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,215
GitHub

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

Board footer

Powered by FluxBB