Code Monkey home page Code Monkey logo

ruby-american_date's Introduction

ruby-american_date

ruby-american_date exists to make ruby 1.9+ parse american-style month/day/year dates correctly, with behavior matching ruby 1.8.7. It can also be used on earlier ruby version, but it is basically a noop there.

As far as I know, there isn’t a gem that already handles this. You can find many snippets on the web that partially solve the issue, but most won’t be compatible with ruby 1.9.3, because Date.parse and DateTime.parse no longer call Date._parse directly on 1.9.3. Also most don’t handle cases where an american date format is used in addition to a time format.

Note that this gem only handles / separated dates. It does not handle - or . separated dates. This is by design, for compatibility with ruby 1.8.7.

Design

The general idea is fairly simple. We look for a month/day/year substring in the input string, and if we find it, we transform it into a year-month-day ISO format string before passing it to the standard date parsing methods. This is probably the least invasive way that works correctly on both the pure-ruby date parser (<1.9.3) and the C extension date parser (>=1.9.3).

Tested ruby versions

  • ruby 1.8.6, 1.8.7, 1.9.2, 1.9.3, 2.0.0, 2.1.0

  • rubinius 1.2.4, 2.2.6

  • jruby 1.6.5, 1.7.9 (both –1.8 and –1.9 modes)

Installation

ruby-american_date is distributed as a gem, and can be installed with:

gem install american_date

Source

ruby-american_date is hosted on GitHub:

https://github.com/jeremyevans/ruby-american_date

Issues

ruby-american_date uses GitHub Issues for issue tracking:

https://github.com/jeremyevans/ruby-american_date/issues

Author

Jeremy Evans <[email protected]>

ruby-american_date's People

Contributors

jeremyevans avatar sd avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.