• Do not register here on develop.twiki.org, login with your twiki.org account.
• Use View topic Item7848 for generic doc work for TWiki-6.1.1. Use View topic Item7851 for doc work on extensions that are not part of a release. More... Close
• Anything you create or change in standard webs (Main, TWiki, Sandbox etc) will be automatically reverted on every SVN update.
Does this site look broken?. Use the LitterTray web for test cases.

Item6219: TablePlugin: Sort ISO dates

Item Form Data

AppliesTo: Component: Priority: CurrentState: WaitingFor: TargetRelease ReleasedIn
Extension TablePlugin Normal New   n/a  

Edit Form Data

Reported By:
Applies To:
Current State:
Waiting For:
Target Release:
Released In:


See patch provided at TWiki:Plugins/TablePluginDev by TWiki:Main/UlrichSpoerlein - 21 Mar 2009

-- TWiki:Main/PeterThoeny - 22 Mar 2009

The patch is slightly incorrect as months run from 0..11 International ISO format is also YYYY-MM-DD.

--- lib/TWiki/Plugins/TablePlugin/Core.pm.orig  2010-04-21 22:39:57.000000000 +0100
+++ lib/TWiki/Plugins/TablePlugin/Core.pm       2010-04-21 23:17:13.000000000 +0100
@@ -533,6 +533,13 @@
         $year += 2000 if ( length($year) == 2 );
         $date = timegm( 0, 0, 0, $1, $mon2num{$2}, $year - 1900 );
+    elsif ( $text =~
+        m|^\s*([0-9]{4})[-/\s]([0-9]{2})[-/\s]([0-9]{2})\s*$| )
+    {
+        # ISO "2003-12-31" "2003 12 31" "2003/12/31"
+        $date = timegm( 0, 0, 0, $3, $2 - 1, $1 - 1900 );
+    }
     elsif ( $text =~ /^\s*([0-9]+)(\.([0-9]))*(.?)*$/ ) {

         # for example for attachment sizes: 1.1 K

-- TWiki:Main.AlexSchuilenburg - 21 Apr 2010

I believe this has been fixed in Item6414, could you verify if TWikirev:18412 is correct?

-- TWiki:Main.PeterThoeny - 24 Apr 2010

TWikirev:18412 will work, but IMHO is broken because it will incorrectly accept something like "2010-012-31999999999999999" as a valid date and return christmas day as the value. It lacks the trailing "\s*$", which means it may interpret a bar code as a date. Also there are two totally unnecessary "0?"' matches in the regexp which do nothing to help verify the field as an ISO date (in fact, even with a trailing "\s*$" added, they make the submission of 9999-099-099 possible, as well as single digit month and days, both not permissible by the ISO 8601 standard. My proposed patch is IMHO a lot more accurate than TWikirev:18412

-- TWiki:Main.AlexSchuilenburg - 25 Apr 2010

Your proposed patch is more accurate to parse valid ISO dates, but it is not that forgiving. ISO dates are frequently created by humans, especially in TWiki. There is a reason for stripping off the leading 0: Perl interprets a string as an octal number if it starts with a zero. The regex could be tweaked to allow 1 to 2 digits, and to remove a leading 0. As for not anchoring at the end, this is done by design so that date sorting works also if followed by time (albeit without sorting the time). This can be made more robust, such as testing for a non-numeric character at the end of the regex. Untested regex:


-- TWiki:Main.PeterThoeny - 25 Apr 2010

Summary TablePlugin: Sort ISO dates
ReportedBy TWiki:Main.PeterThoeny

SVN Range TWiki-5.0.0, Mon, 23 Feb 2009, build 17838
AppliesTo Extension
Component TablePlugin
Priority Normal
CurrentState New


TargetRelease n/a

Edit | Attach | Watch | Print version | History: r6 < r5 < r4 < r3 < r2 | Backlinks | Raw View |  Raw edit | More topic actions
Topic revision: r6 - 2010-04-25 - PeterThoeny
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2021 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback