Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2013-03-26 21:37:02

etc
Developer
Registered: 2010-11-11
Posts: 5,053
Website GitHub

etc_date : custom dates and calendars

Textpattern has localized strings for almost everything, but dates are under servers responsibility. This is reasonable, since dates are more than just months/days names, but can be a problem if some locales are not installed on the server. For example, if ru_RU locale is not available on your server, <txp:posted /> will output something like March 26, 09:21 PM, even if you switch Textpattern current language to Russian.

This is where etc_date intervenes. It allows you to define your own date strings and output dates in the language of your choice. Moreover, you can use custom calendars, to output something like 18 Brumaire An VIII (though currently only Gregorian and Hijri calendars are available).

More info and download.

Offline

#2 2013-03-29 20:53:33

etc
Developer
Registered: 2010-11-11
Posts: 5,053
Website GitHub

Re: etc_date : custom dates and calendars

Small update (v.0.2.2) to include Jalali calendar (knowledgeable testers needed).

Attention: locale attribute is renamed to lang, to avoid clashes with global variables and to comply avec <txp:posted /> attributes.

Offline

#3 2013-03-31 11:14:52

etc
Developer
Registered: 2010-11-11
Posts: 5,053
Website GitHub

Re: etc_date : custom dates and calendars

Version 0.2.5: introduces <txp:etc_if_date /> tag:

<txp:etc_if_date value="12-25" format="%m-%d">
	Merry Christmas!
</txp:etc_if_date>

Offline

#4 2013-03-31 15:01:03

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

Re: etc_date : custom dates and calendars

etc wrote:

Version 0.2.5: introduces <txp:etc_if_date /> tag:

I could use this:)

Thanks soo much Oleg. I’ll be giving your plugin a try.


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

Offline

#5 2013-03-31 15:28:03

etc
Developer
Registered: 2010-11-11
Posts: 5,053
Website GitHub

Re: etc_date : custom dates and calendars

colak wrote:

I could use this:)

It does not help much in retrieving money from a bank, I’m afraid :) Good luck, Yiannis, I have experienced it in 90’s in Russia, loosing every ruble I had (that was not much), and life still goes on.

Offline

#6 2013-04-01 05:58:18

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

Re: etc_date : custom dates and calendars

etc wrote:

It does not help much in retrieving money from a bank, I’m afraid :)

Hey Oleg, Why didn’t you mention this before I installed it? It’s what I needed it for:)


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

Offline

#7 2013-04-03 04:54:08

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

Re: etc_date : custom dates and calendars

Hi Oleg is there a way to have a conditional on a range of dates?

Something like

<txp:etc_if_date from="1-25" to="2-16" format="%m-%d">
	Range specific message
</txp:etc_if_date>

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 2013-04-03 13:10:25

etc
Developer
Registered: 2010-11-11
Posts: 5,053
Website GitHub

Re: etc_date : custom dates and calendars

Hi Yiannis, thanks for your proposal. It surely makes sense and is easy to implement for literal comparisons. I wouldn’t like to multiply attributes, though. What do you think of value="1-25..2-16" or something like this to specify a range?

That’s more tricky to do consistently for non-literal comparisons, due to the “international” nature of the plugin. Imagine that someone wants

<txp:etc_if_date from="25 January" to="16 February" format="%d %B">
	Range specific message
</txp:etc_if_date>

We can not do literal comparison here, so we have to convert dates to timestamps. It would be ok for default locales, but how to do with custom locales/calendars:

<txp:etc_if_date from="14 Farvardin 1392" to="14 Esphand 1394" lang="fa_IR" calendar="jalali" format="%d %B %Y">
	Range specific message
</txp:etc_if_date>

PHP has no idea of what Farvardin is, so we have to provide a converter to timestamp for every calendar/locale/format combination…

BTW, etc_query can also be used as universal conditional plugin:

<txp:etc_query functions="date" query="date('md') >= '0125' and date('md') <= '0216'">
	Range specific message
</txp:etc_query>

Offline

#9 2013-04-03 13:28:37

phuture303
Member
Registered: 2008-09-14
Posts: 127

Re: etc_date : custom dates and calendars

colak schrieb:

<txp:etc_if_date from=“1-25” to=“2-16” format=”%m-%d”> Range specific message
</txp:etc_if_date>

Hi colak,

depending of what you want to do you should have a look at pat_timer. I’m using it for registration forms (hide/live soon -> live/registration open -> hide again/registration closed) with success.

Example (looks weird I know…)

<txp:pat_timer start="2012-01-01" end="2013-03-31 20:00">
	<txp:upm_textile>
		<txp:custom_field name="anmeldung-text-bald" escape=""/>
	</txp:upm_textile>
</txp:pat_timer>
<txp:pat_timer start="2013-03-31 20:00" end="2013-04-14 20:00">
	<txp:upm_textile>
		<txp:custom_field name="anmeldung-text-ja" escape=""/>
	</txp:upm_textile>
	<txp:output_form form="anmeldeformular_machform" />
</txp:pat_timer>
<txp:pat_timer start="2013-04-14 20:00" end="2013-12-31">
	<txp:upm_textile>
		<txp:custom_field name="anmeldung-text-nein" escape=""/>
	</txp:upm_textile>
</txp:pat_timer>

David

Edit: Added code blocks to make it readable..

Last edited by jstubbs (2013-04-03 14:43:32)

Offline

#10 2013-04-03 14:59:53

etc
Developer
Registered: 2010-11-11
Posts: 5,053
Website GitHub

Re: etc_date : custom dates and calendars

Done as described above, please test, e.g.

<txp:etc_if_date date="-2 months" value="01-25..02-16" format="%m-%d">
	Range specific message
</txp:etc_if_date>

Multiple ranges are possible too:

<txp:etc_if_date value="01-25..02-16 | 04-03" format="%m-%d">
	Range specific message
<txp:else />
	Out of range
</txp:etc_if_date>

Last edited by etc (2013-04-04 10:28:52)

Offline

#11 2013-04-04 10:28:25

etc
Developer
Registered: 2010-11-11
Posts: 5,053
Website GitHub

Re: etc_date : custom dates and calendars

Version 0.2.7: implements ranges for dates comparison. Help updated.

Offline

#12 2013-04-04 11:07:36

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

Re: etc_date : custom dates and calendars

Hi Oleg and David,

Apologies for the delayed reply but inspire of the fact the Cyprus is disappearing from the world news, the situation here is still absolutely crazy with uncertainty looming over everyone.

Thanks soo much for your replies. I’ll be looking into it later today.


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

Offline

Board footer

Powered by FluxBB