Archive of RubyForge sup-devel mailing list
 help / color / mirror / Atom feed
From: Hamish <dmishd@gmail.com>
To: sup-devel <sup-devel@rubyforge.org>
Subject: [sup-devel] [PATCH] Fix problem with time parsing
Date: Mon, 02 May 2011 23:02:43 +0100	[thread overview]
Message-ID: <1304373710-sup-1383@whisper> (raw)

[-- 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

             reply	other threads:[~2011-05-02 22:03 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-02 22:02 Hamish [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1304373710-sup-1383@whisper \
    --to=dmishd@gmail.com \
    --cc=sup-devel@rubyforge.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox