Textpattern CMS support forum

You are not logged in. Register | Login | Help

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

etc
Developer
Registered: 2010-11-11
Posts: 3,159
Website

Re: etc_date : custom dates and calendars

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


etc_[ query | search | pagination | date | tree | cache ]

Offline

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

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 7,245
Website

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.org | hblack.net | LABS | State Machines | Respbublika! | NeMe @ github

Offline

#13 2013-07-20 15:04:32

etc
Developer
Registered: 2010-11-11
Posts: 3,159
Website

Re: etc_date : custom dates and calendars

Version 0.2.8: easier dates comparison:

<txp:etc_if_date date="expires" compare="now..+3 days" format="%s">
	This article expires within 3 days!
</txp:etc_if_date>

etc_[ query | search | pagination | date | tree | cache ]

Offline

#14 2013-07-20 17:09:27

etc
Developer
Registered: 2010-11-11
Posts: 3,159
Website

Re: etc_date : custom dates and calendars

Version 0.2.9: and a new <txp:etc_date_diff /> tag:

<txp:etc_if_date date="expires" compare="now..+3 days" format="%s">
	This article expires in less than <txp:etc_date_diff from="yesterday" to="expires" /> days!
</txp:etc_if_date>

etc_[ query | search | pagination | date | tree | cache ]

Offline

#15 2013-12-20 14:34:18

etc
Developer
Registered: 2010-11-11
Posts: 3,159
Website

Re: etc_date : custom dates and calendars

Version 0.3: introduces date ranges, so it’s possible to output date lists like

<txp:etc_date date="today..expires" />

Now can be used as container too:

<txp:etc_date date="sunday..sunday +6 days" wraptag="p" break=", ">
	<txp:etc_date timestamp='<txp:etc_timestamp />' format="%A" /> -
	<txp:etc_date timestamp='<txp:etc_timestamp />' format="%A" lang="ru_RU" />
</txp:etc_date>

outputs

Sunday - Воскресенье , Monday - Понедельник , Tuesday - Вторник , Wednesday - Среда , Thursday - Четверг , Friday - Пятница , Saturday - Суббота

etc_[ query | search | pagination | date | tree | cache ]

Offline

#16 2017-01-30 12:52:12

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 3,435
Website

Re: etc_date : custom dates and calendars

Hi Oleg,

I saw your example of a countdown above, and you date + x days example with etc_date too.

Does that mean, you can add a number of days to an existing date to make a message expire automatically after x days, or to begin a message the day after a date?

An example: I have a course site with key dates stored as variables, and a little self-built macro, txp:datum, that pulls out the variables and reformats them in different formats for use in the text or calendar.

Would the following be correct?

Example: begin a message a day after a submission deadline

<txp:etc_if_date value='<txp:datum date="apply-by" format="%s" /> +1 day..<txp:datum date="confirm-by" format="%s" />' format="%s">
  <p>Applications are now closed. We will inform successful applicants shortly.</p>
</txp:etc_if_date>

Example: final message that should begin a day after the course is over and auto-expire 10 days later

<txp:etc_if_date value='<txp:datum date="course-end" format="%s" /> +1 day..<txp:datum date="course-end" format="%s" /> +10 days' format="%s">
   <p>The course is over. Thank you to all who came.</p>
</txp:etc_if_date>

Have I understood that correctly?


TXP Builders – finely-crafted code, design and txp

Offline

#17 2017-01-30 14:45:09

etc
Developer
Registered: 2010-11-11
Posts: 3,159
Website

Re: etc_date : custom dates and calendars

Hi Julian,

This will not work, since

<txp:etc_if_date format="%s"
    value='<txp:datum date="apply-by" format="%s" /> +1 day..<txp:datum date="confirm-by" format="%s" />' />

will try to literally compare the current %s-formatted date (say, 1485788875) with something like 1485780000 +1 day.

Additionally, strtotime function used in etc_date will not correctly interpret 1485780000 +1 day. You need to change the format to get some English date from <txp:datum /> and use compare attribute, something like

<txp:etc_if_date compare='<txp:datum date="apply-by" format="%c" /> +1 day..<txp:datum date="confirm-by" format="%c" />'>
  <p>Applications are now closed. We will inform successful applicants shortly.</p>
</txp:etc_if_date>

Hope it helps.


etc_[ query | search | pagination | date | tree | cache ]

Offline

#18 2017-01-31 09:58:32

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 3,435
Website

Re: etc_date : custom dates and calendars

Brilliant, thank you – I wasn’t sure which strftime combinations worked. My ‘datum’ macro has some plain-language attributes/presets (deutsch, deutsch_text, etc.) for easier use by editors in articles, but can output any strftime date format.

As I don’t have any times set in the variables, can I also use %x instead (and is that better or worse)?
Or would it be better to explicitly specify a certain output given that my server is based in Germany and I’m not sure if that locale plays well with +1 days, etc. – and if so, what’s best %m/%d/%Y (America) or %d/%m/%Y (British) or %F (aka %Y-%m-%d)?

The other thing I haven’t quite worked out with etc_date is which attributes to use when, and in which combination. In your last example, you have compare without a date attribute. I didn’t realise that was possible. Am I right in assuming that when no date is given, it compares against the current server date?


TXP Builders – finely-crafted code, design and txp

Offline

#19 2017-01-31 10:45:27

etc
Developer
Registered: 2010-11-11
Posts: 3,159
Website

Re: etc_date : custom dates and calendars

AFAIK, strtotime is not localized, so you’d better use something like %F, which should be ok.

jakob wrote #303750:

Am I right in assuming that when no date is given, it compares against the current server date?

Completely, be it with value or compare. The difference between value and compare is that value will be used as is for comparison with formatted date, while compare will be transformed (by strtotime) into UNIX timestamp, as well as date.


etc_[ query | search | pagination | date | tree | cache ]

Offline

#20 2017-01-31 11:19:44

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 3,435
Website

Re: etc_date : custom dates and calendars

etc wrote #303752:

AFAIK, strtotime is not localized, so you’d better use something like %F, which should be ok.

Thanks. That’s what I’d read too.

Completely, be it with value or compare. The difference between value and compare is that value will be used as is for comparison with formatted date, while compare will be transformed (by strtotime) into UNIX timestamp, as well as date.

Apologies if I’m being dense here but in case I’ve got confused here, do you mean:

  • Use value where your date string (or from..to combo) exactly matches the format specified in the format attribute, and
  • Use compare where your date string first needs computing (e.g. has a +1 day / +1 week / +10 days …) prior to comparison.
  • Use date attribute to compare against a specific date. If omitted, the server date (e.g. now/today) is used.

Sorry for all the questions, but it’s not so easy to test whether everything’s working correctly when testing different if-constructions against server time. I can only specify a date attribute to compare against, then remove it again and hope it will work correctly when the time comes…


TXP Builders – finely-crafted code, design and txp

Offline

Board footer

Powered by FluxBB