[prev in list] [next in list] [prev in thread] [next in thread]
List: ruby-core
Subject: Multi-Line Date Formate Patch
From: James Edward Gray II <james () grayproductions ! net>
Date: 2006-07-31 13:26:56
Message-ID: 58CAEE8D-863C-4490-97AB-4FA79C1985B2 () grayproductions ! net
[Download RAW message or body]
It was pointed out to me that the following code is surprising:
require "date"
Time.now.strftime("foo\nbar\n") # => "foo\nbar\n"
DateTime.now.strftime("foo\nbar\n") # => "foobar"
This happens because date/format.rb uses a . in a regular expression
to match all non-escape characters of the format pattern and thus
cannot pick-up newlines. Below is my one character patch to resolve
this issue.
Thanks.
James Edward Gray II
Index: lib/date/format.rb
===================================================================
RCS file: /src/ruby/lib/date/format.rb,v
retrieving revision 1.12
diff -u -r1.12 format.rb
--- lib/date/format.rb 6 Feb 2005 05:05:18 -0000 1.12
+++ lib/date/format.rb 31 Jul 2006 13:20:37 -0000
@@ -490,7 +490,7 @@
def strftime(fmt='%F')
o = ''
- fmt.scan(/%[EO]?.|./o) do |c|
+ fmt.scan(/%[EO]?.|./mo) do |c|
cc = c.sub(/^%[EO]?(.)$/o, '%\\1')
case cc
when '%A'; o << DAYNAMES[wday]
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic