Rah's Get Date

The plugin, rah_get_date, outputs date and time from the requested url. Supports Textpattern’s build in date and month -GET variables, and outputs formatted date based on those two GET values. That way you can, for example, output month header to month separated article listing pages.

Download

Version 0.2 May 22, 2011
Other versions...

A cup of coffee
via PayPal

List of features

  • Output date from ?date= and/or ?month= get values.
  • Format date just like you can with <txp:posted />.

Requirements

Minimum requirements:

  • TXP 4.x.x+

Recommended:

  • TXP 4.4.0+

Installation and usage

The basic method stands: paste plugin code to the plugin install textarea and run the automatic setup. Activate the plugin, and you are ready to use the new tag, <txp:rah_get_date /> like others.

Attributes

The tag is <txp:rah_get_date /> and attributes for it follow. All attributes are optional.

format
Date format used to output the date. Any valid strftime() string value since iso8601, w3cdtf, or rfc822.
Default: format="%Y %B" Example: "%Y %m %d".

format_year
Allows specific formatting for dates that only specify the year (YYYY). If the attribute is set, the additional formatting is used. Same formatting rules apply.
Default: unset Example: format_year="Articles posted during %Y"

format_month
Allows specific formatting for dates that only specify the year and the month of the year (YYYY-mm). If the attribute is set, the additional formatting is used. Same formatting rules apply.
Default: unset Example: format_month="%B, %Y"

format_date
Allows specific formatting for dates that only specify the year, the month and the day of the month (YYYY-mm-dd). If the attribute is set, the additional formatting is used. Same formatting rules apply.
Default: unset Example: format_date="%B %d, %Y"

format_hour
Allows specific formatting for dates that only specify the year, month, day and hour of the day (YYYY-mm-dd HH). If the attribute is set, the additional formatting is used. Same formatting rules apply.
Default: unset Example: format_hour="Posted on %H of %d"

format_minute
Allows specific formatting for dates that only specify the year, month, day, hours and minutes (YYYY-mm-dd HH:MM). If the attribute is set, the additional formatting is used. Same formatting rules apply.
Default: unset Example: format_minute="%H:%M"

format_second
Allows specific formatting for dates that only specify the year, month, day, hours, minutes and seconds (YYYY-mm-dd HH:MM:SS). If the attribute is set, the additional formatting is used. Same formatting rules apply.
Default: unset Example: format_second="%Y %B, %d %H:%M:%S"

format_now
Formatting used if the requested date is the current time. Current time’s condition is set with the now_condition attribute. By default, if the requested date/time is within the current day, the formatting defined in format_now is used.
Default: unset Example: format_now="Articles posted today"

now_condition
Defines what dates are considered as current time. Set the date format that is used in matching current and requested dates. By default matches days (today).
Default: now_condition="%Y-%m-%d" Example: "%Y-%m"

Examples

Example #1: Basic usage

<txp:rah_get_date format="%Y %B" />

Outputs "2009 March" if requested URI is http://mysite.com/path/?month=2009-3.

Example #2: Use specific formatting for dates that only define the year

The example uses format_year attribute to set the formatting for the dates that only specify the year.

<txp:rah_get_date format="%Y %B" format_year="Posted during %Y" />

Outputs "2009 March" if the requested URL is http://mysite.com/path/?month=2009-3 and "Posted during 2008" if the requested URL is http://mysite.com/path/?month=2008

*Example #3: Output "Posted today", if the requested timestamp is today.

<txp:rah_get_date now_condition="%Y-%m-%d" format_now="Posted today" />

Changelog

Version 0.2

  • Added: support for additional formatting rules applied based on timestamp’s accuracy. Added attributes: format_year, format_month, format_date, format_hour, format_minute, format_second, format_now, now_condition and date.
  • Added: Ability to set the date using date attribute in addition to the URL parameter.
  • Now uses safe_strtotime() instead of strtotime() to format the dates.
  • Now checks if the provided date is in valid strtotime() format.
  • Skip date formatting if the resulting formatting string is empty.

Version 0.1

  • First release.