Hm, you might want to make it backward compatible, not to escape them
if it's already escaped.

=== lib/DateTime/Format/Strptime.pm
==================================================================
--- lib/DateTime/Format/Strptime.pm     (revision 5695)
+++ lib/DateTime/Format/Strptime.pm     (local)
@@ -582,6 +582,7 @@
       my @fields = $field_list =~ m/(%\{\w+\}|%\d*.)/g;
       $field_list = join('',@fields);

+        $regex =~ s/(?<!\\)([\(\)])/\\$1/g;  # escape parens
       my $tempdt = DateTime->now(); # Created just so we can do
$tempdt->can(..)

       # Locale-ize the parser
=== t/008_parens.t
==================================================================
--- t/008_parens.t      (revision 5695)
+++ t/008_parens.t      (local)
@@ -0,0 +1,12 @@
+use strict;
+use warnings;
+use Test::More;
+use DateTime::Format::Strptime;
+
+plan tests => 1;
+
+{
+    my $str = "2006/10/25 (Wed)";
+    my $p   = DateTime::Format::Strptime->new(pattern => "%Y/%m/%d (%a)");
+    ok my $dt  = $p->parse_datetime($str);
+}



On 10/25/06, Tatsuhiko Miyagawa <[EMAIL PROTECTED]> wrote:
Here's a patch for DateTime::Format::Strptime, to allow parsing
strings like "2006/10/25 (Wed)" without the kludge to escape
parenthesis in the format.


=== lib/DateTime/Format/Strptime.pm
==================================================================
--- lib/DateTime/Format/Strptime.pm     (revision 5695)
+++ lib/DateTime/Format/Strptime.pm     (local)
@@ -582,6 +582,7 @@
       my @fields = $field_list =~ m/(%\{\w+\}|%\d*.)/g;
       $field_list = join('',@fields);

+        $regex =~ s/([\(\)])/\\$1/g;  # escape parens
       my $tempdt = DateTime->now(); # Created just so we can do
$tempdt->can(..)

       # Locale-ize the parser
=== t/008_parens.t
==================================================================
--- t/008_parens.t      (revision 5695)
+++ t/008_parens.t      (local)
@@ -0,0 +1,12 @@
+use strict;
+use warnings;
+use Test::More;
+use DateTime::Format::Strptime;
+
+plan tests => 1;
+
+{
+    my $str = "2006/10/25 (Wed)";
+    my $p   = DateTime::Format::Strptime->new(pattern => "%Y/%m/%d (%a)");
+    ok my $dt  = $p->parse_datetime($str);
+}



--
Tatsuhiko Miyagawa



--
Tatsuhiko Miyagawa

Reply via email to