Skip to content

Commit

Permalink
Item8130: converted to foswiki plugin
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk/TimeSincePlugin@3647 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
MichaelDaum authored and MichaelDaum committed Apr 23, 2009
1 parent 40641c2 commit 3824320
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 29 deletions.
Expand Up @@ -97,12 +97,7 @@ Format strings may contain the following:


---++ Plugin Installation Instructions

* Download the ZIP file
* Unzip it in your twiki installation directory. Content:
| *File:* | *Description:* |
%$MANIFEST%
* Visit =configure= in your installation, and enable the plugin in the {Plugins} section.
%$INSTALL_INSTRUCTIONS%

---++ Plugin Info
<!-- provided for compatibility only
Expand All @@ -112,8 +107,9 @@ Format strings may contain the following:
| Plugin Author: | Michael Daum |
| Copyright &copy;: | 2005-2009, Michael Daum http://michaeldaumconsulting.com |
| License: | GPL ([[http://www.gnu.org/copyleft/gpl.html][GNU General Public License]]) |
| Plugin Version: | v2.00 |
| Plugin Version: | v3.00 |
| Change History: | <!-- versions below in reverse order -->&nbsp; |
| 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 |
Expand All @@ -125,4 +121,4 @@ Format strings may contain the following:
| Other Dependencies: | none |
| Perl Version: | 5.005 |
| Plugin Home: | Foswiki:Extensions/%TOPIC% |
| Feedback: | Foswiki:Extensions/%TOPIC%Dev |
| Support: | Foswiki:Support/%TOPIC% |
Expand Up @@ -19,7 +19,7 @@
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

package TWiki::Plugins::TimeSincePlugin;
package Foswiki::Plugins::TimeSincePlugin;

use strict;
use vars qw(
Expand All @@ -28,31 +28,30 @@ use vars qw(
);

$VERSION = '$Rev$';
$RELEASE = '2.00';
$RELEASE = '3.00';
$NO_PREFS_IN_TOPIC = 1;
$SHORTSUMMARY = 'Display time difference in a human readable way';

###############################################################################
sub initPlugin {

if ($TWiki::Plugins::VERSION < 1.1) {
if ($Foswiki::Plugins::VERSION < 1.1) {
return 0;
}

TWiki::Func::registerTagHandler('TIMESINCE', \&handleTimeSince);
Foswiki::Func::registerTagHandler('TIMESINCE', \&handleTimeSince);
return 1;
}

###############################################################################
sub handleTimeSince {

unless ($isInitialized) {
eval 'use TWiki::Plugins::TimeSincePlugin::Core;';
die $@ if $@;
require Foswiki::Plugins::TimeSincePlugin::Core;
$isInitialized = 1;
}

return TWiki::Plugins::TimeSincePlugin::Core::handleTimeSince(@_);
return Foswiki::Plugins::TimeSincePlugin::Core::handleTimeSince(@_);
}

1;
Expand Up @@ -19,7 +19,7 @@
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

package TWiki::Plugins::TimeSincePlugin::Core;
package Foswiki::Plugins::TimeSincePlugin::Core;

use DateTime;
use strict;
Expand All @@ -46,12 +46,11 @@ sub writeDebug {
print STDERR "TimeSincePlugin - $_[0]\n" if DEBUG
}


###############################################################################
sub handleTimeSince {
my ($session, $params, $theTopic, $theWeb) = @_;

writeDebug("handleTimeSince(" . $params->stringify() . ") called");
#writeDebug("handleTimeSince(" . $params->stringify() . ") called");

my $theFrom = $params->{_DEFAULT} || $params->{from} || '';
my $theTo = $params->{to} || '';
Expand All @@ -72,9 +71,8 @@ sub handleTimeSince {

if ($theFrom eq '' && $theTo eq '') {
# if there's no starting date then get the current revision date
my ($meta, undef) = TWiki::Func::readTopic($theWeb, $theTopic);
my ($epoch) = $meta->getRevisionInfo();
$theFrom = DateTime->from_epoch(epoch=>$epoch);
my ($date) = Foswiki::Func::getRevisionInfo($theWeb, $theTopic);
$theFrom = DateTime->from_epoch(epoch=>$date);
$theTo = parseTime();
} else {

Expand Down Expand Up @@ -123,7 +121,7 @@ sub handleTimeSince {
}
}

writeDebug("theFrom=$theFrom, theTo=$theTo");
#writeDebug("theFrom=$theFrom, theTo=$theTo");

my $since = $theTo - $theFrom;
my $isNeg = $since->is_negative;
Expand Down Expand Up @@ -162,10 +160,10 @@ sub handleTimeSince {
$index++;
last if $index >= $theUnits;
}
writeDebug("unit=$unit, count=$count, timestring=$timeString");
#writeDebug("unit=$unit, count=$count, timestring=$timeString");
};

writeDebug("timeString=$timeString");
#writeDebug("timeString=$timeString");

if ($timeString eq '') {
return expandVariables($theNull);
Expand Down Expand Up @@ -194,7 +192,7 @@ sub parseTime {
# NOTE: This routine *will break* if input is not one of below formats!

# FIXME - why aren't ifs around pattern match rather than $5 etc
# try "31 Dec 2001 - 23:59:11" (TWiki date)
# try "31 Dec 2001 - 23:59:11" (Foswiki date)
if ($date =~ /(\d+)\s+([A-Za-z]+)\s+(\d\d\d\d)[\s\-]+(\d+)\:(\d+)(?:\:(\d+))?/) {
my $year = $3;
my $seconds = $6 || 0;
Expand Down Expand Up @@ -343,7 +341,7 @@ sub parseTime {

###############################################################################
sub inlineError {
return '<span class="twikiAlert">' . $_[0] . '</span>' ;
return '<span class="foswikiAlert">' . $_[0] . '</span>' ;
}

###############################################################################
Expand Down
3 changes: 3 additions & 0 deletions lib/Foswiki/Plugins/TimeSincePlugin/MANIFEST
@@ -0,0 +1,3 @@
data/System/TimeSincePlugin.txt 0644
lib/Foswiki/Plugins/TimeSincePlugin.pm 0644
lib/Foswiki/Plugins/TimeSincePlugin/Core.pm 0644
File renamed without changes.
3 changes: 0 additions & 3 deletions lib/TWiki/Plugins/TimeSincePlugin/MANIFEST

This file was deleted.

0 comments on commit 3824320

Please sign in to comment.