date_duration 1.0.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: adf0ad34fe0118987dc3edde7238e89e1967c4bab7a8be34ad4fd58a3142c46d
4
- data.tar.gz: 306a2251872431901dcd5ef5cf72b71c6b1acb63858b5c08172879cc9e88f2c8
3
+ metadata.gz: 756214117c04405a153c9214dd750baa6e606954b6b4c6a5a3a62638f646c898
4
+ data.tar.gz: afa6cbe9a80ff30a4f68a8df23c8a6e2c1b11fd04fcfb3d2655a82d159eda7b8
5
5
  SHA512:
6
- metadata.gz: 9b4c850559c69be34b74cba7c18657f0315ed935e9ec14e972abbe11e18087a2b9bf2c8313aa33499b14420b948686950bcf80cf288d8909c73bc1911ca2a936
7
- data.tar.gz: 9c1e7e03feef14dcbc3de865b15ed74734dd893d0eaa12bea442b09e7f510241b931723bdb54808d20d1794773050436ab12a89fd42023cb0e244250e9961265
6
+ metadata.gz: 18f699eaf8494dc7c0d2e7e157ec61bcf34a0d28a88ca4f330eeeba0e1a86026fe5be20974068086d1f2f57ab235c56eadff2d6cf544f8b0b0090da0f6e445e0
7
+ data.tar.gz: 3dd12561efd9a580647a2318cf0943909914b5bf88028607830febcae54db275f01b732d710b6cb4e290dfaecccf8fba7b481a0ad678c4255bebf486416ffe57
Binary file
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
@@ -0,0 +1,14 @@
1
+ language: ruby
2
+ script: "rake test"
3
+ rvm:
4
+ - 1.8.7
5
+ - 1.9.2
6
+ - 1.9.3
7
+ - 2.0.0
8
+ - 2.1.5
9
+ - 2.2.0
10
+ - 2.3.0
11
+ - 2.4.0
12
+ - 2.5.0
13
+ - 2.6.0
14
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in date_duration.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 TODO: nithin stany dsouza
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,22 @@
1
+ # DateDuration
2
+
3
+ The Duration Calculator calculates the number of days, months and years between two dates.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'date_duration'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install date_duration
18
+
19
+ ## Usage
20
+
21
+ require 'date_duration'
22
+ components = Date.duration(start_date, end_date)
@@ -0,0 +1,10 @@
1
+ require 'bundler'
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new do |test|
6
+ test.libs << 'lib' << 'test'
7
+ test.ruby_opts << "-rubygems"
8
+ test.pattern = 'test/**/test_*.rb'
9
+ test.verbose = true
10
+ end
@@ -0,0 +1,19 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'date_duration/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "date_duration"
8
+ spec.version = DateDuration::VERSION
9
+ spec.authors = ["Mohan Chhalotre"]
10
+ spec.email = ["mohanchhalotre@gmail.com"]
11
+ spec.description = %q{The Duration Calculator calculates the number of days, months and years between two dates.}
12
+ spec.summary = %q{The Duration Calculator calculates the number of days, months and years between two dates.}
13
+ spec.homepage = "https://github.com/mohangurjar82/date_duration"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+ end
@@ -0,0 +1,46 @@
1
+ require "date_duration/version"
2
+ require 'rubygems'
3
+ require 'active_support/all'
4
+ require 'i18n'
5
+
6
+
7
+ class Date
8
+ def self.duration(start_date, end_date)
9
+ common_year_days_in_month = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
10
+ start_date, end_date = end_date, start_date if start_date > end_date
11
+
12
+ start_date_year, start_date_month, start_date_day = start_date.year, start_date.month, start_date.day
13
+ end_date_year, end_date_month, end_date_day = end_date.year, end_date.month, end_date.day
14
+
15
+ day_duration = end_date_day - start_date_day
16
+
17
+ if (day_duration < 0)
18
+ day_duration = common_year_days_in_month[start_date_month-1] - start_date_day + end_date_day
19
+ end_date_month -= 1
20
+ end
21
+
22
+ if (end_date_month < 0)
23
+ end_date_month += 12
24
+ end_date_year -= 1
25
+ end
26
+
27
+ month_duration = end_date_month - start_date_month
28
+
29
+ if (month_duration < 0)
30
+ month_duration += 12
31
+ end_date_year -= 1
32
+ end
33
+
34
+ year_duration = end_date_year - start_date_year
35
+
36
+ duration_hash = { :year => year_duration, :month => month_duration, :day => day_duration }
37
+
38
+ duration_array = []
39
+ ["year", "month", "day"].each do |key|
40
+ value = duration_hash[key.to_sym]
41
+ duration_array << value.to_s + " " + ((value > 1)? I18n.t(key.to_s.pluralize, :default => key.to_s.pluralize.to_s) : I18n.t(key.to_s, :default => key.to_s)).to_s if value > 0
42
+ end
43
+ duration_hash[:duration] = duration_array.join(" ").to_s
44
+ duration_hash
45
+ end
46
+ end
@@ -0,0 +1,3 @@
1
+ module DateDuration
2
+ VERSION = "2.0.0"
3
+ end
@@ -0,0 +1,7 @@
1
+ en:
2
+ day: "day"
3
+ days: "days"
4
+ month: "month"
5
+ months: "months"
6
+ year: "year"
7
+ years: "years"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: date_duration
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mohan Chhalotre
@@ -17,7 +17,18 @@ email:
17
17
  executables: []
18
18
  extensions: []
19
19
  extra_rdoc_files: []
20
- files: []
20
+ files:
21
+ - ".DS_Store"
22
+ - ".gitignore"
23
+ - ".travis.yml"
24
+ - Gemfile
25
+ - LICENSE.txt
26
+ - README.md
27
+ - Rakefile
28
+ - date_duration.gemspec
29
+ - lib/date_duration.rb
30
+ - lib/date_duration/version.rb
31
+ - lib/en.yml
21
32
  homepage: https://github.com/mohangurjar82/date_duration
22
33
  licenses:
23
34
  - MIT