Giter Club home page Giter Club logo

date-casually's Introduction

DateCasually

If you’ve always expected the Rails date helpers to say “Today”, “Yesterday” or “10 days ago” when asked about a specific date, then it’s time to date casually.

I’ve never liked (and always seem to forget) the name of the Rails distance_of_time_in_words_to_now helper method. Additionally it doesn’t handle obvious translations such as “today”, “tomorrow” or “yesterday” and doesn’t determine if a date is in the future (“10 days from now”) or the past (“10 days ago”).

Quick Examples

Date.today.casual 
  #=> 'today'

(Date.today + 1).casual 
  #=> 'tomorrow'

(Date.today - 1).casual 
  #=> 'yesterday'

The :as option

If you’d like to change what increments of time DateCasually returns you can use the :as option.

(Date.today + 12).casual(:as => :days) 
  #=> '12 days from now'

You can also pass in multiple options:

(Date.today + 1).casual(:as => [ :months, :years ]) 
  #=> 'less than a month from now'

The default :as options for DatCasually are:

(Date.today + 1).casual(:as => [:days, :weeks, :months, :years])

If you’d change DateCasually globally, do this:

DateCasually::Config.as = :months, :years

i18n

DateCasually hooks into the i18n gem, but currently only supports English.

Dependencies

  • i18n

  • chronic (only used in the test suite)

  • timecop (only used in the test suite)

date-casually's People

Contributors

twmills avatar

Stargazers

Michael Powell avatar Michael Nissim avatar Andrew Vos avatar  avatar

Watchers

Palpandi R avatar  avatar James Cloos avatar

Forkers

mbrock

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.