weekday 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ == 1.0.0 / 2010-12-04
2
+
3
+ * 1 major enhancement
4
+ * Birthday!
data/README.md ADDED
@@ -0,0 +1,60 @@
1
+ weekday
2
+ ===========
3
+
4
+ This gem calculates date like 'first tuesday in december 2010' or 'third friday in may 2011' or 'last Saturday in december 2010'
5
+
6
+ Features
7
+ --------
8
+
9
+ * All method names are a combination of 'first', 'second', 'third', 'fourth', 'fifth' and 'monday', 'tuesday', ...
10
+ * Also 'last' + 'monday', 'tuesday', ... is possible
11
+ * All methods require two arguments for the year and the month
12
+ * If there is for example no fifth saturday in a specific month then nil is returned
13
+
14
+ Examples
15
+ --------
16
+
17
+ require 'rubygems'
18
+ require 'weekday'
19
+
20
+ 1.upto 12 do |month|
21
+ day = Weekday.first_thursday(2010, month)
22
+ puts day
23
+ end
24
+
25
+
26
+ Install
27
+ -------
28
+
29
+ * [sudo] gem install weekday
30
+
31
+ Author
32
+ ------
33
+
34
+ Original author: Thomas Preymesser
35
+
36
+ License
37
+ -------
38
+
39
+ (The MIT License)
40
+
41
+ Copyright (c) 2010 Thomas Preymesser
42
+
43
+ Permission is hereby granted, free of charge, to any person obtaining
44
+ a copy of this software and associated documentation files (the
45
+ 'Software'), to deal in the Software without restriction, including
46
+ without limitation the rights to use, copy, modify, merge, publish,
47
+ distribute, sublicense, and/or sell copies of the Software, and to
48
+ permit persons to whom the Software is furnished to do so, subject to
49
+ the following conditions:
50
+
51
+ The above copyright notice and this permission notice shall be
52
+ included in all copies or substantial portions of the Software.
53
+
54
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
55
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
56
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
57
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
58
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
59
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
60
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+
2
+ begin
3
+ require 'bones'
4
+ rescue LoadError
5
+ abort '### Please install the "bones" gem ###'
6
+ end
7
+
8
+ task :default => 'test:run'
9
+ task 'gem:release' => 'test:run'
10
+
11
+ Bones {
12
+ name 'weekday'
13
+ authors 'Thomas Preymesser'
14
+ email 'thopre@gmail.com'
15
+ url 'http://weekday.rubyforge.net/'
16
+ }
17
+
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'weekday' # Weekday-Gem
5
+ require 'date'
6
+
7
+ NEXTDAYS = ['heute','morgen','uebermorgen']
8
+
9
+ def heute?(day)
10
+ t = Time.now
11
+ day == Date.new(t.year,t.month,t.day)
12
+ end
13
+
14
+ def morgen?(day)
15
+ heute? day-1
16
+ end
17
+
18
+ def uebermorgen?(day)
19
+ morgen? day-1
20
+ end
21
+
22
+ def puts_event(day,text,condition)
23
+ if condition
24
+ print NEXTDAYS[0]+", " if heute? day
25
+ print NEXTDAYS[1]+", " if morgen? day
26
+ print NEXTDAYS[2]+", " if uebermorgen? day
27
+ puts "#{day.day}.#{day.month}.#{day.year}"
28
+ puts text
29
+ puts
30
+ end
31
+ end
32
+
33
+ t = Time.now
34
+ tag = Date.new(t.year,t.month,t.day)
35
+ reichweite = 10
36
+ reichweite = ARGV[0].to_i if ARGV[0]
37
+ ueberschrift = "Termine in den naechsten #{reichweite} Tagen"
38
+ puts ueberschrift
39
+ puts '-'*ueberschrift.length
40
+ reichweite.times do
41
+ year = tag.year
42
+ month = tag.month
43
+ puts_event tag, "Blue Moon Freie Themenwahl (jeden 2. Di)", Weekday.second_tuesday(year,month) == tag
44
+ puts_event tag, "Chaos Radio (jeden letzten Do)", Weekday.last_thursday(year,month) == tag
45
+ puts_event tag, "Hackerfunk (jeden 1. Samstag)", Weekday.first_saturday(year,month) == tag
46
+ puts_event tag, "rug-b Treffen (jeden 1. Do)", Weekday.first_thursday(year,month) == tag
47
+ puts_event tag, "Ocean Club Radio Eins (jeden 2. Sa 1-5 h)", Weekday.second_saturday(year,month) == tag
48
+ puts_event tag, "Ocean Club Radio Eins (jeden 4. Sa 1-5 h)", Weekday.fourth_saturday(year,month) == tag
49
+ tag += 1
50
+ end
@@ -0,0 +1,274 @@
1
+ <?xml version="1.0" encoding="CP850"?>
2
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+ <head>
6
+ <meta content="text/html; charset=CP850" http-equiv="Content-Type" />
7
+
8
+ <title>Class: Object</title>
9
+
10
+ <link rel="stylesheet" href="./rdoc.css" type="text/css" media="screen" />
11
+
12
+ <script src="./js/jquery.js" type="text/javascript"
13
+ charset="utf-8"></script>
14
+ <script src="./js/thickbox-compressed.js" type="text/javascript"
15
+ charset="utf-8"></script>
16
+ <script src="./js/quicksearch.js" type="text/javascript"
17
+ charset="utf-8"></script>
18
+ <script src="./js/darkfish.js" type="text/javascript"
19
+ charset="utf-8"></script>
20
+
21
+ </head>
22
+ <body class="class">
23
+
24
+ <div id="metadata">
25
+ <div id="home-metadata">
26
+ <div id="home-section" class="section">
27
+ <h3 class="section-header">
28
+ <a href="./index.html">Home</a>
29
+ <a href="./index.html#classes">Classes</a>
30
+ <a href="./index.html#methods">Methods</a>
31
+ </h3>
32
+ </div>
33
+ </div>
34
+
35
+ <div id="file-metadata">
36
+ <div id="file-list-section" class="section">
37
+ <h3 class="section-header">In Files</h3>
38
+ <div class="section-body">
39
+ <ul>
40
+
41
+ <li><a href="./weekday_rb.html?TB_iframe=true&amp;height=550&amp;width=785"
42
+ class="thickbox" title="weekday.rb">weekday.rb</a></li>
43
+
44
+ </ul>
45
+ </div>
46
+ </div>
47
+
48
+
49
+ </div>
50
+
51
+ <div id="class-metadata">
52
+
53
+ <!-- Parent Class -->
54
+
55
+ <div id="parent-class-section" class="section">
56
+ <h3 class="section-header">Parent</h3>
57
+
58
+ <p class="link"></p>
59
+
60
+ </div>
61
+
62
+
63
+ <!-- Namespace Contents -->
64
+
65
+
66
+ <!-- Method Quickref -->
67
+
68
+ <div id="method-list-section" class="section">
69
+ <h3 class="section-header">Methods</h3>
70
+ <ul class="link-list">
71
+
72
+ <li><a href="#method-c-method_missing">::method_missing</a></li>
73
+
74
+ </ul>
75
+ </div>
76
+
77
+
78
+ <!-- Included Modules -->
79
+
80
+ </div>
81
+
82
+ <div id="project-metadata">
83
+
84
+
85
+
86
+ <div id="classindex-section" class="section project-section">
87
+ <h3 class="section-header">Class/Module Index
88
+ <span class="search-toggle"><img src="./images/find.png"
89
+ height="16" width="16" alt="[+]"
90
+ title="show/hide quicksearch" /></span></h3>
91
+ <form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
92
+ <fieldset>
93
+ <legend>Quicksearch</legend>
94
+ <input type="text" name="quicksearch" value=""
95
+ class="quicksearch-field" />
96
+ </fieldset>
97
+ </form>
98
+
99
+ <ul class="link-list">
100
+
101
+ <li><a href="./Object.html">Object</a></li>
102
+
103
+ </ul>
104
+ <div id="no-class-search-results" style="display: none;">No matching classes.</div>
105
+ </div>
106
+
107
+
108
+ </div>
109
+ </div>
110
+
111
+ <div id="documentation">
112
+ <h1 class="class">Object</h1>
113
+
114
+ <div id="description">
115
+
116
+ </div>
117
+
118
+ <!-- Constants -->
119
+
120
+ <div id="constants-list" class="section">
121
+ <h3 class="section-header">Constants</h3>
122
+ <dl>
123
+
124
+ <dt><a name="COUNTWORDS">COUNTWORDS</a></dt>
125
+
126
+ <dd class="description"></dd>
127
+
128
+
129
+ <dt><a name="DAYNAMES">DAYNAMES</a></dt>
130
+
131
+ <dd class="description"></dd>
132
+
133
+
134
+ <dt><a name="DAYNAMESS">DAYNAMESS</a></dt>
135
+
136
+ <dd class="description"></dd>
137
+
138
+
139
+ <dt><a name="PREV">PREV</a></dt>
140
+
141
+ <dd class="description"></dd>
142
+
143
+
144
+ <dt><a name="ILLEGAL_ARGUMENTS">ILLEGAL_ARGUMENTS</a></dt>
145
+
146
+ <dd class="description"></dd>
147
+
148
+
149
+ </dl>
150
+ </div>
151
+
152
+
153
+ <!-- Attributes -->
154
+
155
+
156
+ <!-- Methods -->
157
+
158
+ <div id="public-class-method-details" class="method-section section">
159
+ <h3 class="section-header">Public Class Methods</h3>
160
+
161
+
162
+ <div id="method_missing-method" class="method-detail ">
163
+ <a name="method-c-method_missing"></a>
164
+
165
+
166
+ <div class="method-heading">
167
+ <span class="method-name">method_missing</span><span
168
+ class="method-args">(m, *args)</span>
169
+ <span class="method-click-advice">click to toggle source</span>
170
+ </div>
171
+
172
+
173
+ <div class="method-description">
174
+
175
+
176
+
177
+
178
+
179
+ <div class="method-source-code"
180
+ id="method_missing-source">
181
+ <pre>
182
+ <span class="ruby-comment"># File weekday.rb, line 21</span>
183
+ def self.method_missing(m, *args)
184
+ <span class="ruby-comment"># self.mondays .. self.sundays
185
+ if <span class="ruby-constant">DAYNAMESS</span>.include?(m.to_s)
186
+ wnum = <span class="ruby-constant">DAYNAMESS</span>.index(m.to_s)
187
+ begin
188
+ d = <span class="ruby-constant">Date</span>.new(args[0],args[1])
189
+ rescue <span class="ruby-constant">ArgumentError</span>
190
+ raise <span class="ruby-constant">ArgumentError</span>, <span class="ruby-constant">ILLEGAL_ARGUMENTS</span>
191
+ end
192
+ result = []
193
+ while d.month == args[1] do
194
+ if d.wday == wnum
195
+ result &lt;&lt; d
196
+ loop do
197
+ d += 7
198
+ break if not d.month == args[1]
199
+ result &lt;&lt; d
200
+ end
201
+ end
202
+ d += 1
203
+ end
204
+ return result
205
+ end
206
+ count,weekday = m.to_s.split(<span class="ruby-string">'_'</span>)
207
+ unless <span class="ruby-constant">COUNTWORDS</span>.include?(count)
208
+ raise <span class="ruby-constant">NoMethodError</span>, &quot;undefined method `#{m}'&quot;
209
+ end
210
+ count = <span class="ruby-constant">COUNTWORDS</span>.index(count)+1
211
+ wnum = <span class="ruby-constant">DAYNAMES</span>.index(weekday)
212
+ unless wnum
213
+ raise <span class="ruby-constant">NoMethodError</span>, &quot;undefined method `#{m}'&quot;
214
+ end
215
+ <span class="ruby-comment"># self.last_monday .. self.last_sunday
216
+ if count == <span class="ruby-constant">COUNTWORDS</span>.index(<span class="ruby-constant">COUNTWORDS</span>[-1])+1
217
+ d = <span class="ruby-constant">Date</span>.new(args[0],args[1],-1)
218
+ while not d.wday == wnum do
219
+ d -= 1
220
+ end
221
+ return d
222
+ end
223
+ case count
224
+ when 1
225
+ begin
226
+ d = <span class="ruby-constant">Date</span>.new(args[0],args[1],1)
227
+ rescue <span class="ruby-constant">ArgumentError</span>
228
+ raise <span class="ruby-constant">ArgumentError</span>, <span class="ruby-constant">ILLEGAL_ARGUMENTS</span>
229
+ end
230
+
231
+ while not d.wday == wnum do
232
+ d += 1
233
+ end
234
+ return d
235
+ when 2..5
236
+ m_name = (<span class="ruby-constant">PREV</span>[count] + <span class="ruby-string">'_'</span> + weekday).to_sym
237
+ prev = self.send((<span class="ruby-constant">PREV</span>[count] + <span class="ruby-string">'_'</span> + weekday), args[0], args[1])
238
+ result = if prev
239
+ prev + 7
240
+ else
241
+ nil
242
+ end
243
+ unless result and result.month == args[1]
244
+ result = nil
245
+ end
246
+ return result
247
+ else
248
+ raise <span class="ruby-constant">NoMethodError</span>, &quot;undefined method `#{m}'&quot;
249
+ end
250
+ end</pre>
251
+ </div>
252
+
253
+ </div>
254
+
255
+
256
+
257
+
258
+ </div>
259
+
260
+
261
+ </div>
262
+
263
+
264
+ </div>
265
+
266
+ <div id="validator-badges">
267
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
268
+ <p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
269
+ Rdoc Generator</a> 2</small>.</p>
270
+ </div>
271
+
272
+ </body>
273
+ </html>
274
+
@@ -0,0 +1,137 @@
1
+ <?xml version="1.0" encoding="CP850"?>
2
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+ <head>
6
+ <meta content="text/html; charset=CP850" http-equiv="Content-Type" />
7
+
8
+ <title>Class: Weekday</title>
9
+
10
+ <link rel="stylesheet" href="./rdoc.css" type="text/css" media="screen" />
11
+
12
+ <script src="./js/jquery.js" type="text/javascript"
13
+ charset="utf-8"></script>
14
+ <script src="./js/thickbox-compressed.js" type="text/javascript"
15
+ charset="utf-8"></script>
16
+ <script src="./js/quicksearch.js" type="text/javascript"
17
+ charset="utf-8"></script>
18
+ <script src="./js/darkfish.js" type="text/javascript"
19
+ charset="utf-8"></script>
20
+
21
+ </head>
22
+ <body class="class">
23
+
24
+ <div id="metadata">
25
+ <div id="home-metadata">
26
+ <div id="home-section" class="section">
27
+ <h3 class="section-header">
28
+ <a href="./index.html">Home</a>
29
+ <a href="./index.html#classes">Classes</a>
30
+ <a href="./index.html#methods">Methods</a>
31
+ </h3>
32
+ </div>
33
+ </div>
34
+
35
+ <div id="file-metadata">
36
+ <div id="file-list-section" class="section">
37
+ <h3 class="section-header">In Files</h3>
38
+ <div class="section-body">
39
+ <ul>
40
+
41
+ <li><a href="./wd_rb.html?TB_iframe=true&amp;height=550&amp;width=785"
42
+ class="thickbox" title="wd.rb">wd.rb</a></li>
43
+
44
+ <li><a href="./weekday_rb.html?TB_iframe=true&amp;height=550&amp;width=785"
45
+ class="thickbox" title="weekday.rb">weekday.rb</a></li>
46
+
47
+ </ul>
48
+ </div>
49
+ </div>
50
+
51
+
52
+ </div>
53
+
54
+ <div id="class-metadata">
55
+
56
+ <!-- Parent Class -->
57
+
58
+ <div id="parent-class-section" class="section">
59
+ <h3 class="section-header">Parent</h3>
60
+
61
+ <p class="link">Object</p>
62
+
63
+ </div>
64
+
65
+
66
+ <!-- Namespace Contents -->
67
+
68
+
69
+ <!-- Method Quickref -->
70
+
71
+ <div id="method-list-section" class="section">
72
+ <h3 class="section-header">Methods</h3>
73
+ <ul class="link-list">
74
+
75
+ <li><a href="#method-c-libpath">::libpath</a></li>
76
+
77
+ <li><a href="#method-c-method_missing">::method_missing</a></li>
78
+
79
+ <li><a href="#method-c-path">::path</a></li>
80
+
81
+ <li><a href="#method-c-require_all_libs_relative_to">::require_all_libs_relative_to</a></li>
82
+
83
+ <li><a href="#method-c-version">::version</a></li>
84
+
85
+ </ul>
86
+ </div>
87
+
88
+
89
+ <!-- Included Modules -->
90
+
91
+ </div>
92
+
93
+ <div id="project-metadata">
94
+
95
+
96
+
97
+ <div id="classindex-section" class="section project-section">
98
+ <h3 class="section-header">Class/Module Index
99
+ <span class="search-toggle"><img src="./images/find.png"
100
+ height="16" width="16" alt="[+]"
101
+ title="show/hide quicksearch" /></span></h3>
102
+ <form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
103
+ <fieldset>
104
+ <legend>Quicksearch</legend>
105
+ <input type="text" name="quicksearch" value=""
106
+ class="quicksearch-field" />
107
+ </fieldset>
108
+ </form>
109
+
110
+ <ul class="link-list">
111
+
112
+ <li><a href="./Weekday.html">Weekday</a></li>
113
+
114
+ </ul>
115
+ <div id="no-class-search-results" style="display: none;">No matching classes.</div>
116
+ </div>
117
+
118
+
119
+ </div>
120
+ </div>
121
+
122
+ <div id="documentation">
123
+ <h1 class="class">Weekday</h1>
124
+
125
+ <div id="description">
126
+
127
+ </div>
128
+
129
+ <!-- Constants -->
130
+
131
+ <div id="constants-list" class="section">
132
+ <h3 class="section-header">Constants</h3>
133
+ <dl>
134
+
135
+ <dt><a name="COUNTWORDS">COUNTWORDS</a></dt>
136
+
137
+ <dd class="description">
@@ -0,0 +1,2 @@
1
+ Tue, 01 Feb 2011 11:47:32 +0100
2
+ weekday.rb Tue, 01 Feb 2011 11:12:46 +0100
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,59 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
3
+ "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
4
+
5
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
6
+ <head>
7
+ <meta content="text/html; charset=CP850" http-equiv="Content-Type" />
8
+
9
+ <title>RDoc Documentation</title>
10
+
11
+ <link type="text/css" media="screen" href="rdoc.css" rel="stylesheet" />
12
+
13
+ <script src="js/jquery.js" type="text/javascript" charset="utf-8"></script>
14
+ <script src="js/thickbox-compressed.js" type="text/javascript" charset="utf-8"></script>
15
+ <script src="js/quicksearch.js" type="text/javascript" charset="utf-8"></script>
16
+ <script src="js/darkfish.js" type="text/javascript" charset="utf-8"></script>
17
+
18
+ </head>
19
+ <body class="indexpage">
20
+
21
+
22
+ <h1>RDoc Documentation</h1>
23
+
24
+
25
+ <p>This is the API documentation for 'RDoc Documentation'.</p>
26
+
27
+
28
+
29
+
30
+
31
+ <h2 id="classes">Classes/Modules</h2>
32
+ <ul>
33
+
34
+ <li class="class"><a href="Weekday.html">Weekday</a></li>
35
+
36
+ </ul>
37
+
38
+ <h2 id="methods">Methods</h2>
39
+ <ul>
40
+
41
+ <li><a href="Weekday.html#method-c-libpath">::libpath &mdash; Weekday</a></li>
42
+
43
+ <li><a href="Weekday.html#method-c-method_missing">::method_missing &mdash; Weekday</a></li>
44
+
45
+ <li><a href="Weekday.html#method-c-path">::path &mdash; Weekday</a></li>
46
+
47
+ <li><a href="Weekday.html#method-c-require_all_libs_relative_to">::require_all_libs_relative_to &mdash; Weekday</a></li>
48
+
49
+ <li><a href="Weekday.html#method-c-version">::version &mdash; Weekday</a></li>
50
+
51
+ </ul>
52
+
53
+ <div id="validator-badges">
54
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
55
+ <p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
56
+ Rdoc Generator</a> 2</small>.</p>
57
+ </div>
58
+ </body>
59
+ </html>