week_of_month 1.0.3 → 1.1.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.
- data/lib/week_of_month.rb +101 -3
- metadata +2 -34
data/lib/week_of_month.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
#!/bin/env ruby
|
2
2
|
# encoding: utf-8
|
3
3
|
|
4
|
-
require '
|
5
|
-
require 'active_support/core_ext/date/calculations.rb'
|
4
|
+
require 'date'
|
6
5
|
|
7
6
|
class Date
|
8
7
|
|
@@ -22,6 +21,105 @@ class Date
|
|
22
21
|
3 =>'サード', 4=> '第4回',
|
23
22
|
5 =>'第五',6=> 'シックス' }
|
24
23
|
|
24
|
+
|
25
|
+
GENERAL_YEAR = { "January" => 31, "February" => 28, "March" => 31,
|
26
|
+
"April" => 30, "May" => 31, "June" => 30, "July" => 31,
|
27
|
+
"August" => 31, "September" => 30, "October" => 31,
|
28
|
+
"November" => 30, "December" => 31 }
|
29
|
+
|
30
|
+
LEAP_YEAR = { "January" => 31, "February" => 28, "March" => 31,
|
31
|
+
"April" => 30, "May" => 31, "June" => 30, "July" => 31,
|
32
|
+
"August" => 31, "September" => 30, "October" => 31,
|
33
|
+
"November" => 30, "December" => 31 }
|
34
|
+
|
35
|
+
def last_day_of_month
|
36
|
+
if january?
|
37
|
+
31
|
38
|
+
elsif february?
|
39
|
+
if leap?
|
40
|
+
29
|
41
|
+
else
|
42
|
+
28
|
43
|
+
end
|
44
|
+
elsif march?
|
45
|
+
31
|
46
|
+
elsif april?
|
47
|
+
30
|
48
|
+
elsif may?
|
49
|
+
31
|
50
|
+
elsif june?
|
51
|
+
30
|
52
|
+
elsif july?
|
53
|
+
31
|
54
|
+
elsif august?
|
55
|
+
31
|
56
|
+
elsif september?
|
57
|
+
30
|
58
|
+
elsif october?
|
59
|
+
31
|
60
|
+
elsif november?
|
61
|
+
30
|
62
|
+
elsif december?
|
63
|
+
31
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def january?
|
68
|
+
month == 1
|
69
|
+
end
|
70
|
+
|
71
|
+
def february?
|
72
|
+
month == 2
|
73
|
+
end
|
74
|
+
|
75
|
+
def march?
|
76
|
+
month == 3
|
77
|
+
end
|
78
|
+
|
79
|
+
def april?
|
80
|
+
month == 4
|
81
|
+
end
|
82
|
+
|
83
|
+
def may?
|
84
|
+
month == 5
|
85
|
+
end
|
86
|
+
|
87
|
+
def june?
|
88
|
+
month == 6
|
89
|
+
end
|
90
|
+
|
91
|
+
def july?
|
92
|
+
month == 7
|
93
|
+
end
|
94
|
+
|
95
|
+
def august?
|
96
|
+
month == 8
|
97
|
+
end
|
98
|
+
|
99
|
+
def september?
|
100
|
+
month == 9
|
101
|
+
end
|
102
|
+
|
103
|
+
def october?
|
104
|
+
month == 10
|
105
|
+
end
|
106
|
+
|
107
|
+
def november?
|
108
|
+
month == 11
|
109
|
+
end
|
110
|
+
|
111
|
+
def december?
|
112
|
+
month == 12
|
113
|
+
end
|
114
|
+
|
115
|
+
def end_of_month
|
116
|
+
Date.new(year,month,last_day_of_month)
|
117
|
+
end
|
118
|
+
|
119
|
+
def beginning_of_month
|
120
|
+
Date.new(year,month,1)
|
121
|
+
end
|
122
|
+
|
25
123
|
def days_array
|
26
124
|
day = self.beginning_of_month.wday
|
27
125
|
array = []
|
@@ -35,7 +133,7 @@ class Date
|
|
35
133
|
end
|
36
134
|
|
37
135
|
def week_of_month
|
38
|
-
week_split.each_with_index do |o,i|
|
136
|
+
week_split.each_with_index do |o,i|
|
39
137
|
return (i + 1) if o.include?(self.day)
|
40
138
|
end
|
41
139
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: week_of_month
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,39 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
date: 2012-09-22 00:00:00.000000000 Z
|
13
|
-
dependencies:
|
14
|
-
- !ruby/object:Gem::Dependency
|
15
|
-
name: activesupport
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
|
-
requirements:
|
19
|
-
- - ! '>='
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: '0'
|
22
|
-
type: :runtime
|
23
|
-
prerelease: false
|
24
|
-
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ! '>='
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '0'
|
30
|
-
- !ruby/object:Gem::Dependency
|
31
|
-
name: activesupport
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
|
-
requirements:
|
35
|
-
- - ! '>='
|
36
|
-
- !ruby/object:Gem::Version
|
37
|
-
version: '0'
|
38
|
-
type: :development
|
39
|
-
prerelease: false
|
40
|
-
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
|
-
requirements:
|
43
|
-
- - ! '>='
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: '0'
|
13
|
+
dependencies: []
|
46
14
|
description: Its gives you week_of_month method on date object, that returns week
|
47
15
|
of the month.
|
48
16
|
email: sachin@railsdeveloper.in
|