week_of_month 1.2.2.1 → 1.2.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7cc308a8f81dbd9579c4aa6fbef97b4001fbd17f
4
- data.tar.gz: bb5dc79f8c80fc31608ecce03cddbdc24fd390dc
3
+ metadata.gz: eb8e17155b66f00d79619774220611769249f90d
4
+ data.tar.gz: de433fd66043692ee66d04705ec26beec126d91f
5
5
  SHA512:
6
- metadata.gz: 014a5ad79f2aa49d60d8b91b012dec5e29d5b714dacd73866db4b94e317dc275a61c8f1efe178549315ab600a6e5694ac1a8f27ce06e846c3bc71e960f6d96bc
7
- data.tar.gz: 4b3c698b9a98ddab51a6dbcdded707c89dbfcab19ebd241e23dcc4d339432638cb3ab071476924064d04e899ba66a8f8f5d2cc47748a4abe5014f6dcdd8b1369
6
+ metadata.gz: 481f139413ab807b87057c916aa09f4f19eea12745cd42058c2395fadc1b28d83fbf7c73de48de71bb18b20eb4ead9111c9ebd8fa7c051dead44c1390d44c26a
7
+ data.tar.gz: e487771ab29e5c6cb351e70a634e83e6f20c37d2e76f0c4f0bbf18107814c6ad534d63cabbba9dc2aa4a282fc258a7291c9bbec66f647899854ac11b882c9bd5
data/Gemfile CHANGED
@@ -1,2 +1,4 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ gem "rake"
4
+
data/Gemfile.lock CHANGED
@@ -1,8 +1,10 @@
1
1
  GEM
2
2
  remote: https://rubygems.org/
3
3
  specs:
4
+ rake (10.1.0)
4
5
 
5
6
  PLATFORMS
6
7
  ruby
7
8
 
8
9
  DEPENDENCIES
10
+ rake
data/README.rdoc CHANGED
@@ -11,6 +11,8 @@ or Rails application. To install, simply add the following to your Gemfile:
11
11
 
12
12
  gem 'week_of_month'
13
13
 
14
+ Run bundle install and don't forget to restart your server after you install a new gem.
15
+
14
16
  == Usage
15
17
 
16
18
  It returns week split of that date's month
@@ -25,33 +27,27 @@ or Rails application. To install, simply add the following to your Gemfile:
25
27
 
26
28
  It returns month's week in which the date lies
27
29
 
28
- Date.new(2012,1,1).week_of_month
29
- => 1
30
+ Date.new(2012,1,1).week_of_month => 1
30
31
 
31
32
  It return true if date lies in first week of month, else false.
32
33
 
33
- Date.new(2012,1,1).first_week?
34
- => true
34
+ Date.new(2012,1,1).first_week? => true
35
35
 
36
36
  It returns true if date lies in second week of month, else false.
37
37
 
38
- Date.new(2012,1,9).second_week?
39
- => true
38
+ Date.new(2012,1,9).second_week? => true
40
39
 
41
40
  It returns true if date lies in last week of month, else false.
42
41
 
43
- Date.new(2012,1,31).last_week?
44
- => true
42
+ Date.new(2012,1,31).last_week? => true
45
43
 
46
44
  It returns total number of weeks in month.
47
45
 
48
- Date.new(2012,1,31).total_weeks
49
- => 5
46
+ Date.new(2012,1,31).total_weeks => 5
50
47
 
51
48
  It returns month's week in which the date lies
52
49
 
53
- Date.new(2012,1,31).week_of_month_in_eng
54
- => "Fifth"
50
+ Date.new(2012,1,31).week_of_month_in_eng => "Fifth"
55
51
 
56
52
  == Tools Being Used
57
53
 
@@ -87,25 +83,6 @@ august?, september?, october?, november?, december?, last_day_of_month
87
83
 
88
84
  Fork, fix, then send me a pull request.
89
85
 
90
- == Copyright
91
-
92
- (The MIT License)
93
-
94
- Copyright (c) 2012-2013 Sachin Singh. See LICENSE for details.
95
-
96
- Permission is hereby granted, free of charge, to any person obtaining a copy
97
- of this software and associated documentation files (the ‘Software’), to deal
98
- in the Software without restriction, including without limitation the rights
99
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
100
- of the Software, and to permit persons to whom the Software is furnished to do so,
101
- subject to the following conditions:
102
-
103
- The above copyright notice and this permission notice shall be included in all
104
- copies or substantial portions of the Software.
86
+ ## License
105
87
 
106
- THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
107
- INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
108
- PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
109
- HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
110
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
111
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
88
+ use MIT license.
@@ -7,19 +7,19 @@ module WeekOfMonth
7
7
  module Constant
8
8
 
9
9
  # hash containg english words from one to seventh
10
- WEEK_IN_ENG = { 1 => 'First', 2 => 'Second', 3 => 'Third',
10
+ WEEK_OF_MONTH_IN_ENG = { 1 => 'First', 2 => 'Second', 3 => 'Third',
11
11
  4 => 'Fourth', 5 => 'Fifth', 6 => 'Sixth', 7 => 'Seventh'}
12
12
 
13
13
  # hash containg french words from one to seventh
14
- WEEK_IN_FR = { 1 => 'First', 2 => 'Second', 3 => 'Third',
14
+ WEEK_OF_MONTH_IN_FR = { 1 => 'First', 2 => 'Second', 3 => 'Third',
15
15
  4 => 'Quatrième', 5 => 'Cinquième', 6 => 'sixième', 7 => 'septième'}
16
16
 
17
17
  # hash containg german words from one to seventh
18
- WEEK_IN_GER = { 1 => 'First', 2 => 'Second', 3 => 'Dritten',
18
+ WEEK_OF_MONTH_IN_GER = { 1 => 'First', 2 => 'Second', 3 => 'Dritten',
19
19
  4 => 'Vierte', 5 => 'Fünfte', 6 => 'Sechste', 7 => 'siebte'}
20
20
 
21
21
  # hash containg japneese words from one to seventh
22
- WEEK_IN_JAP = { 1 => '最初', 2 => '秒', 3 => 'サード',
22
+ WEEK_OF_MONTH_IN_JAP = { 1 => '最初', 2 => '秒', 3 => 'サード',
23
23
  4 => '第4回', 5 => '第五', 6=> 'シックス', 7 => '第7' }
24
24
 
25
25
  # hash containg month name with days in that month(in non leap yaer)
@@ -38,4 +38,4 @@ module WeekOfMonth
38
38
  DAYS_IN_SEQUENCE = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
39
39
  "Saturday"]
40
40
  end
41
- end
41
+ end
data/lib/modules/month.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # @author Sachion Singh
2
2
 
3
- require_relative 'constant'
3
+ RUBY_VERSION < '1.9' ? require('modules/constant') : require_relative('constant')
4
4
 
5
5
  module WeekOfMonth
6
6
  module Month
data/lib/modules/week.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # @author Sachion Singh
2
2
 
3
- require_relative 'constant'
3
+ RUBY_VERSION < '1.9' ? require('modules/constant') : require_relative('constant')
4
4
 
5
5
  module WeekOfMonth
6
6
  module Week
@@ -16,6 +16,30 @@ module WeekOfMonth
16
16
  return (i + 1) if o.include?(self.day)
17
17
  end
18
18
  end
19
+
20
+ # November week_split would like this
21
+ # [[nil, nil, nil, nil, nil, 1, 2],
22
+ # [3, 4, 5, 6, 7, 8, 9],
23
+ # [10, 11, 12, 13, 14, 15, 16],
24
+ # [17, 18, 19, 20, 21, 22, 23],
25
+ # [24, 25, 26, 27, 28, 29, 30]]
26
+ #
27
+ # The First Day of week decide its month of week.
28
+ # The W1 Nov should be Nov 3 - Nov 9
29
+ #
30
+ # Date.new(2012,11,15).general_week_of_month
31
+ # => 2
32
+ #
33
+ # Date.new(2013,11,3).general_week_of_month
34
+ # => 1
35
+ # @return [Fixnum]
36
+ def general_week_of_month
37
+ if week_split.first.first.nil?
38
+ week_of_month - 1
39
+ else
40
+ week_of_month
41
+ end
42
+ end
19
43
 
20
44
  # checks whether the given day lies in first week of month
21
45
  # Date.new(2012,11,1).first_week?
@@ -84,10 +108,9 @@ module WeekOfMonth
84
108
  # Date.new(2012,11,30).week_of_month_in_fr
85
109
  # => "Cinquième"
86
110
  # @return [String]
87
- ['eng', 'fr', 'ger', 'jap'].each do |lang|
88
- method_name = "week_of_month_in_#{lang}"
89
- define_method(method_name) do
90
- eval "WEEK_IN_#{lang.upcase}[week_of_month]"
111
+ constants.select{|x| x.to_s.match("WEEK_OF_MONTH_IN_")}.each do |const|
112
+ define_method(const.to_s.downcase) do
113
+ eval "#{const.to_s}[week_of_month]"
91
114
  end
92
115
  end
93
116
 
@@ -176,4 +199,4 @@ module WeekOfMonth
176
199
  end
177
200
 
178
201
  end
179
- end
202
+ end
@@ -2,23 +2,26 @@
2
2
  # encoding: utf-8
3
3
 
4
4
  require 'test/unit'
5
- require_relative '../../week_of_month'
5
+ RUBY_VERSION < '1.9' ? require('lib/week_of_month') : require_relative('../../week_of_month')
6
+
6
7
 
7
8
  class TestConstant < Test::Unit::TestCase
8
9
 
9
10
  def test_constants_present?
10
11
  [Date,Time].each do |klass|
11
- assert klass::WEEK_IN_ENG
12
+ assert klass::WEEK_OF_MONTH_IN_ENG
12
13
 
13
- assert klass::WEEK_IN_GER
14
+ assert klass::WEEK_OF_MONTH_IN_GER
14
15
 
15
- assert klass::WEEK_IN_FR
16
+ assert klass::WEEK_OF_MONTH_IN_FR
16
17
 
17
- assert klass::WEEK_IN_JAP
18
+ assert klass::WEEK_OF_MONTH_IN_JAP
18
19
 
19
20
  assert klass::MONTH_WITH_DAY
20
21
 
21
22
  assert klass::MONTH_WITH_SEQUENCE
23
+
24
+ assert klass::DAYS_IN_SEQUENCE
22
25
  end
23
26
  end
24
27
 
@@ -27,22 +30,22 @@ class TestConstant < Test::Unit::TestCase
27
30
  assert_equal({ 1 => 'First', 2 => 'Second',
28
31
  3 => 'Third', 4 => 'Fourth',
29
32
  5 => 'Fifth', 6 => 'Sixth',
30
- 7 =>"Seventh" }, klass::WEEK_IN_ENG)
33
+ 7 =>"Seventh" }, klass::WEEK_OF_MONTH_IN_ENG)
31
34
 
32
35
  assert_equal({ 1 => 'First', 2 => 'Second',
33
36
  3 => 'Third', 4 => 'Quatrième',
34
37
  5 => 'Cinquième', 6 => 'sixième',
35
- 7 => "septième" }, klass::WEEK_IN_FR)
38
+ 7 => "septième" }, klass::WEEK_OF_MONTH_IN_FR)
36
39
 
37
40
  assert_equal({ 1 => 'First', 2 => 'Second',
38
41
  3 => 'Dritten', 4 => 'Vierte',
39
42
  5 => 'Fünfte', 6 => 'Sechste',
40
- 7 => "siebte" }, klass::WEEK_IN_GER)
43
+ 7 => "siebte" }, klass::WEEK_OF_MONTH_IN_GER)
41
44
 
42
45
  assert_equal({ 1=>'最初', 2 =>'秒',
43
46
  3 =>'サード', 4=> '第4回',
44
47
  5 =>'第五', 6=> 'シックス' ,
45
- 7 => "第7" } , klass::WEEK_IN_JAP)
48
+ 7 => "第7" } , klass::WEEK_OF_MONTH_IN_JAP)
46
49
 
47
50
  assert_equal({ :january => 1, :february => 2, :march => 3,
48
51
  :april => 4, :may => 5, :june => 6, :july => 7,
@@ -60,4 +63,4 @@ class TestConstant < Test::Unit::TestCase
60
63
  end
61
64
 
62
65
  end
63
-
66
+
@@ -3,12 +3,13 @@
3
3
 
4
4
  require 'test/unit'
5
5
 
6
- require_relative '../../week_of_month'
6
+ RUBY_VERSION < '1.9' ? require('lib/week_of_month') : require_relative('../../week_of_month')
7
7
  class TestDay < Test::Unit::TestCase
8
-
8
+
9
9
  def test_days_array
10
10
  [Date,Time].each do |klass|
11
11
  object = klass.new(2012,2,8)
12
+
12
13
  days_array_for_february = [nil, nil, nil,1, 2, 3, 4, 5,
13
14
  6, 7, 8, 9, 10, 11, 12, 13, 14,
14
15
  15, 16, 17, 18, 19, 20, 21, 22,
@@ -2,7 +2,7 @@
2
2
  # encoding: utf-8
3
3
 
4
4
  require 'test/unit'
5
- require_relative '../../week_of_month'
5
+ RUBY_VERSION < '1.9' ? require('lib/week_of_month') : require_relative('../../week_of_month')
6
6
 
7
7
  class TestMonth < Test::Unit::TestCase
8
8
 
@@ -24,7 +24,7 @@ class TestMonth < Test::Unit::TestCase
24
24
 
25
25
  assert klass.new(2012,8,1).august?
26
26
 
27
- assert klass.new(2012,9,1).september?
27
+ assert klass.new(2012,9,1).september?
28
28
 
29
29
  assert klass.new(2012,10,1).october?
30
30
 
@@ -2,7 +2,8 @@
2
2
  # encoding: utf-8
3
3
 
4
4
  require 'test/unit'
5
- require_relative '../../week_of_month'
5
+ RUBY_VERSION < '1.9' ? require('lib/week_of_month') : require_relative('../../week_of_month')
6
+
6
7
 
7
8
  class TestWeek < Test::Unit::TestCase
8
9
 
@@ -33,7 +34,35 @@ class TestWeek < Test::Unit::TestCase
33
34
  assert_equal 5, klass.new(2013,12,31).week_of_month
34
35
  end
35
36
  end
36
-
37
+
38
+ def test_general_week_of_month
39
+ [Date,Time].each do |klass|
40
+ assert_equal 4, klass.new(2013,1,31).general_week_of_month
41
+
42
+ assert_equal 4, klass.new(2013,2,28).general_week_of_month
43
+
44
+ assert_equal 5, klass.new(2013,3,31).general_week_of_month
45
+
46
+ assert_equal 4, klass.new(2013,4,30).general_week_of_month
47
+
48
+ assert_equal 4, klass.new(2013,5,31).general_week_of_month
49
+
50
+ assert_equal 5, klass.new(2013,6,30).general_week_of_month
51
+
52
+ assert_equal 4, klass.new(2013,7,31).general_week_of_month
53
+
54
+ assert_equal 4, klass.new(2013,8,31).general_week_of_month
55
+
56
+ assert_equal 5, klass.new(2013,9,30).general_week_of_month
57
+
58
+ assert_equal 4, klass.new(2013,10,31).general_week_of_month
59
+
60
+ assert_equal 4, klass.new(2013,11,30).general_week_of_month
61
+
62
+ assert_equal 5, klass.new(2013,12,31).general_week_of_month
63
+ end
64
+ end
65
+
37
66
  def test_week_split
38
67
  [Date,Time].each do |klass|
39
68
  object = klass.new(2013,1,10)
@@ -4,7 +4,7 @@
4
4
  # @author Sachin Singh
5
5
 
6
6
  require 'test/unit'
7
- require_relative '../../week_of_month'
7
+ RUBY_VERSION < '1.9' ? require('lib/week_of_month') : require_relative('../../week_of_month')
8
8
 
9
9
  class TestYear < Test::Unit::TestCase
10
10
 
data/lib/week_of_month.rb CHANGED
@@ -1,15 +1,32 @@
1
1
  require 'date'
2
2
  require 'time'
3
- require_relative 'modules/day'
4
- require_relative 'modules/month'
5
- require_relative 'modules/week'
6
- require_relative 'modules/year'
3
+
4
+ RUBY_VERSION < '1.9' ? require('modules/day') : require_relative('modules/day')
5
+ RUBY_VERSION < '1.9' ? require('modules/month') : require_relative('modules/month')
6
+ RUBY_VERSION < '1.9' ? require('modules/week') : require_relative('modules/week')
7
+ RUBY_VERSION < '1.9' ? require('modules/year') : require_relative('modules/year')
7
8
 
8
9
  class Date
9
10
  include WeekOfMonth::Day
10
11
  include WeekOfMonth::Month
11
12
  include WeekOfMonth::Week
12
13
  include WeekOfMonth::Year
14
+
15
+ unless method_defined?(:to_date)
16
+ def to_date
17
+ ::Date.new(year, month, day)
18
+ end
19
+ end
20
+
21
+ unless method_defined?(:sunday?)
22
+ def sunday? ; self.wday == 0; end
23
+ def monday? ; self.wday == 1; end
24
+ def tuesday? ; self.wday == 2; end
25
+ def wednesday? ; self.wday == 3; end
26
+ def thursday? ; self.wday == 4; end
27
+ def friday? ; self.wday == 5; end
28
+ def saturday? ; self.wday == 6; end
29
+ end
13
30
  end
14
31
 
15
32
  class Time
@@ -21,4 +38,36 @@ class Time
21
38
  def leap?
22
39
  self.to_date.leap?
23
40
  end
41
+
42
+ if RUBY_VERSION < '1.9'
43
+ def self.new(year=Time.now.year, month=Time.now.month, day=Time.now.day, hour=Time.now.hour, min=Time.now.min, sec=Time.now.sec, millisecond=(Time.now.to_f * 1000.0).to_i)
44
+ Time.local(year, month, day, hour, min, sec, millisecond)
45
+ end
46
+ end
47
+
48
+ unless method_defined?(:to_date)
49
+ def to_date
50
+ ::Date.new(year, month, day)
51
+ end
52
+ end
53
+ unless method_defined?(:sunday?)
54
+ def sunday? ; self.wday == 0; end
55
+ def monday? ; self.wday == 1; end
56
+ def tuesday? ; self.wday == 2; end
57
+ def wednesday? ; self.wday == 3; end
58
+ def thursday? ; self.wday == 4; end
59
+ def friday? ; self.wday == 5; end
60
+ def saturday? ; self.wday == 6; end
61
+ end
24
62
  end
63
+
64
+ class Hash
65
+ unless method_defined?(:key)
66
+ def key(value)
67
+ result = nil
68
+ self.each do |k,v| result = k if v == value && result == nil; end if self.values.include?(value)
69
+ result
70
+ end
71
+ end
72
+ end
73
+
data/license CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2012-2013 Sachin Singh
3
+ Copyright (c) 2012-2014 Sachin Singh
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -1,13 +1,12 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'week_of_month'
3
- s.version = '1.2.2.1'
4
- s.date = '2013-08-12'
3
+ s.version = '1.2.3.1'
4
+ s.date = '2014-04-27'
5
5
  s.summary = "Week Of Month!"
6
6
  s.description = "Its gives you week_of_month method on date and time objects, that returns week of the month."
7
7
  s.authors = ["Sachin Singh"]
8
8
  s.email = 'sachin@railsdeveloper.in'
9
9
  s.homepage = 'https://github.com/sachin87/week-of-month'
10
- s.summary = %q{}
11
10
  s.files = `git ls-files`.split("\n").sort
12
11
  s.require_paths = ["lib"]
13
12
  s.license = 'MIT'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: week_of_month
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2.1
4
+ version: 1.2.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sachin Singh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-12 00:00:00.000000000 Z
11
+ date: 2014-04-27 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Its gives you week_of_month method on date and time objects, that returns
14
14
  week of the month.
@@ -58,5 +58,5 @@ rubyforge_project:
58
58
  rubygems_version: 2.0.3
59
59
  signing_key:
60
60
  specification_version: 4
61
- summary: ''
61
+ summary: Week Of Month!
62
62
  test_files: []