Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
translate ISO date into human readable
if i use a custom field for the date, and it’s in the ISO format, how can i get it to display in human terms when i place it in a txp form? or do i need a second custom field where i manually type it out in human words? thanks
Offline
Re: translate ISO date into human readable
Would rah_function do it?
There’s an example there using safe_strftime()
Offline
Re: translate ISO date into human readable
looks like another interesting plugin from the rah camp. i guess my post should’ve gone in msd_datepicker discussion because his plugin lets us pick a date on a custom field, the problem is i’d have to type it out manually afterwards.
Last edited by mrtunes (2010-02-26 19:47:35)
Offline
Re: translate ISO date into human readable
So you’re using one format for the plugin output but you want a different format on the public side?
Information on the formats you can use with the plugin can be found on the jQuery site. If that doesn’t help let me know and we can look into it more.
Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker
Offline
Re: translate ISO date into human readable
I’ve done it with strftime and php date formats (had to display a date stocked as a variable):
<txp:php>echo "cet événement a lieu le " . strftime("%A %e %B",strtotime(variable(array('name' => 'jour'))));</txp:php>
Btw, I’m not a php guy, could someone tell me what’s the difference with safe_strftime? Is strftime unsafe?
Last edited by PascalL (2010-02-26 22:09:25)
Offline
Re: translate ISO date into human readable
PascalL wrote:
what’s the difference with safe_strftime? Is strftime unsafe?
It’s not entirely ‘unsafe’ it’s just that strftime()
is a built-in PHP function so TXP’s equivalent function is called safe_strftime()
to distinguish it from the PHP version. They do similar things but the ‘safe_’ version understands TXP’s underlying time system and can check the DST settings/server timezone offset/etc before returning the date and time. Thus (in theory) it keeps everything in sync in the TXP universe.
In practice, whimsical government alterations to DST and weird server configurations by ISPs banjax many attempts that TXP makes to try and shield you from exterior stupidity.
BTW — and this is just a guess — I think the safe_
prefix is a TXP thing to conform to the other functions in TXP’s library of database access functions: all the ones that go and get stuff from the TXP database start with safe_
as well. I guess the real reason for this is lost in the mists of time / Dean’s head ;-)
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
Re: translate ISO date into human readable
pieman wrote:
Would rah_function do it?
If time isn’t in unix timestamp, it requires two function calls, strtotime()
and safe_strftime()
. Following could do it, possibly maybe:
<txp:rah_function call="safe_strftime" format="%Y %m %d" thing="here">
<txp:rah_function call="strtotime">
<txp:custom_field name="MyCustomField" />
</txp:rah_function>
</txp:rah_function>
Before using, probably need to remove indentation from the code. The indentation is there only to make the example readable. In real usage it might destroy the timezone outputs with whitespace.
Offline