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 +4 -4
- data/.DS_Store +0 -0
- data/.gitignore +17 -0
- data/.travis.yml +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +22 -0
- data/Rakefile +10 -0
- data/date_duration.gemspec +19 -0
- data/lib/date_duration.rb +46 -0
- data/lib/date_duration/version.rb +3 -0
- data/lib/en.yml +7 -0
- metadata +13 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 756214117c04405a153c9214dd750baa6e606954b6b4c6a5a3a62638f646c898
|
4
|
+
data.tar.gz: afa6cbe9a80ff30a4f68a8df23c8a6e2c1b11fd04fcfb3d2655a82d159eda7b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18f699eaf8494dc7c0d2e7e157ec61bcf34a0d28a88ca4f330eeeba0e1a86026fe5be20974068086d1f2f57ab235c56eadff2d6cf544f8b0b0090da0f6e445e0
|
7
|
+
data.tar.gz: 3dd12561efd9a580647a2318cf0943909914b5bf88028607830febcae54db275f01b732d710b6cb4e290dfaecccf8fba7b481a0ad678c4255bebf486416ffe57
|
data/.DS_Store
ADDED
Binary file
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -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.
|
data/README.md
ADDED
@@ -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)
|
data/Rakefile
ADDED
@@ -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
|
data/lib/en.yml
ADDED
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:
|
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
|