Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Date#parse assume a EU format - can it assume a US format?

Reply
Thread Tools

Date#parse assume a EU format - can it assume a US format?

 
 
Josh Sharpe
Guest
Posts: n/a
 
      09-21-2010
Before you jump to an answer here, please don't suggest that I use
_strptime. Going that route forces my users to give me the date and/or
time in the format that I specify. Which is really not optimal.

So the problem is that Date#parse assumes that the format is
day/month/year. I would like to make it assume that it is in the US
format, month/day/year.

After digging into format.rb I tried this:

class Date
def _parse_eu(str, e)
_parse_us(str,e)
end
end

... in an attempt to skip the parse_eu method.... that solution doesn't
exactly work:

ruby-1.9.2-p0 > Date.parse("10/04/2010")
=> Sat, 10 Apr 2010

So, it's still using the EU format. Any other suggestions??

Thanks!
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Brian Candler
Guest
Posts: n/a
 
      09-21-2010
Josh Sharpe wrote:
> Before you jump to an answer here, please don't suggest that I use
> _strptime. Going that route forces my users to give me the date and/or
> time in the format that I specify. Which is really not optimal.
>
> So the problem is that Date#parse assumes that the format is
> day/month/year.


It is U.S. middle-endian format in 1.8.7. But try this monkey-patch for
1.9.2:

require 'date'
def Date._parse_sla(str, e) # :nodoc:
if str.sub!(%r|('?-?\d+)/\s*('?\d+)(?:\D\s*('?-?\d+))?|, ' ') # '
s3e(e, $2, $1, $3)
true
end
end

>> Date.parse("10/04/2010")

=> #<Date: 2010-10-04 (4910947/2,0,2299161)>
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can I assume fgets won't modify last bytes of output array if unused ? Francis Moreau C Programming 17 01-04-2011 01:33 AM
Assume program under constant attack Tomás Ó hÉilidhe C Programming 7 01-22-2008 07:46 PM
Can I assume the memory is continuous? linq936 C++ 21 09-19-2007 12:12 PM
The CIT200 VOIP phone I bought will not establish connection to the USB base. It just beeps - busy signal I assume. Carl Rossman VOIP 0 03-16-2007 10:29 PM
Is it safe to assume default value from dynamic memory allocation? howa C++ 7 12-03-2006 07:44 AM



Advertisments