nithinstany / date_diff Goto Github PK
View Code? Open in Web Editor NEWGem which calculates how many years, months and days are there between two dates in ruby on rails
License: MIT License
Gem which calculates how many years, months and days are there between two dates in ruby on rails
License: MIT License
d1 = Date.parse("12-March-2020")
d2 = Date.parse("1-March-2024")
diff = Date.diff(d1, d2)
puts d1 + diff[:year].years + diff[:month].months + diff[:day].days
> Sun, 03 Mar 2024
Shouldn't the resulting date be 1 Mar 2024?
Thanks - I am probably missing something obvious, but suspect it is not taking in to account the leap year days.
Just did a gem update and then attempted the example from the wiki and get the following error: Below is a list of gems installed.
irb(main):001:0> require 'date_diff'
=> true
irb(main):002:0> Date.diff(Date.parse('2000-01-01'), Date.parse('2013-06-19'))
I18n::InvalidLocaleData: can not load translations from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.0/lib/active_support/locale/en.yml: #<NoMethodError: undefined method `load_file' for Psych:Module>
from /usr/local/lib/ruby/gems/2.2.0/gems/i18n-0.7.0/lib/i18n/backend/base.rb:184:in `rescue in load_yml'
from /usr/local/lib/ruby/gems/2.2.0/gems/i18n-0.7.0/lib/i18n/backend/base.rb:181:in `load_yml'
from /usr/local/lib/ruby/gems/2.2.0/gems/i18n-0.7.0/lib/i18n/backend/base.rb:165:in `load_file'
from /usr/local/lib/ruby/gems/2.2.0/gems/i18n-0.7.0/lib/i18n/backend/base.rb:15:in `block in load_translations'
from /usr/local/lib/ruby/gems/2.2.0/gems/i18n-0.7.0/lib/i18n/backend/base.rb:15:in `each'
from /usr/local/lib/ruby/gems/2.2.0/gems/i18n-0.7.0/lib/i18n/backend/base.rb:15:in `load_translations'
from /usr/local/lib/ruby/gems/2.2.0/gems/i18n-0.7.0/lib/i18n/backend/simple.rb:57:in `init_translations'
from /usr/local/lib/ruby/gems/2.2.0/gems/i18n-0.7.0/lib/i18n/backend/simple.rb:40:in `available_locales'
from /usr/local/lib/ruby/gems/2.2.0/gems/i18n-0.7.0/lib/i18n/config.rb:43:in `available_locales'
from /usr/local/lib/ruby/gems/2.2.0/gems/i18n-0.7.0/lib/i18n/config.rb:49:in `available_locales_set'
from /usr/local/lib/ruby/gems/2.2.0/gems/i18n-0.7.0/lib/i18n.rb:278:in `locale_available?'
from /usr/local/lib/ruby/gems/2.2.0/gems/i18n-0.7.0/lib/i18n.rb:284:in `enforce_available_locales!'
from /usr/local/lib/ruby/gems/2.2.0/gems/i18n-0.7.0/lib/i18n.rb:151:in `translate'
from /usr/local/lib/ruby/gems/2.2.0/gems/date_diff-0.0.4/lib/date_diff.rb:41:in `block in diff'
from /usr/local/lib/ruby/gems/2.2.0/gems/date_diff-0.0.4/lib/date_diff.rb:39:in `each'
from /usr/local/lib/ruby/gems/2.2.0/gems/date_diff-0.0.4/lib/date_diff.rb:39:in `diff'
from (irb):2
from /usr/local/bin/irb:11:in `<main>'irb(main):003:0>
> gem list
*** LOCAL GEMS ***
activesupport (4.2.0)
awesome_print (1.6.1, 1.2.0)
bigdecimal (1.2.6)
chronic (0.10.2)
chronic_duration (0.10.6)
colored (1.2)
columnize (0.9.0)
command_line_reporter (3.3.2)
countries (0.9.3)
currencies (0.4.2)
date_diff (0.0.4)
dbd-mysql (0.4.4)
dbd-sqlite3 (1.2.5)
dbi (0.4.5)
deprecated (3.0.1, 2.0.1)
ffi (1.9.6)
i18n (0.7.0)
innate (2013.02.21)
io-console (0.4.3)
json (1.8.2, 1.8.1)
mail (2.6.3)
mailfactory (1.4.0)
mime-types (2.4.3)
minitest (5.5.1, 5.5.0)
mysql (2.9.1)
mysql2 (0.3.17)
numerizer (0.2.0, 0.1.1)
psych (2.0.10, 2.0.8)
rack (1.6.0, 1.5.2)
rake (10.4.2)
ramaze (2012.12.08)
rdoc (4.2.0)
ruby-progressbar (1.7.1)
ruby_info (1.0.1)
sequel (4.18.0, 4.17.0)
span (0.1.2)
sqlite3 (1.3.10)
sqlite3-ruby (1.3.3)
sys-cpu (0.7.1)
sys-filesystem (1.1.3)
sys-host (0.6.2)
sys-uname (0.9.2)
sys-uptime (0.6.2)
terminal-table (1.4.5)
thread_safe (0.3.4)
tzinfo (1.2.2)
unicode (0.4.4.2)
unicode_utils (1.4.0)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.