Invalid string for Date.parse

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

[ruby-core:11860]e$B$K$h$l$P!"e(B1.8.6(e$B$He(Btrunk)e$B$G$Oe(B

% ruby -r date -e ‘p Date.parse(“junk”).to_s’
“2007-06-01”

e$B$H$J$j$^$9!#$I$&$b!“e(Bjune$B$G$O$8$^$C$F$$$k$N$Ge(B6e$B7n$H$_$J$7$F$$$ke(B
e$B$h$&$G$9!#0JA0$O%(%i!<$K$J$C$F$$$?$N$G!”$3$l$O$"$^$jK>$^$7$$e(B
e$B;EMMJQ99$G$O$J$$$H;W$$$^$9!#e(B

[email protected]$G$9!#e(B

At Wed, 8 Aug 2007 15:42:33 +0900,
Yukihiro M. wrote in [ruby-dev:31357]:

[ruby-core:11860]e$B$K$h$l$P!"e(B1.8.6(e$B$He(Btrunk)e$B$G$Oe(B

% ruby -r date -e ‘p Date.parse(“junk”).to_s’
“2007-06-01”

e$B$H$J$j$^$9!#$I$&$b!“e(Bjune$B$G$O$8$^$C$F$$$k$N$Ge(B6e$B7n$H$_$J$7$F$$$ke(B
e$B$h$&$G$9!#0JA0$O%(%i!<$K$J$C$F$$$?$N$G!”$3$l$O$"$^$jK>$^$7$$e(B
e$B;EMMJQ99$G$O$J$$$H;W$$$^$9!#e(B

e$B$H$j$"$($:A4Ite(B\be$B$He(Boe$B%*%W%7%g%s$rIU$1$F$_$^$7$?!#e(B

Index: lib/date/format.rb

— lib/date/format.rb (revision 12899)
+++ lib/date/format.rb (working copy)
@@ -404,12 +404,12 @@ class Date
case s
when ‘A’, ‘a’

  • return unless str.sub!(/\A(#{Format::DAYS.keys.join(’|’)})/io, ‘’)
    ||
  •  str.sub!(/\A(#{Format::ABBR_DAYS.keys.join('|')})/io, '')
    
  • return unless str.sub!(/\A(#{Format::DAYS.keys.join(’|’)})\b/io,
    ‘’) ||
  •  str.sub!(/\A(#{Format::ABBR_DAYS.keys.join('|')})\b/io, '')
    
    val = Format::DAYS[$1.downcase] || Format::ABBR_DAYS[$1.downcase]
    return unless val
    e.wday = val
    when ‘B’, ‘b’, ‘h’
  • return unless str.sub!(/\A(#{Format::MONTHS.keys.join(’|’)})/io,
    ‘’) ||
  •  str.sub!(/\A(#{Format::ABBR_MONTHS.keys.join('|')})/io, '')
    
  • return unless str.sub!(/\A(#{Format::MONTHS.keys.join(’|’)})\b/io,
    ‘’) ||

  •  str.sub!(/\A(#{Format::ABBR_MONTHS.keys.join('|')})\b/io, '')
    

    val = Format::MONTHS[$1.downcase] ||
    Format::ABBR_MONTHS[$1.downcase]
    return unless val
    @@ -685,5 +685,5 @@ class Date

    def self._parse_day(str, e) # :nodoc:

  • if str.sub!(/\b(#{Format::ABBR_DAYS.keys.join(’|’)})[^-\d\s]*/in, ’
    ')
  • if
    str.sub!(/\b(#{Format::ABBR_DAYS.keys.join(’|’)})\b[^-\d\s]/ion, ’ ‘)
    e.wday = Format::ABBR_DAYS[$1.downcase]
    true
    @@ -774,5 +774,5 @@ class Date
    /’?(\d+)[^-\d\s]

    \s*
  • (#{Format::ABBR_MONTHS.keys.join('|')})[^-\d\s']*
    
  • (#{Format::ABBR_MONTHS.keys.join('|')})\b[^-\d\s']*
    (?:
      \s*
    

@@ -781,5 +781,5 @@ class Date
(’?-?\d+(?:(?:st|nd|rd|th)\b)?)
)?

  • /inx,
  • /ionx,
    ’ ') # ’
    s3e(e, $4, Format::ABBR_MONTHS[$2.downcase], $1,
    @@ -791,5 +791,5 @@ class Date
    def self._parse_us(str, e) # :nodoc:
    if str.sub!(
  • /\b(#{Format::ABBR_MONTHS.keys.join(’|’)})[^-\d\s’]*
  • /\b(#{Format::ABBR_MONTHS.keys.join(’|’)})\b[^-\d\s’]*
    \s*
    (’?\d+)[^-\d\s’]*
    @@ -800,5 +800,5 @@ class Date
    (’?-?\d+)
    )?
  • /inx,
  • /ionx,
    ’ ') # ’
    s3e(e, $4, Format::ABBR_MONTHS[$1.downcase], $2,
    @@ -854,10 +854,10 @@ class Date

def self._parse_vms(str, e) # :nodoc:

  • if str.sub!(/(’?-?\d+)-(#{Format::ABBR_MONTHS.keys.join(’|’)})[^-]*
  • -(’?-?\d+)/inx, ’ ')
  • if
    str.sub!(/(’?-?\d+)-(#{Format::ABBR_MONTHS.keys.join(’|’)})\b[^-]*
  • -(’?-?\d+)/ionx, ’ ')
    s3e(e, $3, Format::ABBR_MONTHS[$2.downcase], $1)
    true
  • elsif str.sub!(/\b(#{Format::ABBR_MONTHS.keys.join(’|’)})[^-]*
  • -(’?-?\d+)(?:-(’?-?\d+))?/inx, ’ ')
  • elsif str.sub!(/\b(#{Format::ABBR_MONTHS.keys.join(’|’)})\b[^-]*
  • -(’?-?\d+)(?:-(’?-?\d+))?/ionx, ’ ')
    s3e(e, $3, Format::ABBR_MONTHS[$1.downcase], $2)
    true
    @@ -887,5 +887,5 @@ class Date

def self._parse_mon(str, e) # :nodoc:

  • if str.sub!(/\b(#{Format::ABBR_MONTHS.keys.join(’|’)})\S*/in, ’ ')
  • if str.sub!(/\b(#{Format::ABBR_MONTHS.keys.join(’|’)})\b\S*/ion, ’
    ')
    e.mon = Format::ABBR_MONTHS[$1.downcase]
    true

e$B$H$J$j$^$9!#$I$&$b!“e(Bjune$B$G$O$8$^$C$F$$$k$N$Ge(B6e$B7n$H$_$J$7$F$$$ke(B
e$B$h$&$G$9!#0JA0$O%(%i!<$K$J$C$F$$$?$N$G!”$3$l$O$"$^$jK>$^$7$$e(B
e$B;EMMJQ99$G$O$J$$$H;W$$$^$9!#e(B

e$B$=$l$re(B6e$B7n$H8+Jo$9$N$O!"0JA0$+$i$N$3$H$G$9$,!"7nL>C1BN$G$b<u$1$H$l$k$he(B
e$B$&$K$J$C$?$3$H$,JQ$C$F$$$^$9!#$^$?!"0JA0$O!“G/7nF|$,B7$C$F$$$J$$$H%(%i!<e(B
e$B$K$7$F$$$^$7$?$,!”:#$O!"e(BTime.parse
e$B$N;EMM$K6a$$?6Iq$$$K$J$C$F$$$^$9!#e(B

e$BKM<+?H$O!“e(Bparse
e$B$O!“F|IU$r8!>Z$9$k$3$H$OA4$/L\E*$H$7$F$$$J$$$H9M$($F$$e(B
e$B$^$9!#$=$&$$$&$3$H$r$”$^$j:Y$+$/[email protected][email protected]$9$H!”:#$Ne(B parse
e$B$N$"$jJ}<+BN$,e(B
[email protected]$H$$$&$3$H$K$J$j$^$9!#e(B

$ ruby -vr time -e “p Time.parse(‘2 light years ago’)”
ruby 1.8.6 (2007-06-07 patchlevel 36) [i386-freebsd6.2]
Wed Aug 08 19:00:12 +0900 2007

Time.parse
e$B$J$I$O!“0JA0$+$i!”$J$s$iF|IU$i$7$5$,$J$$$b$N$G$b%(%i!<$K$Je(B
e$B$j$^$;$s!#$7$+$7!“e(BDate.parse
e$B$K$D$$$F!”$I$&$7$F$b$=$3$^[email protected]$,I,e(B
[email protected]$H$$$&$J$i!"85$KLa$9$N$,$$$$$G$7$g$&!#e(B

e$B$G!"[email protected]$5$s$N%Q%C%A$O!"e(B’Sept 23’
e$B$N$h$&$JF|IU$bH]Dj$7$F$7$^$&$N$G5Qe(B
e$B2<$5$;$F$b$i$$$^$9!#e(B

e$B$=$l$H!"$D$$$G$G$9$,!"e(B[ruby-dev:31309]
e$B$N7o!"D>$9$+!"D>$;$J$$$N$J$i!"e(B
e$B85$KLa$7$F$[$7$$$N$G$9$,!#54<V$N:G?7HG$N%P%[email protected]$H;W$$$^$9!#e(B

[email protected]$G$9!#e(B

At Wed, 8 Aug 2007 20:12:04 +0900,
Tadayoshi F. wrote in [ruby-dev:31359]:

e$B$G!"[email protected]$5$s$N%Q%C%A$O!"e(B’Sept 23’ e$B$N$h$&$JF|IU$bH]Dj$7$F$7$^$&$N$G5Qe(B
e$B2<$5$;$F$b$i$$$^$9!#e(B

Septe$B$H$$$&$N$O$"$k$+$b$7$l$^$;$s$,!“e(BSeptee$B$H$+e(BSepteme$B$H$+e(BSeptembe$B$_e(B
e$B$?$$$N$b$”$j$G$7$g$&$+!#$b$7e([email protected]$15vMF$9$k$N$G$"$le(B
e$B$P!"$=$l$be(BABBR_MONTHSe$B$KDI2C$9$l$P$$$$$N$G$O$J$$$+$H;W$$$^$9$,!#e(B

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:31359] Re: invalid string for Date.parse”
on Wed, 8 Aug 2007 20:12:04 +0900, Tadayoshi F. [email protected]
writes:

|> e$B$H$J$j$^$9!#$I$&$b!“e(Bjune$B$G$O$8$^$C$F$$$k$N$Ge(B6e$B7n$H$_$J$7$F$$$ke(B
|> e$B$h$&$G$9!#0JA0$O%(%i!<$K$J$C$F$$$?$N$G!”$3$l$O$"$^$jK>$^$7$$e(B
|> e$B;EMMJQ99$G$O$J$$$H;W$$$^$9!#e(B
|
|e$B$=$l$re(B6e$B7n$H8+Jo$9$N$O!"0JA0$+$i$N$3$H$G$9$,!"7nL>C1BN$G$b<u$1$H$l$k$he(B
|e$B$&$K$J$C$?$3$H$,JQ$C$F$$$^$9!#$^$?!"0JA0$O!“G/7nF|$,B7$C$F$$$J$$$H%(%i!<e(B
|e$B$K$7$F$$$^$7$?$,!”:#$O!"e(BTime.parse e$B$N;EMM$K6a$$?6Iq$$$K$J$C$F$$$^$9!#e(B

e$B$U$`!#$=$&$$$&$3$H$G$9$+!#7nL>C1BN$r<u$1IU$1$k$K$J$C$?I{:nMQe(B
e$B$H!#!Ve(BSepe$B$Oe(BOKe$B$Ge(BSepte$B$O%@%a!W$H$$$&$N$,[email protected]$&$N$O$$C$7$ce(B
e$B$kDL$j$G$9$M!#M}A[$r$$$($Pe(BSepe$B0J>e$Ge(BSeptembere$B$N0lIt$G$"$k$b$Ne(B
[email protected]$1$,e(Bvalide$B$H$9$k$N$,NI$$$N$G$7$g$&$,!"$=$l$O%3%9%HE
[email protected]^$je(B
[email protected]$m$&$H$$$&$N$bJ,$+$j$^$9!#e(B

|Time.parse e$B$J$I$O!“0JA0$+$i!”$J$s$iF|IU$i$7$5$,$J$$$b$N$G$b%(%i!<$K$Je(B
|e$B$j$^$;$s!#$7$+$7!“e(BDate.parse e$B$K$D$$$F!”$I$&$7$F$b$=$3$^[email protected]$,I,e(B
|[email protected]$H$$$&$J$i!"85$KLa$9$N$,$$$$$G$7$g$&!#e(B

e$B$$$($$$(!";v>p$,J,$+$l$PL5M}$O$$$$$^$;$s!#@hJ}$K$O$=$N;]EA$(e(B
e$B$F$*$-$^$7$g$&!#e(B

|e$B$=$l$H!"$D$$$G$G$9$,!"e(B[ruby-dev:31309] e$B$N7o!"D>$9$+!"D>$;$J$$$N$J$i!"e(B
|e$B85$KLa$7$F$[$7$$$N$G$9$,!#54<V$N:G?7HG$N%P%[email protected]$H;W$$$^$9!#e(B

e$BD>$9$h$&$KEXNO$7$F$^$9$,!"$^[email protected]$7$F$^$;$s!#85$KLa$9$He(B
Unicodee$B<~$j$N?<9o$J%P%0$rI|3h$5$;$k$N$Gm4m0$7$F$^$9!#$3$l$be(B
e$B==J,?<9o$J$N$G$9$,!#e(B

                            e$B$^$D$b$He(B e$B$f$-$R$me(B /:|)

Septe$B$H$$$&$N$O$"$k$+$b$7$l$^$;$s$,!“e(BSeptee$B$H$+e(BSepteme$B$H$+e(BSeptembe$B$_e(B
e$B$?$$$N$b$”$j$G$7$g$&$+!#$b$7e([email protected]$15vMF$9$k$N$G$"$le(B
e$B$P!"$=$l$be(BABBR_MONTHSe$B$KDI2C$9$l$P$$$$$N$G$O$J$$$+$H;W$$$^$9$,!#e(B

[email protected]$H;W$$$^$9!#[email protected]!"$=$b$=$b8!>Z$NLr$KN)$D$h$&$Ke(B
e$B=PMh$F$$$^$;$s!#[email protected]$+$i!"[email protected]$1BP=h$7$F$b!"$"$^$j0UL#$,$"$k$h$&$K;W$oe(B
e$B$l$^$;$s!#$3$l$O2]Bj$N0lIt$G$7$+$J$$$H;W$$$^$9!#e(B

e$B8!>Z$NLr$KN)$F$?$$$J$i$P!“0JA0e(B rbison (e$B:#$J$ie(B racc e$B$+e(B)
e$B$G=q$$$?e(B
parsedate2
e$B$N$[$&$,$d$j$d$9$$$H;W$$$^$9$,!#$G$b!”$=$l$O$=$l$G!"$^$?JLe(B
e$B$N$$$/$D$b$N2][email protected]$k$3$H$K$J$kH&$G$9!#CY$/$J$k$7!"$0$C$HBP>]$r9J$j$3e(B
e$B$`$3$H$K$J$k$H;W$$$^$9!#e(B

e$B$G!“F1$8$h$&$J2]Bj$,$”$C$F$b!"$J$<$+2r7h$re(B Time
e$B$G$O$J$/!"e(BDate e$B$K5a$ae(B
e$B$i$l$k$3$H$,B?$$$h$&$J5$$,$9$k$N$G$9$,!"2?8N!"e(BTime.parse
e$B$K$O5?Ld$r$be(B
e$B$?$l$J$$$N$+$J!#EDCf$5$s$,F10U$9$k$J$i!"e(BTime
e$B$N$[$&[email protected]$:HO$r<($7$F$/e(B
e$B$l$F$b$$$$$H;W$$$^$9!#e(B

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:31369] Re: invalid string for Date.parse”
on Thu, 9 Aug 2007 08:52:51 +0900, Tanaka A. [email protected]
writes:

|e$BLdBj$O!"==J,$KB?$/$N?M$,G<[email protected]$G$-$kF|IU$NDj5A$O2DG=$+!"$H$$$&e(B
|e$B$H$3$m$K$"$k$H;W$&$N$G!"J86g$r$$$C$F$/$k?M$K$O$=$NDj5A$r?R$Me(B
|e$B$l$P$$$$$s$8$c$J$$$G$7$g$&$+!#$b$7G<[email protected][email protected]$i$7$$Ez$($,e(B
|e$BJV$C$F$-$?$i$<$R:NMQ$7$^$7$g$&!#e(B

[ruby-core:11866]e$B$N$h$&$K!V9W8%[email protected]$m$&$+!W$H9M$($F$$$ke(B
e$B?M$O$$$k$N$G!"Cf$K$ODj5A$r;}$C$F$$$k?M$,$$$k$+$b$7$l$^$;$s!#e(B
e$B8=;[email protected]$G$Oe(B

http://search.cpan.org/~gbarr/TimeDate-1.16/

e$B$NDj5A$,;29M$K$J$k$N$G$O$J$$$+e(B[ruby-core:11870]e$B$/$i$$$7$+8+e(B
e$B$+$1$^$;$s$1$l$I!#$G!“e(BPerle$B$Ne(BTimeDatee$B$Ne(Bparsee$B$,;H$$J*$K$J$k$+e(B
e$B$I$&$+!”$"$k$$$O!VG<[email protected]$G$-$kEz$(!W$J$N$+$I$&$+!"8=;[email protected]$G$O;de(B
e$B$K$OJ,$+$j$^$;$s!#e(B

                            e$B:G6aDLLu78!)e(B
                            e$B$^$D$b$He(B e$B$f$-$R$me(B /:|)

In article [email protected],
Tadayoshi F. [email protected] writes:

e$B$G!“F1$8$h$&$J2]Bj$,$”$C$F$b!"$J$<$+2r7h$re(B Time e$B$G$O$J$/!"e(BDate e$B$K5a$ae(B
e$B$i$l$k$3$H$,B?$$$h$&$J5$$,$9$k$N$G$9$,!"2?8N!"e(BTime.parse e$B$K$O5?Ld$r$be(B
e$B$?$l$J$$$N$+$J!#e(B

e$B%I%-%e%a%s%H$Ke(B Date._parse e$B$,<:GT$7$?$i<:GT$7$^$9!"$C$F=q$$e(B
e$B$F$"$k$+$i$+$J$!!#e(B

e$BEDCf$5$s$,F10U$9$k$J$i!"e(BTime e$B$N$[$&[email protected]$:HO$r<($7$F$/e(B
e$B$l$F$b$$$$$H;W$$$^$9!#e(B

e$BLdBj$O!"==J,$KB?$/$N?M$,G<[email protected]$G$-$kF|IU$NDj5A$O2DG=$+!"$H$$$&e(B
e$B$H$3$m$K$"$k$H;W$&$N$G!"J86g$r$$$C$F$/$k?M$K$O$=$NDj5A$r?R$Me(B
e$B$l$P$$$$$s$8$c$J$$$G$7$g$&$+!#$b$7G<[email protected][email protected]$i$7$$Ez$($,e(B
e$BJV$C$F$-$?$i$<$R:NMQ$7$^$7$g$&!#e(B

e$B$^$!!"$=$&$$$&Ez$($O$"$j$=$&$K$J$$$N$G!“J86g$r$$$C$F$/$k?M$Ke(B
e$B$OMQES$r?R$M$F!“F1$8MQES$,$$$m$s$J?M$+$i=P$F$/$k$h$&$J$ie(B
Time.rfc2822 e$B$N$h$&$JFCDjMQES8~$1%a%=%C%I$r3H=<$7$F$$$1$P$$e(B
e$B$$$s$8$c$J$$$+$H;W$C$F$^$9$,!#$”$H$Oe(B strptime e$B$r4+$a$k$H$$$&e(B
e$B<j$b$”$k$+$J!#e(B

In article [email protected],
Yukihiro M. [email protected] writes:

[ruby-core:11866]e$B$N$h$&$K!V9W8%[email protected]$m$&$+!W$H9M$($F$$$ke(B
e$B?M$O$$$k$N$G!"Cf$K$ODj5A$r;}$C$F$$$k?M$,$$$k$+$b$7$l$^$;$s!#e(B

e$BDj5A$,=P$F$-$?$i9M$($^$7$g$&!#e(B

e$B8=;[email protected]$G$Oe(B

http://search.cpan.org/~gbarr/TimeDate-1.16/

e$B$NDj5A$,;29M$K$J$k$N$G$O$J$$$+e(B[ruby-core:11870]e$B$/$i$$$7$+8+e(B
e$B$+$1$^$;$s$1$l$I!#$G!“e(BPerle$B$Ne(BTimeDatee$B$Ne(Bparsee$B$,;H$$J*$K$J$k$+e(B
e$B$I$&$+!”$"$k$$$O!VG<[email protected]$G$-$kEz$(!W$J$N$+$I$&$+!"8=;[email protected]$G$O;de(B
e$B$K$OJ,$+$j$^$;$s!#e(B

e$B;d$bJ,$+$j$^$;$s$N$G!"C/$+J,$+$k$H<gD%$9$k?M$,=P$F$-$?$i9M$(e(B
e$B$^$7$g$&!#e(B