Archive of RubyForge sup-devel mailing list
 help / color / mirror / Atom feed
* [sup-devel] [PATCH] Fix problem with time parsing
@ 2011-05-02 22:02 Hamish
  2011-05-10 17:45 ` William Morgan
  0 siblings, 1 reply; 5+ messages in thread
From: Hamish @ 2011-05-02 22:02 UTC (permalink / raw)
  To: sup-devel

[-- Attachment #1: Type: text/plain, Size: 1191 bytes --]

If a message has a date with month first and day second, then if the
day is greater than 12, heliotrope crashes. This patch catches the
error, and tries again after swapping the day and month.
---
 lib/heliotrope/maildir-walker.rb |   14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletions(-)

diff --git a/lib/heliotrope/maildir-walker.rb b/lib/heliotrope/maildir-walker.rb
index db9b9d4..47cb08b 100644
--- a/lib/heliotrope/maildir-walker.rb
+++ b/lib/heliotrope/maildir-walker.rb
@@ -43,7 +43,19 @@ private
       while(l = f.gets)
         if l =~ /^Date:\s+(.+\S)\s*$/
           date = $1
-          pdate = Time.parse($1)
+          begin
+            pdate = Time.parse($1)
+          rescue ArgumentError
+            # flip the day and month around and try again
+            if date =~ %r|(\d\d?)([-./])(\d\d?)([-./])(\d{2,4})|
+              date = $3 + $2 + $1 + $4 + $5
+              pdate = Time.parse(date)
+            else
+              puts "Error while parsing time in file #{fn}"
+              puts "Matched date text was #{date}"
+              pdate = Time.at 0
+            end
+          end
           return pdate
         end
       end
-- 
1.7.4.1

[-- Attachment #2: 0001-Fix-problem-with-time-parsing.patch --]
[-- Type: application/octet-stream, Size: 1387 bytes --]

From 073fead606d4270445c74e9572a91e67c24b4a7a Mon Sep 17 00:00:00 2001
From: Hamish Downer <dmishd@gmail.com>
Date: Mon, 2 May 2011 22:56:17 +0100
Subject: [PATCH] Fix problem with time parsing

If a message has a date with month first and day second, then if the
day is greater than 12, heliotrope crashes. This patch catches the
error, and tries again after swapping the day and month.
---
 lib/heliotrope/maildir-walker.rb |   14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletions(-)

diff --git a/lib/heliotrope/maildir-walker.rb b/lib/heliotrope/maildir-walker.rb
index db9b9d4..47cb08b 100644
--- a/lib/heliotrope/maildir-walker.rb
+++ b/lib/heliotrope/maildir-walker.rb
@@ -43,7 +43,19 @@ private
       while(l = f.gets)
         if l =~ /^Date:\s+(.+\S)\s*$/
           date = $1
-          pdate = Time.parse($1)
+          begin
+            pdate = Time.parse($1)
+          rescue ArgumentError
+            # flip the day and month around and try again
+            if date =~ %r|(\d\d?)([-./])(\d\d?)([-./])(\d{2,4})|
+              date = $3 + $2 + $1 + $4 + $5
+              pdate = Time.parse(date)
+            else
+              puts "Error while parsing time in file #{fn}"
+              puts "Matched date text was #{date}"
+              pdate = Time.at 0
+            end
+          end
           return pdate
         end
       end
-- 
1.7.4.1


[-- Attachment #3: Type: text/plain, Size: 143 bytes --]

_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-05-22 22:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-02 22:02 [sup-devel] [PATCH] Fix problem with time parsing Hamish
2011-05-10 17:45 ` William Morgan
2011-05-10 18:47   ` Hamish
2011-05-11  0:34     ` William Morgan
2011-05-22 22:03       ` Hamish

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox