Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for MM-DD-YYYY? #1

Closed
rymohr opened this issue May 22, 2012 · 7 comments
Closed

Support for MM-DD-YYYY? #1

rymohr opened this issue May 22, 2012 · 7 comments

Comments

@rymohr
Copy link

rymohr commented May 22, 2012

I noticed the library only recognizes MM/DD/YYYY and not MM-DD-YYYY. Any plans to support the latter?

@jeremyevans
Copy link
Owner

No. American dates are always separated with slashes in my experience (Wikipedia seems to agree). There may be users that want MDY for slash separated dates and DMY for dash separated dates. However, if you want to support dash-separated dates as well as slash separated dates, here's a quick hack that should work:

require 'american_date'
class << Date
  remove_const(:AMERICAN_DATE_RE)
  AMERICAN_DATE_RE = %r_\A\s*(\d{1,2})[-/](\d{1,2})[-/](\d{4}|\d{2})_.freeze
end

@rymohr
Copy link
Author

rymohr commented May 22, 2012

Thanks

@ericboehs
Copy link

Thanks Jeremy for the recommendation. I definitely wanted dash support as well. I've added the recommend patch for now.

FWIW: The chronic gem parses both formats american style.

@ghost
Copy link

ghost commented Sep 21, 2012

Wikipedia has this to say about American date formats. Emphasis added:

Middle-endian, starting with month (Month-Day-Year)

This sequence is used primarily in the United States, partially in Canada, and a few other countries[citation needed]. This date format was commonly used alongside the small endian form in the United Kingdom until the early 20th Century, and can be found in both defunct and modern print media such as the London Gazette and The Times, respectively. In the UK, it would be verbally expressed as Sunday, November the 9th, whereas in the United States, it is usually Sunday, November 9th, although usage of "the" isn't uncommon.

  • Sunday, November 9, 2003
  • November 9, 2003
  • Nov. 9, 2003 or 11/9/2003
  • 11-9-2003, 11.9.2003, 11.09.03, or 11/09/03

There is nothing particularly American about slashes -- a gem that aims to be usable for most applications should support arbitrary delimiters.

@jeremyevans
Copy link
Owner

I think you are quoting Wikipedia out of context, see http://en.wikipedia.org/wiki/Date_and_time_notation_in_the_United_States, which only mentions slash separated middle endian dates. Middle-endian date format may used with other delimiters in other countries, but in the USA, it is very rare to see dates in America use something other than a slash for middle endian dates, in my experience (I can't recall a single example). Looking at http://en.wikipedia.org/wiki/Date_format_by_country, I don't see a single middle endian date example using something other than a slash delimiter.

I've already posted a trivial monkey patch to get the behavior you want. Please use that if you want to handle non-slash delimiters.

@jeremyevans
Copy link
Owner

Also, FWIW, american_date reflects ruby 1.8 behavior:

$ ruby18  -r date -e 'puts Date.parse("11.08.2005").to_s'
2005-08-11
$ ruby18  -r date -e 'puts Date.parse("11-08-2005").to_s'
2005-08-11
$ ruby18  -r date -e 'puts Date.parse("11/08/2005").to_s'
2005-11-08

Considering the first sentence of the README, "ruby-american_date exists to make ruby versions greater than 1.8 parse american-style month/day/year dates correctly, just like ruby 1.8.", I think the current behavior makes sense and don't plan to change it.

@ghost
Copy link

ghost commented Sep 21, 2012

Totally understand the 1.8 support -- that makes sense, and we'll end up having to just use our forked version of the gem.

But neither Wikipedia nor your memory should determine which date delimiters are worth supporting -- the final authority should be application users. And a cursory search will turn up plenty of examples of users using dashes in American dates. Here's one from the U.S. government: http://www.nasa.gov/directorates/heo/reports/iss_reports/2012/05032012.html.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants