This plugin hasn’t been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues when used with more recent versions of WordPress.

[TiSiE] RelativeTime

Description

Adds template tags to your wordpress blog that lets you show relative time strings,
such as “3 months and 2 days” or “4 months, 10 hours and 2 minutes”.

Unlike other algorithms used to calculate relative time, this plugin uses an algorithm based
on written substraction and therefore the calculated relative time is synchronous to the gregorian
calendar system.
Example: Let’s assume todays date were “2010-03-01” and the post date were “2010-02-01“. The
result of this plugin’s calculation would be “1 month“.

Currently only englisch and german localizations are available. But maybe you can help me
translate to other languages. I will gladly add them. (see “FAQ” for more details)

The following template tags are available

  • the_date_relative / get_the_date_relative
  • the_modified_date_relative / get_the_modified_date_relative
  • comment_date_relative / get_comment_date_relative

Additionally there are two filter hooks available

  • tirt_get_string
  • tirt_get_array

Please see the “Other Notes
tab for more information about the usage.

Du kannst auch auf deutsch lesen.

This is a BETA release

So, if something is not working as expected or you get others errors or you encounter incompatibilities to other
plugins – please report them to me so I can fix and improve my plugin.

Usage

General

All template tags accepts one optional parameter which specifies how many
relative time string parts should be in the string. This parameter must be
an integer between 1 and 7 inclusively.

The default value is 2.

To prevent strings like “1 year, 3 hours and 2 minutes, parts that have the value 0
and all following parts are stripped from the string, regardless of the value of
the optional parameter.

Examples:
– the_date_relative(1)

“1 year”, “3 days”

  • the_date_relative(3)

    “1 year, 2 months and 4 weeks”, “12 days, 3 hours and 37 minutes”, “4 days”

Template Tags

  • the_date_relative

    displays the relative post date string

    Usage: <?php the_date_relative($parts) ?>

  • get_the_date_relative

    gets the relative post date string

    Usage: <?php $rel = get_the_date_relative($parts) ?>

  • the_modified_date_relative

    displays the relative post modified date string

    Usage: <?php the_modified_date_relative($parts) ?>

  • get_the_modified_date_relative

    gets the relative post modified date string

    Usage: <?php $rel = get_the_modified_date_relative($parts) ?>

  • comment_date_relative

    displays the relative comment date string

    Usage: <?php comment_date_relative($parts) ?>

  • get_comment_date_relative

    gets the relative comment date string

    Usage: <?php $rel = get_comment_date_relative($parts) ?>

Additional Functions

If, for whatever reason, you have a date which is not covered by the tags above, that you
want to show as a relative string, you can use the following functions:

  • <?php tirt_get_string($date, $parts) ?>

    gets a relative date string

    Parameters:

    • $date (string) the date to show relative in mysql DateTime format
    • $parts (int) (optional) How many parts to show maximal (Default: 2)
  • <?php tirt_get_array($date) ?>

    gets relative date parts as array in the form:
    array(
    ‘year’ => ,
    ‘month’ => ,
    ‘week’ => ,
    ‘day’ => ,
    ‘hour’ => ,
    ‘minute’ => ,
    ‘second’ =>
    );

    Parameters:

    • $date (string) the date to get the relative parts in mysql DateTime format

Filter Hooks

On general information how to use filter hooks, please see the
Funtion Reference

  • tirt_get_array

    applied to the date array at the end of tirt_get_array.
    Can be used to modify the values of the array.

    NOTE: The filter using this hook MUST return an array with the same
    keys as the input array.

  • tirt_get_string

    applied to the relative time string.
    Can be used to i.e append or prepend text to the string, If you do not want
    to do that on every occurence of the template tag in your theme files.

Screenshots

  • Relative comment date string on my blog

Installation

  1. Upload the .zip file to your plugins folder and unzip
  2. Activate the plugin through the plugin management admin interface
  3. Add the template tags to your theme files (see “Usage”)
  4. (Optional) Uses the filter hooks to modify the output without touching the
    plugin files.

There are no settings for this plugin, it will work straight away.

FAQ

How do I translate to other languages?

Just take the “tirt.pot” file located in the subdirectory “translations” under the plugin’s root directory and add
the translated string in the “msgstr” line between the ‘”‘.
Save the edited file as “tirt-[langCode].po” and convert it to a .mo file with gettext.

Or use poedit: Load the tirt.pot file as new catalog, translate the strings and
save it as “tirt-[langCode].po”, poedit will automatically create a .mo file.

[langCode] is the language code, such as “en_EN” or “de_DE”.

Contributors & Developers

“[TiSiE] RelativeTime” is open source software. The following people have contributed to this plugin.

Contributors

Changelog

0.2

  • fixed: The date was not validated. (see upgrade notice)
  • new: Error handling. Now uses WP_Error objects to reflect errors.
  • new: Two filter hooks: tirt_get_string and tirt_get_array

0.1

  • Beta-Release