Foswiki on GitHub is open for business! Next release meeting: Monday October 13, 1300Z

TimeSincePlugin

This plugin is inspired by the WordPress TimeSince plugin. It which can be used to display a time difference in a human readable way, for instance to tell you that a topic has been published "2 days, 3 hours ago".

There are some problems with the original TimeSince plugin for WordPress. For example, it was only able to display a time diff with at most two expressions: "1day, 2hours ago" or "1 week ago" but not "1 day, 2 hours and 3 minutes". It even displays only one time expression if the difference does not occure in two adjacent time units (time units are year, month, week, day, hour, minute). If a time interval differs in week and hour the TimeSince WP plugin will only display the week difference and not the hours as week and hour are not adjacent. This is fixed in the TimeSincePlugin for Foswiki. Several other parameters have been added to give a finer control of the format and the information displayed.

Syntax Rules

%TIMESINCE%, %TIMESINCE{[[from]="..."] [to="..."]}%

Without arguments the time since the current topic has been created will be displayed.

ArgumentSorted ascending Description
days="on,off" switch on/off days
format="<format-string>" format of the output, defaults to "$time", other usefull settings format="$time ago", format="replied $time later", "format="$time after the incident"
from="<time-experssion>" the starting time point, if ommited the current time
hours="on,off" switch on/off hours
minutes="on,off" switch on/off minutes
months="on,off" switch on/off months
negformat="<format-string>" use this format string if the time difference is negative
null="<format-string>" to be displayed if the tim difference is null; defaults to "about now"
seconds="on,off" switch on/off seconds, default off
to="<time-expression>" the ending timepoint, if ommited the current time
units="1...7" number of time units to display, default 2; (example units="3": 2 months, 1 day and 3 minutes)
weeks="on,off" switch on/off weeks
years="on,off" switch on/off years

Note, that switching off years and months (or any other two adjacent time unites) won't display the correct duration when the times differ more than a year, that is: years can't be converted to weeks, the next lower unit. The following units can be converted to each other:
  • year <=> months
  • weeks <=> days
  • hours <=> minutes

For a further explanation/excuse, read how datetime math is done.

Time expressions can be specified in any of the following format:
  • 31 Dec 2001 - 23:59 (Foswiki date)
  • 31 Dec 2001
  • 2001/12/31 23:59:59 (RCS date)
    also -, . instead of / in date, also . instead : in time
  • 2001/12/31 23:59
  • 2001/12/31
  • 2001-12-31T23:59:59Z (ISO date)
  • 2001-12-31T23:59:59+01:00
  • 2001-12-31T23:59Z
  • 2001-12-31T23:59+01:00
  • epoch seconds

Format strings may contain the following:
  • $time expands to the calculated time difference
  • $percnt$ expands to a % char
  • $dollar$ expands to a $ char
  • $n expands to a linefeed
  • $t expands to a tab space
  • $nop expands to the empty string

Examples

You type You get (simulated) You get (if installed)
%TIMESINCE% 2 years and 6 months %TIMESINCE%
%TIMESINCE{format="topic was created $time ago" null="topic has just now been saved" units="3" }% topic was created 1 day, 3 hours and 8 minutes ago %TIMESINCE{format="topic was created $time ago" null="topic has just now been saved" units="4"}%
%TIMESINCE{"11 Sep 2001 - 8:45" units="7" seconds="on"}% 4 years, 2 months, 2 days, 5 hours, 50 minutes, 16 seconds %TIMESINCE{"11 Sep 2001 - 8:45" units="7" seconds="on"}%
%TIMESINCE{from="1955/04/18" to="1979-03-14" units="3"}% 23 years, 11 months, 6 days %TIMESINCE{from="1955/04/18" to="1979-03-14" units="3"}%

Plugin Installation Instructions

You do not need to install anything in the browser to use this extension. The following instructions are for the administrator who installs the extension on the server.

Open configure, and open the "Extensions" section. Use "Find More Extensions" to get a list of available extensions. Select "Install".

If you have any problems, or if the extension isn't available in configure, then you can still install manually from the command-line. See http://foswiki.org/Support/ManuallyInstallingExtensions for more help.

Plugin Info

Plugin Author: Michael Daum
Copyright ©: 2005-2009, Michael Daum http://michaeldaumconsulting.com
License: GPL (GNU General Public License)
Release: 3.00
Version: 3647 (2009-04-23)
Change History:  
23 Apr 2009: converted to foswiki plugin
13 Aug 2008: replaced CPAN:Time::Local with much more powerful and more precise CPAN:DateTime
03 Jan 2008: improved parsing time formats
13 Oct 2006: added negformat parameter
31 Aug 2006: added NO_PREFS_IN_TOPIC
27 Apr 2006: added lazy compilation
11 Nov 2005: Initial version
Dependency: $Foswiki::Plugins::VERSION 1.1
CPAN Dependencies: CPAN:DateTime
Other Dependencies: none
Perl Version: 5.005
Plugin Home: Foswiki:Extensions/TimeSincePlugin
Support: Foswiki:Support/TimeSincePlugin
Topic revision: r7 - 14 Jul 2012, MichaelDaum
 
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. see CopyrightStatement. Creative Commons License