Calculate the differences between two dates. A few notes:
- It is calendar-correct, meaning that it respects non-30-day months
- It currently only calculates the composite span, meaning that each quantity in the result hash contributes to the total span.
- No external dependencies except the standard library
Add this line to your application's Gemfile:
gem 'span'
And then execute:
$ bundle
Or install it yourself as:
$ gem install span
Span
ships with a single entry point for its API currently: compute
.
require 'span'
end_date = Date.parse '25/03/2013'
start_date = Date.parse '01/01/2012'
result = Span.compute end_date , start_date
puts result[ :year ].inspect # => 1
puts result[ :month ].inspect # => 2
puts result[ :week ].inspect # => 3
puts result[ :day ].inspect # => 4
It returns a Hash
that has four Symbol
keys: :year
, :month
, :week
,
and :day
.
- Add more API options
- Better tests?
- Clean up code to make it easier to contribute
- Fork it ( http://github.com/cookrn/span/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request