Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2013-07-22 13:05:08

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

<txp:posted format="since" /> for upcoming articles

Hi, developers (and everyone else).
This may be too much of an edge case to be fixed, but I wanted to lay it out here in case I’m over-thinking it.

Upcoming articles (that is, live articles with a future timestamp) can be displayed on the front end with some finagling. This is great, and adds a very useful dimension to sites where the time is important. Using <txp:posted format="since"/> on these articles, though, gives erroneous results. The article is stamped with ‘a few seconds ago’, or whatever the i18n string is, when it’s actually in the future.

Now, rationally, I’m not using Textpattern in the vanilla sense. I’m stretching it to do things that are nice but not as designed (at least that’s my interpretation of displaying articles with a future timestamp). Clearly this isn’t a trivial fix, but would something like <txp:posted format="offset" /> be viable for a future version? Primary aim here is to get rid of the tense, while still applying a relative offset.

Thank you in advance. You may now tear my suggestion to pieces :)

Offline

#2 2013-07-24 11:02:40

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

Re: <txp:posted format="since" /> for upcoming articles

gaekwad wrote:

Primary aim here is to get rid of the tense, while still applying a relative offset.

Hmmm. As you found, since only works for past articles (and it’s actually an ugly hack with a note in the code from about 2004 to look into ways of fixing the i18n!). Presumably you don’t want to put a conditional in to detect future articles and add “Will be published on <txp:posted format="%A, %B %e %Y" />” to the template?

If you don’t mind adding a plugin, there’s smd_countdown which can be coerced into displaying number of days, hours, minutes, whatever until each article’s Posted date is reached. Not sure how to reliably handle this (and the ‘since’ debacle) in core, but never say never.

Last edited by Bloke (2013-07-24 11:04:03)


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

#3 2013-07-24 13:33:08

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

Re: <txp:posted format="since" /> for upcoming articles

Hi, Stef. Thank you for your response.
I have previously used smd_countdown with some success; I seem to recall there was a spurious <br /> that spannered things for me somewhat, so I stopped using it. When I have time, I’ll raise a bug report for it.

Frankly, the functionality within smd_countdown was just the thing for date calculations, so harvesting the salient parts of it into core would – perhaps – resolve the issue with <txp:posted format="since" />.

If you’re not sure how to do it in core then me attempting to figure it out is an exercise in futility :) Is there mileage in me reporting it officially so there is an audit trail, or am I too much of an edge case?

Last edited by gaekwad (2013-07-24 13:43:56)

Offline

#4 2013-07-24 15:26:06

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

Re: <txp:posted format="since" /> for upcoming articles

gaekwad wrote:

I seem to recall there was a spurious <br /> that spannered things for me somewhat

Yeah I think I might have made some daft assumptions about what output people would actually use so it needs sorting. For the life of me I can’t remember why it did that so if you do get time to uncover it I’ll review your use case and figure out a more flexible solution. Thanks in advance.

harvesting the salient parts of it into core would – perhaps – resolve the issue with <txp:posted format="since" />.

Maybe, but it’s ugly code (in both core and smd_countdown) and I’m sure there are better ways to do this kind of thing in the latest PHP using the (much better) Date/Time object instead of strftime(). Maybe I’ll make time to look into it someday.

Is there mileage in me reporting it officially so there is an audit trail

Well the fact that the i18n string for since is so poorly implemented in core is enough reason to raise it officially. As I say, it’s been like that since all the time I can remember.

What I meant about not knowing how to fix it yet is that I’m unsure if it’s better to refactor since so it gives decent i18n output for both past and future articles, or to just fix since for past cases and invent a new format string (e.g. until) that can be used for future dates. Having two format strings is appealing but it makes things tricky for site administrators when articles flip from future to past and requires a conditional. Thus using the single since might be better. It’s just that the word since isn’t very semantically correct when referring to both future and past dated content.

*ponder*

Ideas for improvements or maybe a better name to cover both scenarios welcome.


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

#5 2013-07-24 17:02:31

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

Re: <txp:posted format="since" /> for upcoming articles

Bloke wrote:

Ideas for improvements or maybe a better name to cover both scenarios welcome.

  • format="offset"
  • format="delta"
  • format="t" (as in space rocket countdown; t-minus 10, t-plus 10 etc)

Offline

Board footer

Powered by FluxBB