duration_time 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ Gemfile.lock
2
+ pkg/*
3
+ *.gem
4
+ .bundle
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Debbbbie
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,24 @@
1
+ This module provides a method for calculate the duration time from a date
2
+ like reg_date, which is usually used for statistics.
3
+
4
+ Usage:
5
+
6
+ # Assume that today is 2013-07-07
7
+ require 'duration_time'
8
+ reg_time = Time.new(2011,8,2,0,0,0, "+08:00")
9
+ # You can use reg_time = Date.parse("2011-08-02") if you have included
10
+ # gem active_support!
11
+ duration_time( reg_time )
12
+ # => {
13
+ # :years=>[2011, 2012, 2013],
14
+ # :months=>["2011-08", "2011-09", "2011-10", "2011-11", "2011-12",
15
+ # "2012-01", "2012-02", "2012-03", "2012-04", "2012-05", "2012-06",
16
+ # "2012-07", "2012-08", "2012-09", "2012-10", "2012-11", "2012-12",
17
+ # "2013-01", "2013-02", "2013-03", "2013-04", "2013-05", "2013-06"],
18
+ # :quarters=>["2011-09", "2011-12", "2012-03", "2012-06", "2012-09",
19
+ # "2012-12", "2013-03", "2013-06"]
20
+ # }
21
+
22
+ And you can specify default parameter `include_this_month_of_this_year = true`
23
+ if you want to include this month of this year. Default value is `false`.
24
+
@@ -0,0 +1,16 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "duration_time"
5
+ s.version = "1.0.0"
6
+ s.platform = Gem::Platform::RUBY
7
+ s.authors = ["debbbbie"]
8
+ s.email = ["debbbbie@163.com.com"]
9
+ s.homepage = "https://github.com/debbbbie/duration_time"
10
+ s.summary = %q{Calculate the duration time from a date like reg_date, which is usually used for statistics.}
11
+ s.description = %q{This module provides a method for calculate the duration time from a date \nlike reg_date, which is usually used for statistics.\n\nUsage:\n\n # Assume that today is 2013-07-07\n require 'duration_time' \n reg_time = Time.new(2011,8,2,0,0,0, "+08:00")\n # You can use reg_time = Date.parse("2011-08-02") if you have included\n # gem active_support!\n duration_time( reg_time ) \n # => {\n # :years=>[2011, 2012, 2013], \n # :months=>["2011-08", "2011-09", "2011-10", "2011-11", "2011-12", \n # "2012-01", "2012-02", "2012-03", "2012-04", "2012-05", "2012-06", \n # "2012-07", "2012-08", "2012-09", "2012-10", "2012-11", "2012-12", \n # "2013-01", "2013-02", "2013-03", "2013-04", "2013-05", "2013-06"], \n # :quarters=>["2011-09", "2011-12", "2012-03", "2012-06", "2012-09", \n # "2012-12", "2013-03", "2013-06"]\n # }\n\nAnd you can specify default parameter `include_this_month_of_this_year = true`\nif you want to include this month of this year. Default value is `false`.\n }
12
+ s.files = `git ls-files`.split("\n")
13
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
15
+ s.require_paths = ["lib"]
16
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'duration_time'
@@ -0,0 +1,20 @@
1
+
2
+ def get_duration_time(reg_date, current_date = Time.now, include_current_year_month = false)
3
+ to_current_year_month = include_current_year_month ? current_date.month : current_date.month - 1
4
+
5
+ years = (reg_date.year..current_date.year).to_a; months = []; quarters = []
6
+ years.each do |selected_year|
7
+ data_month = if selected_year == reg_date.year and selected_year == current_date.year
8
+ (reg_date.month..to_current_year_month).to_a
9
+ elsif selected_year > reg_date.year and selected_year == current_date.year
10
+ (1..to_current_year_month).to_a
11
+ elsif selected_year == reg_date.year and selected_year < current_date.year
12
+ (reg_date.month..12).to_a
13
+ elsif selected_year > reg_date.year and selected_year < current_date.year
14
+ (1..12).to_a
15
+ end
16
+ months.concat( data_month.map{|m|"#{selected_year}-#{m.to_s.rjust(2,'0')}"} )
17
+ quarters.concat( data_month.select{|m|m%3==0}.map{|m|"#{selected_year}-#{(m/3).to_s.rjust(2,'0')}"} )
18
+ end
19
+ {:years => years, :months => months, :quarters => quarters}
20
+ end
data/test/test.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'test/unit'
2
+ require 'active_support'
3
+ require 'duration_time'
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: duration_time
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - debbbbie
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2013-08-12 00:00:00 Z
19
+ dependencies: []
20
+
21
+ description: "This module provides a method for calculate the duration time from a date \\nlike reg_date, which is usually used for statistics.\\n\\nUsage:\\n\\n # Assume that today is 2013-07-07\\n require 'duration_time' \\n reg_time = Time.new(2011,8,2,0,0,0, \"+08:00\")\\n # You can use reg_time = Date.parse(\"2011-08-02\") if you have included\\n # gem active_support!\\n duration_time( reg_time ) \\n # => {\\n # :years=>[2011, 2012, 2013], \\n # :months=>[\"2011-08\", \"2011-09\", \"2011-10\", \"2011-11\", \"2011-12\", \\n # \"2012-01\", \"2012-02\", \"2012-03\", \"2012-04\", \"2012-05\", \"2012-06\", \\n # \"2012-07\", \"2012-08\", \"2012-09\", \"2012-10\", \"2012-11\", \"2012-12\", \\n # \"2013-01\", \"2013-02\", \"2013-03\", \"2013-04\", \"2013-05\", \"2013-06\"], \\n # :quarters=>[\"2011-09\", \"2011-12\", \"2012-03\", \"2012-06\", \"2012-09\", \\n # \"2012-12\", \"2013-03\", \"2013-06\"]\\n # }\\n\\nAnd you can specify default parameter `include_this_month_of_this_year = true`\\nif you want to include this month of this year. Default value is `false`.\\n "
22
+ email:
23
+ - debbbbie@163.com.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - .gitignore
32
+ - Gemfile
33
+ - MIT-LICENSE
34
+ - README
35
+ - duration_time.gemspec
36
+ - init.rb
37
+ - lib/duration_time.rb
38
+ - test/test.rb
39
+ homepage: https://github.com/debbbbie/duration_time
40
+ licenses: []
41
+
42
+ post_install_message:
43
+ rdoc_options: []
44
+
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ hash: 3
53
+ segments:
54
+ - 0
55
+ version: "0"
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 3
62
+ segments:
63
+ - 0
64
+ version: "0"
65
+ requirements: []
66
+
67
+ rubyforge_project:
68
+ rubygems_version: 1.8.24
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: Calculate the duration time from a date like reg_date, which is usually used for statistics.
72
+ test_files: []
73
+