Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2010-02-26 06:37:37

mrtunes
Member
From: Toronto, On
Registered: 2007-03-12
Posts: 575
Website

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

#2 2010-02-26 19:17:51

pieman
Member
From: Bristol, UK
Registered: 2005-09-22
Posts: 491
Website

Re: translate ISO date into human readable

Would rah_function do it?

There’s an example there using safe_strftime()

Offline

#3 2010-02-26 19:45:06

mrtunes
Member
From: Toronto, On
Registered: 2007-03-12
Posts: 575
Website

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

#4 2010-02-26 19:59:53

MattD
Plugin Author
From: Monterey, California
Registered: 2008-03-21
Posts: 1,254
Website

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.


My Plugins

Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker

Offline

#5 2010-02-26 22:08:44

PascalL
Member
From: Switzerland
Registered: 2009-03-09
Posts: 132
Website

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

#6 2010-02-26 22:33:41

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

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

#7 2010-02-27 01:37:49

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

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

Board footer

Powered by FluxBB