Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2022-05-30 19:21:34

kevinpotts
Member
From: Ghost Coast
Registered: 2004-12-07
Posts: 370

[ Solved ] Convert timestamp to total seconds?

Hi fam. Building a new project in TXP and it requires a podcast RSS feed. One of my last missing links is the time length of the MP3 file which is represented in total seconds. While I could use a custom field and dump a dumb integer in there, I like the idea of proper content storage better. It occurred to me that I could use the article’s publishing timestamp to capture the minutes:seconds of the episode, but I cannot figure out how to use the format attribute of <txp:posted /> to convert the minutes and seconds of the timestamp into a total number of seconds. (For example, 1:00:00 would convert to 3600.) Any ideas?

Last edited by kevinpotts (2022-05-31 23:36:45)


Kevin
(graphicpush)

Offline

#2 2022-05-30 19:48:27

etc
Developer
Registered: 2010-11-11
Posts: 4,675
Website GitHub

Re: [ Solved ] Convert timestamp to total seconds?

Hi Kevin, here is a weird solution (but you know your idea is weird as well):

<txp:evaluate query='3600*<txp:posted format="%H" /> + 60*<txp:posted format="%M" /> + <txp:posted format="%S" />' />

Or even easier:

<txp:evaluate query='<txp:posted format="3600*%H + 60*%M + %S" />' />

Last edited by etc (2022-05-30 20:35:03)

Offline

#3 2022-05-30 20:05:40

kevinpotts
Member
From: Ghost Coast
Registered: 2004-12-07
Posts: 370

Re: [ Solved ] Convert timestamp to total seconds?

Intriguing. I am a stranger to the evaluate tag. I’ll try this. Thanks for the zippy response.


Kevin
(graphicpush)

Offline

#4 2022-05-31 23:36:15

kevinpotts
Member
From: Ghost Coast
Registered: 2004-12-07
Posts: 370

Re: [ Solved ] Convert timestamp to total seconds?

<txp:evaluate query='<txp:posted format="3600*%H + 60*%M + %S" />' />

This worked perfectly. Thank you very much. It’s been a solid 7-8 years since I’ve built anything in Textpattern. Feels good to return home, even if someone’s moved the furniture around a bit.


Kevin
(graphicpush)

Offline

#5 2022-06-01 06:00:59

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,751
Website GitHub

Re: [ Solved ] Convert timestamp to total seconds?

Great to see you, Mr Potts. Welcome back.

The tag suite is so much more powerful now that you can get away with way fewer plugins than in previous years. Anything you want to know, give us a shout here and we’ll show you the new carpet and sofa.


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

#6 2022-06-01 08:16:18

etc
Developer
Registered: 2010-11-11
Posts: 4,675
Website GitHub

Re: [ Solved ] Convert timestamp to total seconds?

kevinpotts wrote #333483:

This worked perfectly. Thank you very much. It’s been a solid 7-8 years since I’ve built anything in Textpattern. Feels good to return home, even if someone’s moved the furniture around a bit.

Nice to hear it works. We are strongly committed to preserve the foundations, so I hope you will quickly feel home again.

Offline

#7 2022-06-01 12:11:57

kevinpotts
Member
From: Ghost Coast
Registered: 2004-12-07
Posts: 370

Re: [ Solved ] Convert timestamp to total seconds?

Thanks both. I built the entire site without a single plugin in a week. I may have squeed in joy when I discovered <txp:header />. Exactly the sort of thing that eases the road of doing the hard work of rolling a custom RSS feed.


Kevin
(graphicpush)

Offline

#8 2022-06-01 13:51:43

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

Re: [ Solved ] Convert timestamp to total seconds?

kevinpotts wrote #333496:

I may have squeed in joy when I discovered <txp:header />.

You and me both, sir.

Offline

Board footer

Powered by FluxBB