fat_date 0.1.0 → 0.2.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/.rubocop.yml +3 -9
- data/.yardopts +4 -0
- data/CHANGELOG.org +8 -3
- data/README.md +685 -0
- data/README.org +205 -155
- data/Rakefile +20 -3
- data/doc/Date.html +153 -0
- data/doc/DateTime.html +148 -0
- data/doc/FatDate/Date/ClassMethods.html +1930 -0
- data/doc/FatDate/Date.html +8319 -0
- data/doc/FatDate/DateTime.html +203 -0
- data/doc/FatDate.html +158 -0
- data/doc/Numeric.html +298 -0
- data/doc/_index.html +167 -0
- data/doc/class_list.html +54 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +58 -0
- data/doc/css/style.css +490 -0
- data/doc/file.README.html +780 -0
- data/doc/file_list.html +59 -0
- data/doc/frames.html +22 -0
- data/doc/index.html +780 -0
- data/doc/js/app.js +395 -0
- data/doc/js/full_list.js +244 -0
- data/doc/js/jquery.js +4 -0
- data/doc/method_list.html +814 -0
- data/doc/top-level-namespace.html +112 -0
- data/lib/fat_date/date.rb +25 -10
- data/lib/fat_date/date_time.rb +17 -0
- data/lib/fat_date/version.rb +1 -1
- data/lib/fat_date.rb +22 -7
- metadata +41 -3
data/doc/index.html
ADDED
|
@@ -0,0 +1,780 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>
|
|
7
|
+
File: README
|
|
8
|
+
|
|
9
|
+
— Documentation by YARD 0.9.38
|
|
10
|
+
|
|
11
|
+
</title>
|
|
12
|
+
|
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css" />
|
|
14
|
+
|
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" />
|
|
16
|
+
|
|
17
|
+
<script type="text/javascript">
|
|
18
|
+
pathId = "README";
|
|
19
|
+
relpath = '';
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
|
24
|
+
|
|
25
|
+
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
</head>
|
|
29
|
+
<body>
|
|
30
|
+
<div class="nav_wrap">
|
|
31
|
+
<iframe id="nav" src="class_list.html?1"></iframe>
|
|
32
|
+
<div id="resizer"></div>
|
|
33
|
+
</div>
|
|
34
|
+
|
|
35
|
+
<div id="main" tabindex="-1">
|
|
36
|
+
<div id="header">
|
|
37
|
+
<div id="menu">
|
|
38
|
+
|
|
39
|
+
<a href="_index.html">Index</a> »
|
|
40
|
+
<span class="title">File: README</span>
|
|
41
|
+
|
|
42
|
+
</div>
|
|
43
|
+
|
|
44
|
+
<div id="search">
|
|
45
|
+
|
|
46
|
+
<a class="full_list_link" id="class_list_link"
|
|
47
|
+
href="class_list.html">
|
|
48
|
+
|
|
49
|
+
<svg width="24" height="24">
|
|
50
|
+
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
|
|
51
|
+
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
|
|
52
|
+
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
|
|
53
|
+
</svg>
|
|
54
|
+
</a>
|
|
55
|
+
|
|
56
|
+
</div>
|
|
57
|
+
<div class="clear"></div>
|
|
58
|
+
</div>
|
|
59
|
+
|
|
60
|
+
<div id="content"><div id='filecontents'><ul>
|
|
61
|
+
<li><a href="#org5409ea7">Introduction</a></li>
|
|
62
|
+
<li><a href="#orga0e91c5">Version</a></li>
|
|
63
|
+
<li><a href="#org5f1dd2c">Installation</a></li>
|
|
64
|
+
<li><a href="#org5370e37">Usage</a>
|
|
65
|
+
|
|
66
|
+
<ul>
|
|
67
|
+
<li><a href="#orga3509b5">Constants</a></li>
|
|
68
|
+
<li><a href="#org6982753">Ensure</a></li>
|
|
69
|
+
<li><a href="#orgf1df8b2">Formatting</a></li>
|
|
70
|
+
<li><a href="#orgbd46647">Chunks</a></li>
|
|
71
|
+
<li><a href="#org699b533">Parsing American Dates</a></li>
|
|
72
|
+
<li><a href="#org156cfb2">Holidays and Workdays</a></li>
|
|
73
|
+
<li><a href="#orgb99874d">Ordinal Weekdays in Month</a></li>
|
|
74
|
+
<li><a href="#org16ce332">Easter</a></li>
|
|
75
|
+
<li><a href="#org90aeba3">Date Specs</a></li>
|
|
76
|
+
</ul></li>
|
|
77
|
+
<li><a href="#org4b44d01">Contributing</a></li>
|
|
78
|
+
</ul>
|
|
79
|
+
|
|
80
|
+
<p><a href="https://github.com/ddoherty03/fat_date/actions/workflows/ruby.yml"><img src="https://github.com/ddoherty03/fat_date/actions/workflows/ruby.yml/badge.svg?branch=master" alt="CI"></a></p>
|
|
81
|
+
|
|
82
|
+
<p><a id="org5409ea7"></a></p>
|
|
83
|
+
|
|
84
|
+
<h1 id="introduction">Introduction</h1>
|
|
85
|
+
|
|
86
|
+
<p><code>fat_date</code> collects core extensions for the Date class to make it more useful in financial applications, including:</p>
|
|
87
|
+
|
|
88
|
+
<ul>
|
|
89
|
+
<li> determining when a <code>Date</code> is a federal or NYSE holiday with Presidential decrees included,</li>
|
|
90
|
+
<li> determining when a <code>Date</code> is part of a larger calendar-related "chunk," such as a year, half, quarter, bimonth, month, semimonth, or week,</li>
|
|
91
|
+
<li> calculating Easter for a <code>Date's</code> year, a date on which some "movable feasts" depend, and</li>
|
|
92
|
+
<li> parsing so-called "specs" that allow the beginning or ending <code>Date</code> of a larger period of time to be returned, a facility put to good use in the <a href="https://github.com/ddoherty03/fat_period">FatPeriod</a> gem.</li>
|
|
93
|
+
</ul>
|
|
94
|
+
|
|
95
|
+
<p><a id="orga0e91c5"></a></p>
|
|
96
|
+
|
|
97
|
+
<h1 id="version">Version</h1>
|
|
98
|
+
|
|
99
|
+
<pre class="code ruby"><code class="ruby"><span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='const'><span class='object_link'><a href="FatDate.html" title="FatDate (module)">FatDate</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="FatDate.html#VERSION-constant" title="FatDate::VERSION (constant)">VERSION</a></span></span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span>
|
|
100
|
+
</code></pre>
|
|
101
|
+
|
|
102
|
+
<pre class="code ruby"><code class="ruby">0.1.4
|
|
103
|
+
</code></pre>
|
|
104
|
+
|
|
105
|
+
<p><a id="org5f1dd2c"></a></p>
|
|
106
|
+
|
|
107
|
+
<h1 id="installation">Installation</h1>
|
|
108
|
+
|
|
109
|
+
<p>Add this line to your application's Gemfile:</p>
|
|
110
|
+
|
|
111
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_gem'>gem</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>fat_date</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='symbol'>:git</span> <span class='op'>=></span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>https://github.com/ddoherty03/fat_date.git</span><span class='tstring_end'>'</span></span>
|
|
112
|
+
</code></pre>
|
|
113
|
+
|
|
114
|
+
<p>And then execute:</p>
|
|
115
|
+
|
|
116
|
+
<pre class="code sh"><code class="sh">$ bundle
|
|
117
|
+
</code></pre>
|
|
118
|
+
|
|
119
|
+
<p>Or install it yourself as:</p>
|
|
120
|
+
|
|
121
|
+
<pre class="code sh"><code class="sh">$ gem install fat_date
|
|
122
|
+
</code></pre>
|
|
123
|
+
|
|
124
|
+
<p><a id="org5370e37"></a></p>
|
|
125
|
+
|
|
126
|
+
<h1 id="usage">Usage</h1>
|
|
127
|
+
|
|
128
|
+
<p>Many of these have little that is of general interest, but there are a few goodies.</p>
|
|
129
|
+
|
|
130
|
+
<p><a id="orga3509b5"></a></p>
|
|
131
|
+
|
|
132
|
+
<h3 id="constants">Constants</h3>
|
|
133
|
+
|
|
134
|
+
<p><code>FatDate</code> adds two date constants to the <code>Date</code> class, Date::BOT and Date::EOT. These represent the earliest and latest dates of practical commercial interest. The exact values are rather arbitrary, but they prove useful in date ranges, for example. They are defined as:</p>
|
|
135
|
+
|
|
136
|
+
<ul>
|
|
137
|
+
<li> <strong><code>Date::BOT</code>:</strong> January 1, 1900</li>
|
|
138
|
+
<li> <strong><code>Date::EOT</code>:</strong> December 31, 3000</li>
|
|
139
|
+
<li> <strong><code>Date::FEDERAL_DECREED_HOLIDAYS</code>:</strong> an Array of dates declared as non-work days for federal employees by presidential proclamation</li>
|
|
140
|
+
<li> <strong><code>Date::PRESIDENTIAL_FUNERALS</code>:</strong> an Array of dates of presidential funerals, which are observed with a closing of most federal agencies</li>
|
|
141
|
+
</ul>
|
|
142
|
+
|
|
143
|
+
<p><a id="org6982753"></a></p>
|
|
144
|
+
|
|
145
|
+
<h3 id="ensure">Ensure</h3>
|
|
146
|
+
|
|
147
|
+
<p>The <code>Date.ensure</code> class method tries to convert its argument to a <code>Date</code> object by (1) applying the <code>#to_date</code> method or (2) applying the <code>Date.parse</code> method to a String. This is handy when you want to define a method that takes a date argument but want the caller to be able to supply anything that can reasonably be converted to a <code>Date</code>:</p>
|
|
148
|
+
|
|
149
|
+
<pre class="code ruby"><code class="ruby"><span class='kw'>def</span> <span class='id identifier rubyid_tomorow_tomorrow'>tomorow_tomorrow</span><span class='lparen'>(</span><span class='id identifier rubyid_arg'>arg</span><span class='rparen'>)</span>
|
|
150
|
+
<span class='id identifier rubyid_from'>from</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="Date.html" title="Date (class)">Date</a></span></span><span class='period'>.</span><span class='id identifier rubyid_ensure'>ensure</span><span class='lparen'>(</span><span class='id identifier rubyid_arg'>arg</span><span class='rparen'>)</span> <span class='comment'># => ArgumentError: cannot convert class 'Array' to a Date or DateTime
|
|
151
|
+
</span> <span class='id identifier rubyid_from'>from</span> <span class='op'>+</span> <span class='int'>2</span><span class='period'>.</span><span class='id identifier rubyid_days'>days</span> <span class='comment'># => Mon, 03 Jun 2024, Wed, 16 Oct 2024 05:47:30 -0500, Sun, 03 Mar 2024
|
|
152
|
+
</span><span class='kw'>end</span> <span class='comment'># => :tomorow_tomorrow
|
|
153
|
+
</span>
|
|
154
|
+
<span class='id identifier rubyid_tomorow_tomorrow'>tomorow_tomorrow</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>June 1</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span>
|
|
155
|
+
</code></pre>
|
|
156
|
+
|
|
157
|
+
<pre class="code ruby"><code class="ruby"><span class='int'>2025</span><span class='op'>-</span><span class='int'>06</span><span class='op'>-</span><span class='int'>03</span>
|
|
158
|
+
</code></pre>
|
|
159
|
+
|
|
160
|
+
<p>If you give it a Time, it will return a <code>DateTime</code></p>
|
|
161
|
+
|
|
162
|
+
<pre class="code ruby"><code class="ruby"><span class='lbracket'>[</span><span class='const'>Time</span><span class='period'>.</span><span class='id identifier rubyid_now'>now</span><span class='comma'>,</span> <span class='id identifier rubyid_tomorow_tomorrow'>tomorow_tomorrow</span><span class='lparen'>(</span><span class='const'>Time</span><span class='period'>.</span><span class='id identifier rubyid_now'>now</span><span class='rparen'>)</span><span class='rbracket'>]</span>
|
|
163
|
+
</code></pre>
|
|
164
|
+
|
|
165
|
+
<pre class="code ruby"><code class="ruby">[2025-12-24 05:12:00.897539094 -0600, Fri, 26 Dec 2025 05:12:00 -0600]
|
|
166
|
+
</code></pre>
|
|
167
|
+
|
|
168
|
+
<p>But it's only as good as Date.parse! If all it sees is 'March', it returns March 1 of the current year.</p>
|
|
169
|
+
|
|
170
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_tomorow_tomorrow'>tomorow_tomorrow</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Ides of March</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span>
|
|
171
|
+
</code></pre>
|
|
172
|
+
|
|
173
|
+
<pre class="code ruby"><code class="ruby"><span class='int'>2025</span><span class='op'>-</span><span class='int'>03</span><span class='op'>-</span><span class='int'>03</span>
|
|
174
|
+
</code></pre>
|
|
175
|
+
|
|
176
|
+
<p><a id="orgf1df8b2"></a></p>
|
|
177
|
+
|
|
178
|
+
<h3 id="formatting">Formatting</h3>
|
|
179
|
+
|
|
180
|
+
<p><code>FatDate</code> provides some concise methods for printing string versions of dates that are often useful:</p>
|
|
181
|
+
|
|
182
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_d'>d</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="Date.html" title="Date (class)">Date</a></span></span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>1957-09-22</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
|
183
|
+
<span class='id identifier rubyid_methods'>methods</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>iso</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>num</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>tex_quote</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>eng</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>american</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>org</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span>
|
|
184
|
+
<span class='id identifier rubyid_tab'>tab</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
|
|
185
|
+
<span class='id identifier rubyid_tab'>tab</span> <span class='op'><<</span> <span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Description</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Result</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span>
|
|
186
|
+
<span class='id identifier rubyid_tab'>tab</span> <span class='op'><<</span> <span class='kw'>nil</span>
|
|
187
|
+
<span class='id identifier rubyid_methods'>methods</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_m'>m</span><span class='op'>|</span>
|
|
188
|
+
<span class='id identifier rubyid_tab'>tab</span> <span class='op'><<</span> <span class='lbracket'>[</span><span class='id identifier rubyid_m'>m</span><span class='comma'>,</span> <span class='id identifier rubyid_d'>d</span><span class='period'>.</span><span class='id identifier rubyid_send'>send</span><span class='lparen'>(</span><span class='id identifier rubyid_m'>m</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span><span class='rparen'>)</span><span class='rbracket'>]</span>
|
|
189
|
+
<span class='kw'>end</span>
|
|
190
|
+
<span class='id identifier rubyid_tab'>tab</span> <span class='op'><<</span> <span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>org(active: true)</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='id identifier rubyid_d'>d</span><span class='period'>.</span><span class='id identifier rubyid_org'>org</span><span class='lparen'>(</span><span class='label'>active:</span> <span class='kw'>true</span><span class='rparen'>)</span><span class='rbracket'>]</span>
|
|
191
|
+
</code></pre>
|
|
192
|
+
|
|
193
|
+
<pre class="code ruby"><code class="ruby">| Description | Result |
|
|
194
|
+
|-------------------+--------------------|
|
|
195
|
+
| iso | 1957-09-22 |
|
|
196
|
+
| num | 19570922 |
|
|
197
|
+
| tex_quote | 1957--09--22 |
|
|
198
|
+
| eng | September 22, 1957 |
|
|
199
|
+
| american | 9/22/1957 |
|
|
200
|
+
| org | [1957-09-22 Sun] |
|
|
201
|
+
| org(active: true) | <1957-09-22 Sun> |
|
|
202
|
+
</code></pre>
|
|
203
|
+
|
|
204
|
+
<p>Most of these are self-explanatory, but a couple are not. The <code>Date.org(active: false)</code> method formats a date as an Emacs org-mode timestamp, by default an inactive timestamp that does not show up in the org agenda, but can be made active with the optional parameter <code>active:</code> set to a truthy value. See <a href="https://orgmode.org/manual/Timestamps.html#Timestamps">https://orgmode.org/manual/Timestamps.html#Timestamps</a>.</p>
|
|
205
|
+
|
|
206
|
+
<p>The <code>#tex_quote</code> method formats the date in iso form but using TeX's convention of using en-dashes to separate the components.</p>
|
|
207
|
+
|
|
208
|
+
<p><a id="orgbd46647"></a></p>
|
|
209
|
+
|
|
210
|
+
<h3 id="chunks">Chunks</h3>
|
|
211
|
+
|
|
212
|
+
<p>Many of the methods provided by <code>FatDate</code> deal with various calendar periods that are less common than those provided by the Ruby Standard Library or gems such as <code>active_support</code>. This documentation refers to these calendar periods as "chunks", and they are the following:</p>
|
|
213
|
+
|
|
214
|
+
<ul>
|
|
215
|
+
<li> year,</li>
|
|
216
|
+
<li> half,</li>
|
|
217
|
+
<li> quarter,</li>
|
|
218
|
+
<li> bimonth,</li>
|
|
219
|
+
<li> month,</li>
|
|
220
|
+
<li> semimonth,</li>
|
|
221
|
+
<li> biweek,</li>
|
|
222
|
+
<li> week, and</li>
|
|
223
|
+
<li> day</li>
|
|
224
|
+
</ul>
|
|
225
|
+
|
|
226
|
+
<p><code>FatDate</code> provides methods that query whether the date falls on the beginning or end of each of these chunks:</p>
|
|
227
|
+
|
|
228
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_tab'>tab</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
|
|
229
|
+
<span class='id identifier rubyid_tab'>tab</span> <span class='op'><<</span> <span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Subject Date</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Method</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Result</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span>
|
|
230
|
+
<span class='id identifier rubyid_tab'>tab</span> <span class='op'><<</span> <span class='kw'>nil</span>
|
|
231
|
+
<span class='id identifier rubyid_d'>d</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="Date.html" title="Date (class)">Date</a></span></span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>2017-06-30</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
|
232
|
+
<span class='qsymbols_beg'>%i[</span><span class='tstring_content'>beginning</span><span class='words_sep'> </span><span class='tstring_content'>end</span><span class='tstring_end'>]</span></span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_side'>side</span><span class='op'>|</span>
|
|
233
|
+
<span class='qsymbols_beg'>%i(</span><span class='tstring_content'>year</span><span class='words_sep'> </span><span class='tstring_content'>half</span><span class='words_sep'> </span><span class='tstring_content'>quarter</span><span class='words_sep'> </span><span class='tstring_content'>bimonth</span><span class='words_sep'> </span><span class='tstring_content'>month</span><span class='words_sep'> </span><span class='tstring_content'>semimonth</span><span class='words_sep'> </span><span class='tstring_content'>biweek</span><span class='words_sep'> </span><span class='tstring_content'>week</span><span class='tstring_end'>)</span></span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_chunk'>chunk</span><span class='op'>|</span>
|
|
234
|
+
<span class='id identifier rubyid_meth'>meth</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_side'>side</span><span class='embexpr_end'>}</span><span class='tstring_content'>_of_</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_chunk'>chunk</span><span class='embexpr_end'>}</span><span class='tstring_content'>?</span><span class='tstring_end'>"</span></span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span>
|
|
235
|
+
<span class='id identifier rubyid_tab'>tab</span> <span class='op'><<</span> <span class='lbracket'>[</span><span class='id identifier rubyid_d'>d</span><span class='period'>.</span><span class='id identifier rubyid_iso'>iso</span><span class='comma'>,</span> <span class='id identifier rubyid_meth'>meth</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_d'>d</span><span class='period'>.</span><span class='id identifier rubyid_send'>send</span><span class='lparen'>(</span><span class='id identifier rubyid_meth'>meth</span><span class='rparen'>)</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span><span class='rbracket'>]</span>
|
|
236
|
+
<span class='kw'>end</span>
|
|
237
|
+
<span class='kw'>end</span>
|
|
238
|
+
<span class='id identifier rubyid_tab'>tab</span>
|
|
239
|
+
</code></pre>
|
|
240
|
+
|
|
241
|
+
<pre class="code ruby"><code class="ruby">| Subject Date | Method | Result |
|
|
242
|
+
|--------------+-------------------------+--------|
|
|
243
|
+
| 2017-06-30 | beginning_of_year? | false |
|
|
244
|
+
| 2017-06-30 | beginning_of_half? | false |
|
|
245
|
+
| 2017-06-30 | beginning_of_quarter? | false |
|
|
246
|
+
| 2017-06-30 | beginning_of_bimonth? | false |
|
|
247
|
+
| 2017-06-30 | beginning_of_month? | false |
|
|
248
|
+
| 2017-06-30 | beginning_of_semimonth? | false |
|
|
249
|
+
| 2017-06-30 | beginning_of_biweek? | false |
|
|
250
|
+
| 2017-06-30 | beginning_of_week? | false |
|
|
251
|
+
| 2017-06-30 | end_of_year? | false |
|
|
252
|
+
| 2017-06-30 | end_of_half? | true |
|
|
253
|
+
| 2017-06-30 | end_of_quarter? | true |
|
|
254
|
+
| 2017-06-30 | end_of_bimonth? | true |
|
|
255
|
+
| 2017-06-30 | end_of_month? | true |
|
|
256
|
+
| 2017-06-30 | end_of_semimonth? | true |
|
|
257
|
+
| 2017-06-30 | end_of_biweek? | false |
|
|
258
|
+
| 2017-06-30 | end_of_week? | false |
|
|
259
|
+
</code></pre>
|
|
260
|
+
|
|
261
|
+
<p>It also provides corresponding methods that return the date at the beginning or end of the calendar chunk, starting at the given date:</p>
|
|
262
|
+
|
|
263
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_tab'>tab</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
|
|
264
|
+
<span class='id identifier rubyid_tab'>tab</span> <span class='op'><<</span> <span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Subject Date</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Method</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Result</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span>
|
|
265
|
+
<span class='id identifier rubyid_tab'>tab</span> <span class='op'><<</span> <span class='kw'>nil</span>
|
|
266
|
+
<span class='id identifier rubyid_d'>d</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="Date.html" title="Date (class)">Date</a></span></span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>2017-04-21</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
|
267
|
+
<span class='qsymbols_beg'>%i[</span><span class='tstring_content'>beginning</span><span class='words_sep'> </span><span class='tstring_content'>end</span><span class='tstring_end'>]</span></span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_side'>side</span><span class='op'>|</span>
|
|
268
|
+
<span class='qsymbols_beg'>%i(</span><span class='tstring_content'>year</span><span class='words_sep'> </span><span class='tstring_content'>half</span><span class='words_sep'> </span><span class='tstring_content'>quarter</span><span class='words_sep'> </span><span class='tstring_content'>bimonth</span><span class='words_sep'> </span><span class='tstring_content'>month</span><span class='words_sep'> </span><span class='tstring_content'>semimonth</span><span class='words_sep'> </span><span class='tstring_content'>biweek</span><span class='words_sep'> </span><span class='tstring_content'>week</span><span class='words_sep'> </span><span class='tstring_end'>)</span></span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_chunk'>chunk</span><span class='op'>|</span>
|
|
269
|
+
<span class='id identifier rubyid_meth'>meth</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_side'>side</span><span class='embexpr_end'>}</span><span class='tstring_content'>_of_</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_chunk'>chunk</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span>
|
|
270
|
+
<span class='id identifier rubyid_tab'>tab</span> <span class='op'><<</span> <span class='lbracket'>[</span><span class='id identifier rubyid_d'>d</span><span class='period'>.</span><span class='id identifier rubyid_iso'>iso</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>d.</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_meth'>meth</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_d'>d</span><span class='period'>.</span><span class='id identifier rubyid_send'>send</span><span class='lparen'>(</span><span class='id identifier rubyid_meth'>meth</span><span class='rparen'>)</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span><span class='rbracket'>]</span>
|
|
271
|
+
<span class='kw'>end</span>
|
|
272
|
+
<span class='kw'>end</span>
|
|
273
|
+
<span class='id identifier rubyid_tab'>tab</span>
|
|
274
|
+
</code></pre>
|
|
275
|
+
|
|
276
|
+
<pre class="code ruby"><code class="ruby">| Subject Date | Method | Result |
|
|
277
|
+
|--------------+--------------------------+------------|
|
|
278
|
+
| 2017-04-21 | d.beginning_of_year | 2017-01-01 |
|
|
279
|
+
| 2017-04-21 | d.beginning_of_half | 2017-01-01 |
|
|
280
|
+
| 2017-04-21 | d.beginning_of_quarter | 2017-04-01 |
|
|
281
|
+
| 2017-04-21 | d.beginning_of_bimonth | 2017-03-01 |
|
|
282
|
+
| 2017-04-21 | d.beginning_of_month | 2017-04-01 |
|
|
283
|
+
| 2017-04-21 | d.beginning_of_semimonth | 2017-04-16 |
|
|
284
|
+
| 2017-04-21 | d.beginning_of_biweek | 2017-04-10 |
|
|
285
|
+
| 2017-04-21 | d.beginning_of_week | 2017-04-17 |
|
|
286
|
+
| 2017-04-21 | d.end_of_year | 2017-12-31 |
|
|
287
|
+
| 2017-04-21 | d.end_of_half | 2017-06-30 |
|
|
288
|
+
| 2017-04-21 | d.end_of_quarter | 2017-06-30 |
|
|
289
|
+
| 2017-04-21 | d.end_of_bimonth | 2017-04-30 |
|
|
290
|
+
| 2017-04-21 | d.end_of_month | 2017-04-30 |
|
|
291
|
+
| 2017-04-21 | d.end_of_semimonth | 2017-04-30 |
|
|
292
|
+
| 2017-04-21 | d.end_of_biweek | 2017-04-23 |
|
|
293
|
+
| 2017-04-21 | d.end_of_week | 2017-04-23 |
|
|
294
|
+
</code></pre>
|
|
295
|
+
|
|
296
|
+
<p>You can query which numerical half, quarter, etc. that a given date falls in:</p>
|
|
297
|
+
|
|
298
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_tab'>tab</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
|
|
299
|
+
<span class='id identifier rubyid_tab'>tab</span> <span class='op'><<</span> <span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Subject Date</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Method</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Result</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span>
|
|
300
|
+
<span class='id identifier rubyid_tab'>tab</span> <span class='op'><<</span> <span class='kw'>nil</span>
|
|
301
|
+
<span class='qsymbols_beg'>%i(</span><span class='tstring_content'>year</span><span class='words_sep'> </span><span class='tstring_content'>half</span><span class='words_sep'> </span><span class='tstring_content'>quarter</span><span class='words_sep'> </span><span class='tstring_content'>bimonth</span><span class='words_sep'> </span><span class='tstring_content'>month</span><span class='words_sep'> </span><span class='tstring_content'>semimonth</span><span class='words_sep'> </span><span class='tstring_content'>biweek</span><span class='words_sep'> </span><span class='tstring_content'>week</span><span class='words_sep'> </span><span class='tstring_end'>)</span></span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_chunk'>chunk</span><span class='op'>|</span>
|
|
302
|
+
<span class='id identifier rubyid_d'>d</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="Date.html" title="Date (class)">Date</a></span></span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>2017-04-21</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='op'>+</span> <span class='id identifier rubyid_rand'>rand</span><span class='lparen'>(</span><span class='int'>100</span><span class='rparen'>)</span>
|
|
303
|
+
<span class='id identifier rubyid_meth'>meth</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_chunk'>chunk</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span>
|
|
304
|
+
<span class='id identifier rubyid_tab'>tab</span> <span class='op'><<</span> <span class='lbracket'>[</span><span class='id identifier rubyid_d'>d</span><span class='period'>.</span><span class='id identifier rubyid_iso'>iso</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>d.</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_meth'>meth</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>in </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_chunk'>chunk</span><span class='embexpr_end'>}</span><span class='tstring_content'> number </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_d'>d</span><span class='period'>.</span><span class='id identifier rubyid_send'>send</span><span class='lparen'>(</span><span class='id identifier rubyid_meth'>meth</span><span class='rparen'>)</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span><span class='rbracket'>]</span>
|
|
305
|
+
<span class='kw'>end</span>
|
|
306
|
+
<span class='id identifier rubyid_tab'>tab</span>
|
|
307
|
+
</code></pre>
|
|
308
|
+
|
|
309
|
+
<pre class="code ruby"><code class="ruby">| Subject Date | Method | Result |
|
|
310
|
+
|--------------+-------------+-----------------------|
|
|
311
|
+
| 2017-06-04 | d.year | in year number 2017 |
|
|
312
|
+
| 2017-05-01 | d.half | in half number 1 |
|
|
313
|
+
| 2017-05-03 | d.quarter | in quarter number 2 |
|
|
314
|
+
| 2017-04-29 | d.bimonth | in bimonth number 2 |
|
|
315
|
+
| 2017-06-14 | d.month | in month number 6 |
|
|
316
|
+
| 2017-04-29 | d.semimonth | in semimonth number 8 |
|
|
317
|
+
| 2017-05-20 | d.biweek | in biweek number 10 |
|
|
318
|
+
| 2017-06-12 | d.week | in week number 24 |
|
|
319
|
+
</code></pre>
|
|
320
|
+
|
|
321
|
+
<p><a id="org699b533"></a></p>
|
|
322
|
+
|
|
323
|
+
<h3 id="parsing-american-dates">Parsing American Dates</h3>
|
|
324
|
+
|
|
325
|
+
<p>Americans often write dates in the form M/d/Y, and the normal parse method will parse such a string as d/M/Y, often resulting in invalid date errors. <code>FatDate</code> adds the specialty parsing method, <code>Date.parse_american</code> to handle such strings.</p>
|
|
326
|
+
|
|
327
|
+
<pre class="code ruby"><code class="ruby"><span class='kw'>begin</span>
|
|
328
|
+
<span class='id identifier rubyid_ss'>ss</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>9/22/1957</span><span class='tstring_end'>'</span></span>
|
|
329
|
+
<span class='const'><span class='object_link'><a href="Date.html" title="Date (class)">Date</a></span></span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='id identifier rubyid_ss'>ss</span><span class='rparen'>)</span>
|
|
330
|
+
<span class='kw'>rescue</span> <span class='const'><span class='object_link'><a href="Date.html" title="Date (class)">Date</a></span></span><span class='op'>::</span><span class='const'>Error</span> <span class='op'>=></span> <span class='id identifier rubyid_ex'>ex</span>
|
|
331
|
+
<span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Date.parse('</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_ss'>ss</span><span class='embexpr_end'>}</span><span class='tstring_content'>') raises </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_ex'>ex</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'> (</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_ex'>ex</span><span class='embexpr_end'>}</span><span class='tstring_content'>), but</span><span class='tstring_end'>"</span></span>
|
|
332
|
+
<span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Date.parse_american('</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_ss'>ss</span><span class='embexpr_end'>}</span><span class='tstring_content'>') => </span><span class='embexpr_beg'>#{</span><span class='const'><span class='object_link'><a href="Date.html" title="Date (class)">Date</a></span></span><span class='period'>.</span><span class='id identifier rubyid_parse_american'>parse_american</span><span class='lparen'>(</span><span class='id identifier rubyid_ss'>ss</span><span class='rparen'>)</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span>
|
|
333
|
+
<span class='kw'>end</span>
|
|
334
|
+
</code></pre>
|
|
335
|
+
|
|
336
|
+
<pre class="code ruby"><code class="ruby">=> false
|
|
337
|
+
Date.parse('9/22/1957') raises Date::Error (invalid date), but
|
|
338
|
+
Date.parse_american('9/22/1957') => 1957-09-22
|
|
339
|
+
=> nil
|
|
340
|
+
:org_babel_ruby_eoe
|
|
341
|
+
</code></pre>
|
|
342
|
+
|
|
343
|
+
<p><a id="org156cfb2"></a></p>
|
|
344
|
+
|
|
345
|
+
<h3 id="holidays-and-workdays">Holidays and Workdays</h3>
|
|
346
|
+
|
|
347
|
+
<ol>
|
|
348
|
+
<li><p>Federal</p>
|
|
349
|
+
|
|
350
|
+
<p>One of the original motivations for this library was to provide an easy way to determine whether a given date is a federal holiday in the United States or, nearly but not quite the same, a non-trading day on the New York Stock Exchange. To that end, <code>FatDate</code> provides the following methods:</p></li>
|
|
351
|
+
</ol>
|
|
352
|
+
|
|
353
|
+
<pre class="code ruby"><code class="ruby">- Date#weekend? &#x2013; is this date on a weekend?
|
|
354
|
+
- Date#weekday? &#x2013; is this date on a week day?
|
|
355
|
+
- Date#easter\_this\_year &#x2013; the date of Easter in the Date's year
|
|
356
|
+
|
|
357
|
+
Methods concerning Federal holidays:
|
|
358
|
+
|
|
359
|
+
- Date#fed\_holiday? &#x2013; is this date a Federal holiday? It knows about obscurities such as holidays decreed by past Presidents, dates of Presidential funerals, and the Federal rule for when holidays fall on a weekend, whether it is moved to the prior Friday or the following Monday.
|
|
360
|
+
- Date#fed\_workday? &#x2013; is it a date when Federal government offices are open?, inverse of Date#fed\_holiday?
|
|
361
|
+
- Date#add\_fed\_workdays(n) &#x2013; n Federal workdays following (or preceding if n negative) this date,
|
|
362
|
+
- Date#next\_fed\_workday &#x2013; the next Federal workday following this date,
|
|
363
|
+
- Date#prior\_fed\_workday &#x2013; the previous Federal workday before this date,
|
|
364
|
+
- Date#next\_until\_fed\_workday &#x2013; starting with this date, move forward until we hit a Federal workday
|
|
365
|
+
- Date#prior\_until\_fed\_workday &#x2013; starting with this date, move back until we hit a Federal workday
|
|
366
|
+
|
|
367
|
+
Whether a particular date is a federal holiday is complicated. Certain holidays are statutory as set forth in [5 U.S.C. §6103](https://www.govinfo.gov/content/pkg/USCODE-2024-title5/pdf/USCODE-2024-title5-partIII-subpartE-chap61-subchapI-sec6103.pdf). But if the holiday falls on a Saturday, the prior Friday is observed; if on a Sunday, the following Monday is observed. Inauguration Day after 1965 is observed by employees in Washington, D.C., and surrounding areas, effectively shutting down most federal agencies.
|
|
368
|
+
|
|
369
|
+
On top of that the days of Presidential funeral are federal holidays. On top of that, each President can decree temporary holidays by Executive Order, often to give employees Christmas Eve and the day after Christmas the day off if they would not otherwise be off. The `fat_date` library attempts to capture all of this, but the days of Presidential decrees are only good for the last decade or so.
|
|
370
|
+
|
|
371
|
+
Here is a sampling:
|
|
372
|
+
|
|
373
|
+
```ruby
|
|
374
|
+
result = []
|
|
375
|
+
result << ['Date', 'Federal Holiday?', 'Comment']
|
|
376
|
+
result << nil
|
|
377
|
+
result << ['2014-05-16', Date.parse('2014-05-16').fed_holiday?, 'Nuttin special']
|
|
378
|
+
result << ['2014-05-18', Date.parse('2014-05-18').fed_holiday?, 'A weekend']
|
|
379
|
+
result << ['2014-01-01', Date.parse('2014-01-01').fed_holiday?, 'New Year']
|
|
380
|
+
result << ['1963-11-25', Date.parse('1963-11-25').fed_holiday?, 'JFK Funeral']
|
|
381
|
+
result << ['1973-01-25', Date.parse('1973-01-25').fed_holiday?, 'LBJ Funeral']
|
|
382
|
+
result << ['2003-12-25', Date.parse('2003-12-25').fed_holiday?, 'Christmas']
|
|
383
|
+
result << ['1961-01-20', Date.parse('1961-01-20').fed_holiday?, 'JFK Inauguration (before 1965)']
|
|
384
|
+
result << ['1969-01-20', Date.parse('1969-01-20').fed_holiday?, 'RMN Inauguration (after 1965)']
|
|
385
|
+
result << ['2012-12-24', Date.parse('2012-12-24').fed_holiday?, 'Christmas Eve Decreed by Obama']
|
|
386
|
+
result << ['2003-12-26', Date.parse('2003-12-26').fed_holiday?, 'Friday after Christmas']
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
```
|
|
390
|
+
| Date | Federal Holiday? | Comment |
|
|
391
|
+
|------------+------------------+--------------------------------|
|
|
392
|
+
| 2014-05-16 | false | Nuttin special |
|
|
393
|
+
| 2014-05-18 | true | A weekend |
|
|
394
|
+
| 2014-01-01 | true | New Year |
|
|
395
|
+
| 1963-11-25 | true | JFK Funeral |
|
|
396
|
+
| 1973-01-25 | true | LBJ Funeral |
|
|
397
|
+
| 2003-12-25 | true | Christmas |
|
|
398
|
+
| 1961-01-20 | false | JFK Inauguration (before 1965) |
|
|
399
|
+
| 1969-01-20 | true | RMN Inauguration (after 1965) |
|
|
400
|
+
| 2012-12-24 | true | Christmas Eve Decreed by Obama |
|
|
401
|
+
| 2003-12-26 | true | Friday after Christmas |
|
|
402
|
+
```
|
|
403
|
+
</code></pre>
|
|
404
|
+
|
|
405
|
+
<ol>
|
|
406
|
+
<li><p>NYSE</p>
|
|
407
|
+
|
|
408
|
+
<p>And we have similar methods for "holidays" or non-trading days on the NYSE:</p></li>
|
|
409
|
+
</ol>
|
|
410
|
+
|
|
411
|
+
<pre class="code ruby"><code class="ruby">- Date#nyse\_holiday? &#x2013; is this date a NYSE holiday?
|
|
412
|
+
- Date#nyse\_workday? &#x2013; is it a date when the NYSE is open for trading?, inverse of Date#nyse\_holiday?
|
|
413
|
+
- Date#add\_nyse\_workdays(n) &#x2013; n NYSE workdays following (or preceding if n negative) this date,
|
|
414
|
+
- Date#next\_nyse\_workday &#x2013; the next NYSE workday following this date,
|
|
415
|
+
- Date#prior\_nyse\_workday &#x2013; the previous NYSE workday before this date,
|
|
416
|
+
- Date#next\_until\_nyse\_~~workday &#x2013; starting with this date, move forward until we hit a NYSE workday
|
|
417
|
+
- Date#prior\_until\_nyse\_workday &#x2013; starting with this date, move back until we hit a Federal workday
|
|
418
|
+
|
|
419
|
+
Likewise, days on which the NYSE is closed can be gotten with:
|
|
420
|
+
|
|
421
|
+
```ruby
|
|
422
|
+
Date.parse('2014-04-18').nyse_holiday?
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
```
|
|
426
|
+
true
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
```ruby
|
|
430
|
+
date_comments = [
|
|
431
|
+
['2014-04-18', 'Good Friday'],
|
|
432
|
+
['2014-05-18', 'Weekend'],
|
|
433
|
+
['2014-05-21', 'Any old day'],
|
|
434
|
+
['2014-01-01', 'New Year']
|
|
435
|
+
]
|
|
436
|
+
result = []
|
|
437
|
+
result << ['Date', 'Federal Holiday?', 'NYSE Holiday?', 'Comment']
|
|
438
|
+
result << nil
|
|
439
|
+
date_comments.each do |str, comment|
|
|
440
|
+
d = Date.parse(str)
|
|
441
|
+
result << [d.org, d.fed_holiday?, d.nyse_holiday?, comment]
|
|
442
|
+
end
|
|
443
|
+
result
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
```
|
|
447
|
+
| Date | Federal Holiday? | NYSE Holiday? | Comment |
|
|
448
|
+
|------------------+------------------+---------------+-------------|
|
|
449
|
+
| [2014-04-18 Fri] | false | true | Good Friday |
|
|
450
|
+
| [2014-05-18 Sun] | true | true | Weekend |
|
|
451
|
+
| [2014-05-21 Wed] | false | false | Any old day |
|
|
452
|
+
| [2014-01-01 Wed] | true | true | New Year |
|
|
453
|
+
```
|
|
454
|
+
</code></pre>
|
|
455
|
+
|
|
456
|
+
<p><a id="orgb99874d"></a></p>
|
|
457
|
+
|
|
458
|
+
<h3 id="ordinal-weekdays-in-month">Ordinal Weekdays in Month</h3>
|
|
459
|
+
|
|
460
|
+
<p>It is often useful to find the 1st, 2nd, etc, Sunday, Monday, etc. in a given month. <code>FatDate</code> provides the class method <code>Date.nth_wday_in_year_month(nth, wday, year, month)</code> to return such dates. The first parameter can be negative, which will count from the end of the month.</p>
|
|
461
|
+
|
|
462
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_results'>results</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
|
|
463
|
+
<span class='id identifier rubyid_results'>results</span> <span class='op'><<</span> <span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>n</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Year</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Month</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>nth Thursday</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span>
|
|
464
|
+
<span class='id identifier rubyid_results'>results</span> <span class='op'><<</span> <span class='kw'>nil</span>
|
|
465
|
+
<span class='lparen'>(</span><span class='int'>1</span><span class='op'>..</span><span class='int'>4</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_n'>n</span><span class='op'>|</span>
|
|
466
|
+
<span class='id identifier rubyid_d'>d</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="Date.html" title="Date (class)">Date</a></span></span><span class='period'>.</span><span class='id identifier rubyid_nth_wday_in_year_month'>nth_wday_in_year_month</span><span class='lparen'>(</span><span class='id identifier rubyid_n'>n</span><span class='comma'>,</span> <span class='int'>4</span><span class='comma'>,</span> <span class='int'>2024</span><span class='comma'>,</span> <span class='int'>6</span><span class='rparen'>)</span>
|
|
467
|
+
<span class='id identifier rubyid_results'>results</span> <span class='op'><<</span> <span class='lbracket'>[</span><span class='id identifier rubyid_n'>n</span><span class='comma'>,</span> <span class='id identifier rubyid_d'>d</span><span class='period'>.</span><span class='id identifier rubyid_year'>year</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>June</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='id identifier rubyid_d'>d</span><span class='period'>.</span><span class='id identifier rubyid_org'>org</span><span class='rbracket'>]</span>
|
|
468
|
+
<span class='kw'>end</span>
|
|
469
|
+
<span class='lparen'>(</span><span class='op'>-</span><span class='int'>4</span><span class='op'>..</span><span class='op'>-</span><span class='int'>1</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_a'>to_a</span><span class='period'>.</span><span class='id identifier rubyid_reverse'>reverse</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_n'>n</span><span class='op'>|</span>
|
|
470
|
+
<span class='id identifier rubyid_d'>d</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="Date.html" title="Date (class)">Date</a></span></span><span class='period'>.</span><span class='id identifier rubyid_nth_wday_in_year_month'>nth_wday_in_year_month</span><span class='lparen'>(</span><span class='id identifier rubyid_n'>n</span><span class='comma'>,</span> <span class='int'>4</span><span class='comma'>,</span> <span class='int'>2024</span><span class='comma'>,</span> <span class='int'>6</span><span class='rparen'>)</span>
|
|
471
|
+
<span class='id identifier rubyid_results'>results</span> <span class='op'><<</span> <span class='lbracket'>[</span><span class='id identifier rubyid_n'>n</span><span class='comma'>,</span> <span class='id identifier rubyid_d'>d</span><span class='period'>.</span><span class='id identifier rubyid_year'>year</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>June</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='id identifier rubyid_d'>d</span><span class='period'>.</span><span class='id identifier rubyid_org'>org</span><span class='rbracket'>]</span>
|
|
472
|
+
<span class='kw'>end</span>
|
|
473
|
+
<span class='id identifier rubyid_results'>results</span>
|
|
474
|
+
</code></pre>
|
|
475
|
+
|
|
476
|
+
<pre class="code ruby"><code class="ruby">| n | Year | Month | nth Thursday |
|
|
477
|
+
|----+------+-------+------------------|
|
|
478
|
+
| 1 | 2024 | June | [2024-06-06 Thu] |
|
|
479
|
+
| 2 | 2024 | June | [2024-06-13 Thu] |
|
|
480
|
+
| 3 | 2024 | June | [2024-06-20 Thu] |
|
|
481
|
+
| 4 | 2024 | June | [2024-06-27 Thu] |
|
|
482
|
+
| -1 | 2024 | June | [2024-06-27 Thu] |
|
|
483
|
+
| -2 | 2024 | June | [2024-06-20 Thu] |
|
|
484
|
+
| -3 | 2024 | June | [2024-06-13 Thu] |
|
|
485
|
+
| -4 | 2024 | June | [2024-06-06 Thu] |
|
|
486
|
+
</code></pre>
|
|
487
|
+
|
|
488
|
+
<p><a id="org16ce332"></a></p>
|
|
489
|
+
|
|
490
|
+
<h3 id="easter">Easter</h3>
|
|
491
|
+
|
|
492
|
+
<p>Many holidays in the West are determined by the date of Easter, so FatDate provides the class method <code>Date.easter(year)</code> to return the date of Easter for the given year, using the Julian calendar date before the year of reform, and using the Gregorian calendar beginning in the year of reform. By default, it uses 1582 for the date of reform, but it can take a named parameter, <code>reform_year:</code> to specify a different date. For England, the year of reform was September, 1752. So, to get a historically accurate date of Easter for Anglicans between 1582 and 1752, you should use a reform_year of 1753, since the reform happened after Easter in 1752.</p>
|
|
493
|
+
|
|
494
|
+
<ul>
|
|
495
|
+
<li> <strong><code>Date.easter(year, reform_year: 1582)</code>:</strong> return the date of Easter for the given <code>year</code>, assuming the given year of calendar reform; return nil for any year before 30AD.</li>
|
|
496
|
+
<li> <strong>Date#easter_this_year:</strong> return the date of Easter for the year in which the subject Date falls.</li>
|
|
497
|
+
<li> <strong>Date#easter?:</strong> return whether the subject Date is Easter.</li>
|
|
498
|
+
</ul>
|
|
499
|
+
|
|
500
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_yrs'>yrs</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='int'>800</span><span class='comma'>,</span> <span class='int'>1000</span><span class='comma'>,</span> <span class='int'>1200</span><span class='comma'>,</span> <span class='int'>1400</span><span class='comma'>,</span> <span class='int'>1500</span><span class='comma'>,</span> <span class='int'>1600</span><span class='comma'>,</span> <span class='int'>1800</span><span class='comma'>,</span> <span class='int'>2000</span><span class='rbracket'>]</span>
|
|
501
|
+
<span class='id identifier rubyid_result'>result</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
|
|
502
|
+
<span class='id identifier rubyid_result'>result</span> <span class='op'><<</span> <span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Year</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Easter Date</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span>
|
|
503
|
+
<span class='id identifier rubyid_result'>result</span> <span class='op'><<</span> <span class='kw'>nil</span>
|
|
504
|
+
<span class='id identifier rubyid_yrs'>yrs</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_y'>y</span><span class='op'>|</span>
|
|
505
|
+
<span class='id identifier rubyid_result'>result</span> <span class='op'><<</span> <span class='lbracket'>[</span><span class='id identifier rubyid_y'>y</span><span class='comma'>,</span> <span class='const'><span class='object_link'><a href="Date.html" title="Date (class)">Date</a></span></span><span class='period'>.</span><span class='id identifier rubyid_easter'>easter</span><span class='lparen'>(</span><span class='id identifier rubyid_y'>y</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_org'>org</span> <span class='rbracket'>]</span>
|
|
506
|
+
<span class='kw'>end</span>
|
|
507
|
+
<span class='id identifier rubyid_result'>result</span>
|
|
508
|
+
</code></pre>
|
|
509
|
+
|
|
510
|
+
<pre class="code ruby"><code class="ruby">| Year | Easter Date |
|
|
511
|
+
|------+------------------|
|
|
512
|
+
| 800 | [0800-04-19 Wed] |
|
|
513
|
+
| 1000 | [1000-03-31 Mon] |
|
|
514
|
+
| 1200 | [1200-04-09 Sun] |
|
|
515
|
+
| 1400 | [1400-04-18 Fri] |
|
|
516
|
+
| 1500 | [1500-04-19 Thu] |
|
|
517
|
+
| 1600 | [1600-04-02 Sun] |
|
|
518
|
+
| 1800 | [1800-04-13 Sun] |
|
|
519
|
+
| 2000 | [2000-04-23 Sun] |
|
|
520
|
+
</code></pre>
|
|
521
|
+
|
|
522
|
+
<p><a id="org90aeba3"></a></p>
|
|
523
|
+
|
|
524
|
+
<h3 id="date-specs">Date Specs</h3>
|
|
525
|
+
|
|
526
|
+
<p>It is often desirable to get the first or last date of a specified time period. For this <code>FatDate</code> provides the <code>spec</code> method that takes a string and an optional <code>spec_type</code> parameter of either <code>:from</code>, indicating that the first date of the period should be returned or <code>:to</code>, indicating that the last date of the period should be returned. It assumes the <code>spec_type</code> to be <code>:from</code> by default.</p>
|
|
527
|
+
|
|
528
|
+
<p>Though many specs, other than those specifying a single day, represent a period of time longer than one date, the <code>Date.spec</code> method returns a single date, either the first or last day of the period described by the spec. See the library <code>FatPeriod</code> where the <code>Date.spec</code> method is put to good use in defining a <code>Period</code> type to represent ranges of time.</p>
|
|
529
|
+
|
|
530
|
+
<p>The <code>spec</code> method supports a rich set of ways to specify periods of time. The following sections catalog them all.</p>
|
|
531
|
+
|
|
532
|
+
<ol>
|
|
533
|
+
<li> Given Day</li>
|
|
534
|
+
</ol>
|
|
535
|
+
|
|
536
|
+
<pre class="code ruby"><code class="ruby">- **YYYY-MM-DD:** returns a single day given.
|
|
537
|
+
- **MM-DD:** returns the specified day of the specified month in the current year.
|
|
538
|
+
</code></pre>
|
|
539
|
+
|
|
540
|
+
<ol>
|
|
541
|
+
<li> Day-of-Year</li>
|
|
542
|
+
</ol>
|
|
543
|
+
|
|
544
|
+
<pre class="code ruby"><code class="ruby">- **YYYY-ddd:** returns the ddd'th day of the specified year. Note that exactly three digits are needed: with only two digits it would be interpreted as a month.
|
|
545
|
+
- **ddd:** returns the ddd'th day of the current year. Again, note that exactly three digits are needed: two digits would be interpreted as a month, and four digits as a year.
|
|
546
|
+
</code></pre>
|
|
547
|
+
|
|
548
|
+
<ol>
|
|
549
|
+
<li><p>Month</p>
|
|
550
|
+
|
|
551
|
+
<p>The following return the first or last day of the given month.</p></li>
|
|
552
|
+
</ol>
|
|
553
|
+
|
|
554
|
+
<pre class="code ruby"><code class="ruby">- **YYYY-MM:** returns the first or last day of the specified month in the specified year.
|
|
555
|
+
- **MM:** returns first or last day of the specified month of the current year.
|
|
556
|
+
</code></pre>
|
|
557
|
+
|
|
558
|
+
<ol>
|
|
559
|
+
<li> Year</li>
|
|
560
|
+
</ol>
|
|
561
|
+
|
|
562
|
+
<pre class="code ruby"><code class="ruby">- **YYYY:** returns the first or last day of the specified year.
|
|
563
|
+
</code></pre>
|
|
564
|
+
|
|
565
|
+
<ol>
|
|
566
|
+
<li> Commercial Weeks-of-Year</li>
|
|
567
|
+
</ol>
|
|
568
|
+
|
|
569
|
+
<pre class="code ruby"><code class="ruby">- **YYYY-Wnn or YYYY-nnW:** returns the first or last day of the nn'th commercial week of the given year according to the ISO 8601 standard, in which the week containing the first Thursday of the year counts as the first commercial week, even if that week started in the prior calendar year,
|
|
570
|
+
- **Wnn or nnW:** returns the first or last day of the nn'th commercial week of the current year,
|
|
571
|
+
</code></pre>
|
|
572
|
+
|
|
573
|
+
<ol>
|
|
574
|
+
<li> Halves</li>
|
|
575
|
+
</ol>
|
|
576
|
+
|
|
577
|
+
<pre class="code ruby"><code class="ruby">- **YYYY-1H or YYYY-2H:** returns the first or last day of the specified half year for the given year,
|
|
578
|
+
- **1H or 2H:** returns the first or last day of the specified half year for the current year,
|
|
579
|
+
</code></pre>
|
|
580
|
+
|
|
581
|
+
<ol>
|
|
582
|
+
<li> Quarters</li>
|
|
583
|
+
</ol>
|
|
584
|
+
|
|
585
|
+
<pre class="code ruby"><code class="ruby">- **YYYY-1Q, YYYY-2Q, etc :** returns the first or last day of the calendar quarter for the given year,
|
|
586
|
+
- **1Q, 2Q, etc :** returns the first or last day of the calendar quarter for the current year,
|
|
587
|
+
</code></pre>
|
|
588
|
+
|
|
589
|
+
<ol>
|
|
590
|
+
<li> Semi-Months</li>
|
|
591
|
+
</ol>
|
|
592
|
+
|
|
593
|
+
<pre class="code ruby"><code class="ruby">- **YYYY-MM-A or YYYY-MM-B:** returns the first or last day of the semi-month for the given month and year, where the first semi-month always runs from the 1st to the 15th and the second semi-month always runs from the 16th to the last day of the given month, regardless of the number of days in the month.
|
|
594
|
+
- **MM-A or MM-B:** returns the first or last day of the semi-month of the current year.
|
|
595
|
+
- **A or B:** returns the first or last day of the semi-month of the current year and month.
|
|
596
|
+
</code></pre>
|
|
597
|
+
|
|
598
|
+
<ol>
|
|
599
|
+
<li> Week-of-Month</li>
|
|
600
|
+
</ol>
|
|
601
|
+
|
|
602
|
+
<pre class="code ruby"><code class="ruby">- **YYYY-MM-i or YYYY-MM-ii up to YYYY-MM-vi:** returns the first or last day of the given week within the month, including any partial weeks,
|
|
603
|
+
- **MM-i or MM-ii up to MM-vi:** returns the first or last day of the given week within the month of the current year, including any partial weeks,
|
|
604
|
+
- **i or ii up to vi:** returns the first or last day of the given week within the current month of the current year, including any partial weeks,
|
|
605
|
+
</code></pre>
|
|
606
|
+
|
|
607
|
+
<ol>
|
|
608
|
+
<li>Day-of-Week</li>
|
|
609
|
+
</ol>
|
|
610
|
+
|
|
611
|
+
<pre class="code ruby"><code class="ruby">- **YYYY-MM-nSu up to YYYY-MM-nSa :** returns the single day that is the n'th Sunday, Monday, etc., in the given month using the first two letters of the English names for the days of the week,
|
|
612
|
+
- **MM-nSu up to MM-nSa or MM-nSun up to MM-nSat:** returns the single date that is the n'th Sunday, Monday, etc., in the given month of the current year using the first two letters of the English names for the days of the week,
|
|
613
|
+
- **nSu up to nSa or nSun up to nSat:** returns the single date that is the n'th Sunday, Monday, etc., in the current month of the current year using the first two letters of the English names for the days of the week,
|
|
614
|
+
</code></pre>
|
|
615
|
+
|
|
616
|
+
<ol>
|
|
617
|
+
<li>Easter Based</li>
|
|
618
|
+
</ol>
|
|
619
|
+
|
|
620
|
+
<pre class="code ruby"><code class="ruby">- **YYYY-E:** returns the single date of Easter in the Western church for the given year,
|
|
621
|
+
- **E:** returns the single date of Easter in the Western church for the current year,
|
|
622
|
+
- **YYYY-E-n or YYYY-E+n:** returns the single date that falls n days before (-) or after (+) Easter in the Western church for the given year,
|
|
623
|
+
- **E-n or E+n:** returns the single date that falls n days before (-) or after (+) Easter in the Western church for the current year,
|
|
624
|
+
</code></pre>
|
|
625
|
+
|
|
626
|
+
<ol>
|
|
627
|
+
<li>Relative Dates</li>
|
|
628
|
+
</ol>
|
|
629
|
+
|
|
630
|
+
<pre class="code ruby"><code class="ruby">- **yesterday or yesteryear or lastday or last\_year, etc:** the relative prefixes, 'last' or 'yester' prepended to any chunk name returns the period named by the chunk that precedes today's date.
|
|
631
|
+
- **today or toyear or this-year or thissemimonth, etc:** the relative prefixes, 'to' or 'this' prepended to any chunk name returns the period named by the chunk that contains today's date.
|
|
632
|
+
- **nextday or nextyear or next-year or nextsemimonth, etc:** the relative prefixes, 'next' prepended to any chunk name returns the period named by the chunk that follows today's date. As a special case, 'tomorrow' is treated as equivalent to 'nextday'.
|
|
633
|
+
</code></pre>
|
|
634
|
+
|
|
635
|
+
<ol>
|
|
636
|
+
<li>Extremes</li>
|
|
637
|
+
</ol>
|
|
638
|
+
|
|
639
|
+
<pre class="code ruby"><code class="ruby">- **forever:** returns Date::BOT for :from, and Date::EOT for :to, which, for financial applications is meant to stand in for eternity.
|
|
640
|
+
- **never:** returns nil, representing no date.
|
|
641
|
+
</code></pre>
|
|
642
|
+
|
|
643
|
+
<ol>
|
|
644
|
+
<li><p>Skip Modifiers</p>
|
|
645
|
+
|
|
646
|
+
<p>Appended to any of the above specs (other than 'never'), you may add a 'skip modifier' to change the date to the first day-of-week adjacent to the date that the spec resolves to. This is done by appending one of the following to the spec:</p></li>
|
|
647
|
+
</ol>
|
|
648
|
+
|
|
649
|
+
<pre class="code ruby"><code class="ruby">- **'<Su', '<Mo', &#x2026; '<Sa':** skip to the first Sunday, Monday, etc., *before* the date the spec resolves to.
|
|
650
|
+
- **'<=Su', '<=Mo', &#x2026; '<=Sa':** skip to the first Sunday, Monday, etc., *on or before* the date the spec resolves to.
|
|
651
|
+
- **'>Su', '>Mo', &#x2026; '>Sa':** skip to the first Sunday, Monday, etc., *after* the date the spec resolves to.
|
|
652
|
+
- **'>=Su', '>=Mo', &#x2026; '>=Sa':** skip to the first Sunday, Monday, etc., *on or after* the date the spec resolves to.
|
|
653
|
+
|
|
654
|
+
For example, `Date.spec('2024<=Tu', :to)` resolves to the last Tuesday of 2024, which happens to be December 31, 2024; `Date.spec('2024<Tu', :to)`, on the other hand would resolve to December 24, 2024, since it looks for the first Tuesday strictly *before* December 31, 2024.
|
|
655
|
+
</code></pre>
|
|
656
|
+
|
|
657
|
+
<ol>
|
|
658
|
+
<li><p>Conventions</p>
|
|
659
|
+
|
|
660
|
+
<p>Some things to note with respect to <code>Date.spec</code>:</p>
|
|
661
|
+
|
|
662
|
+
<ol>
|
|
663
|
+
<li> The second argument can be either <code>:from</code> or <code>:to</code>, but it defaults to <code>:from</code>. If it is <code>:from</code>, <code>spec</code> returns the first date of the specified period; if it is <code>:to</code>, it returns the last date of the specified period. When the "period" resolves to a single day, both arguments return the same date, so <code>spec('2024-E', :from)</code> and <code>spec('2024-E', :to)</code> both result in March 31, 2024.</li>
|
|
664
|
+
<li> Where relevant, <code>spec</code> accepts letters of either upper or lower case: so 2024-1Q can be written 2024-1q and 'yesteryear' can be written 'YeSterYeaR', and likewise for all components of the spec using letters.</li>
|
|
665
|
+
<li> Date components can be separated with either a hyphen, as in the examples above, or with a '/' as is common. Thus, 2024-11-09 can also be 2024/11/09, or indeed, 2024/11-09 or 2024-11/09.</li>
|
|
666
|
+
<li> The prefixes for relative periods can be separated from the period name by a hyphen, and underscore, or by nothing at all. Thus, yester-day, yester_day, and yesterday are all acceptable. Neologisms such as 'yestermonth' are quaint, but not harmful.</li>
|
|
667
|
+
<li> Where the names of days of the week are appropriate, any word that starts with 'su' counts as Sunday, regardless of case, any word that starts with 'mo' counts as Monday, and so on.</li>
|
|
668
|
+
<li> 'fortnight' is a synonym for a biweek.</li>
|
|
669
|
+
</ol></li>
|
|
670
|
+
<li><p>Examples</p>
|
|
671
|
+
|
|
672
|
+
<p>The following examples demonstrate all of the date specs available.</p>
|
|
673
|
+
|
|
674
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_strs'>strs</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>today</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>2024-07-04</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>2024-05</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>2024</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>2024-333</span><span class='tstring_end'>'</span></span><span class='comma'>,</span>
|
|
675
|
+
<span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>08</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>08-12</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>2024-W36</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>2024-36W</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>W36</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>36W</span><span class='tstring_end'>'</span></span><span class='comma'>,</span>
|
|
676
|
+
<span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>2024-1H</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>2024-2H</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>1H</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>2H</span><span class='tstring_end'>'</span></span><span class='comma'>,</span>
|
|
677
|
+
<span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>1957-1Q</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>1957-2Q</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>1957-3Q</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>1957-4Q</span><span class='tstring_end'>'</span></span><span class='comma'>,</span>
|
|
678
|
+
<span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>1Q</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>2Q</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>3Q</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>4Q</span><span class='tstring_end'>'</span></span><span class='comma'>,</span>
|
|
679
|
+
<span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>2015-06-A</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>2015-06-B</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>06-A</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>06-B</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>A</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>B</span><span class='tstring_end'>'</span></span><span class='comma'>,</span>
|
|
680
|
+
<span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>2021-09-I</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>2021-09-II</span><span class='tstring_end'>'</span></span><span class='comma'>,</span>
|
|
681
|
+
<span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>2021-09-i</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>2021-09-ii</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>2021-09-iii</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>2021-09-iv</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>2021-09-v</span><span class='tstring_end'>'</span></span><span class='comma'>,</span>
|
|
682
|
+
<span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>10-i</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>10-iii</span><span class='tstring_end'>'</span></span><span class='comma'>,</span>
|
|
683
|
+
<span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>2016-04-3Tu</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>2016-11-4Th</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>2016-11-2Th</span><span class='tstring_end'>'</span></span><span class='comma'>,</span>
|
|
684
|
+
<span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>05-3We</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>06-3Wed</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>3Su</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>4Sa</span><span class='tstring_end'>'</span></span><span class='comma'>,</span>
|
|
685
|
+
<span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>1830-E</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>E</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>2012-E+10</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>2024-E+40</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>2026-E<Fri</span><span class='tstring_end'>'</span></span><span class='comma'>,</span>
|
|
686
|
+
<span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>yestermonth</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>lastmonth</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>yesterfortnight</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>thisfortnight</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>nextfortnight</span><span class='tstring_end'>'</span></span><span class='comma'>,</span>
|
|
687
|
+
<span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>2025-E+50>=Su</span><span class='tstring_end'>'</span></span>
|
|
688
|
+
<span class='rbracket'>]</span>
|
|
689
|
+
<span class='id identifier rubyid_tab'>tab</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
|
|
690
|
+
<span class='id identifier rubyid_tab'>tab</span> <span class='op'><<</span> <span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Spec</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>From</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>To</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span>
|
|
691
|
+
<span class='id identifier rubyid_tab'>tab</span> <span class='op'><<</span> <span class='kw'>nil</span>
|
|
692
|
+
<span class='id identifier rubyid_strs'>strs</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_s'>s</span><span class='op'>|</span>
|
|
693
|
+
<span class='id identifier rubyid_tab'>tab</span> <span class='op'><<</span> <span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>'</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_s'>s</span><span class='embexpr_end'>}</span><span class='tstring_content'>'</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='const'><span class='object_link'><a href="Date.html" title="Date (class)">Date</a></span></span><span class='period'>.</span><span class='id identifier rubyid_spec'>spec</span><span class='lparen'>(</span><span class='id identifier rubyid_s'>s</span><span class='comma'>,</span> <span class='symbol'>:from</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_org'>org</span><span class='comma'>,</span> <span class='const'><span class='object_link'><a href="Date.html" title="Date (class)">Date</a></span></span><span class='period'>.</span><span class='id identifier rubyid_spec'>spec</span><span class='lparen'>(</span><span class='id identifier rubyid_s'>s</span><span class='comma'>,</span> <span class='symbol'>:to</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_org'>org</span><span class='rbracket'>]</span>
|
|
694
|
+
<span class='kw'>end</span>
|
|
695
|
+
<span class='id identifier rubyid_tab'>tab</span>
|
|
696
|
+
</code></pre>
|
|
697
|
+
|
|
698
|
+
<pre class="code ruby"><code class="ruby">| Spec | From | To |
|
|
699
|
+
|-------------------+------------------+------------------|
|
|
700
|
+
| 'today' | [2025-12-24 Wed] | [2025-12-24 Wed] |
|
|
701
|
+
| '2024-07-04' | [2024-07-04 Thu] | [2024-07-04 Thu] |
|
|
702
|
+
| '2024-05' | [2024-05-01 Wed] | [2024-05-31 Fri] |
|
|
703
|
+
| '2024' | [2024-01-01 Mon] | [2024-12-31 Tue] |
|
|
704
|
+
| '2024-333' | [2024-11-28 Thu] | [2024-11-28 Thu] |
|
|
705
|
+
| '08' | [2025-08-01 Fri] | [2025-08-31 Sun] |
|
|
706
|
+
| '08-12' | [2025-08-12 Tue] | [2025-08-12 Tue] |
|
|
707
|
+
| '2024-W36' | [2024-09-02 Mon] | [2024-09-08 Sun] |
|
|
708
|
+
| '2024-36W' | [2024-09-02 Mon] | [2024-09-08 Sun] |
|
|
709
|
+
| 'W36' | [2025-09-01 Mon] | [2025-09-07 Sun] |
|
|
710
|
+
| '36W' | [2025-09-01 Mon] | [2025-09-07 Sun] |
|
|
711
|
+
| '2024-1H' | [2024-01-01 Mon] | [2024-06-30 Sun] |
|
|
712
|
+
| '2024-2H' | [2024-07-01 Mon] | [2024-12-31 Tue] |
|
|
713
|
+
| '1H' | [2025-01-01 Wed] | [2025-06-30 Mon] |
|
|
714
|
+
| '2H' | [2025-07-01 Tue] | [2025-12-31 Wed] |
|
|
715
|
+
| '1957-1Q' | [1957-01-01 Tue] | [1957-03-31 Sun] |
|
|
716
|
+
| '1957-2Q' | [1957-04-01 Mon] | [1957-06-30 Sun] |
|
|
717
|
+
| '1957-3Q' | [1957-07-01 Mon] | [1957-09-30 Mon] |
|
|
718
|
+
| '1957-4Q' | [1957-10-01 Tue] | [1957-12-31 Tue] |
|
|
719
|
+
| '1Q' | [2025-01-01 Wed] | [2025-03-31 Mon] |
|
|
720
|
+
| '2Q' | [2025-04-01 Tue] | [2025-06-30 Mon] |
|
|
721
|
+
| '3Q' | [2025-07-01 Tue] | [2025-09-30 Tue] |
|
|
722
|
+
| '4Q' | [2025-10-01 Wed] | [2025-12-31 Wed] |
|
|
723
|
+
| '2015-06-A' | [2015-06-01 Mon] | [2015-06-15 Mon] |
|
|
724
|
+
| '2015-06-B' | [2015-06-16 Tue] | [2015-06-30 Tue] |
|
|
725
|
+
| '06-A' | [2025-06-01 Sun] | [2025-06-15 Sun] |
|
|
726
|
+
| '06-B' | [2025-06-16 Mon] | [2025-06-30 Mon] |
|
|
727
|
+
| 'A' | [2025-12-01 Mon] | [2025-12-15 Mon] |
|
|
728
|
+
| 'B' | [2025-12-16 Tue] | [2025-12-31 Wed] |
|
|
729
|
+
| '2021-09-I' | [2021-09-01 Wed] | [2021-09-05 Sun] |
|
|
730
|
+
| '2021-09-II' | [2021-09-06 Mon] | [2021-09-12 Sun] |
|
|
731
|
+
| '2021-09-i' | [2021-09-01 Wed] | [2021-09-05 Sun] |
|
|
732
|
+
| '2021-09-ii' | [2021-09-06 Mon] | [2021-09-12 Sun] |
|
|
733
|
+
| '2021-09-iii' | [2021-09-13 Mon] | [2021-09-19 Sun] |
|
|
734
|
+
| '2021-09-iv' | [2021-09-20 Mon] | [2021-09-26 Sun] |
|
|
735
|
+
| '2021-09-v' | [2021-09-27 Mon] | [2021-09-30 Thu] |
|
|
736
|
+
| '10-i' | [2025-10-01 Wed] | [2025-10-05 Sun] |
|
|
737
|
+
| '10-iii' | [2025-10-13 Mon] | [2025-10-19 Sun] |
|
|
738
|
+
| '2016-04-3Tu' | [2016-04-19 Tue] | [2016-04-19 Tue] |
|
|
739
|
+
| '2016-11-4Th' | [2016-11-24 Thu] | [2016-11-24 Thu] |
|
|
740
|
+
| '2016-11-2Th' | [2016-11-10 Thu] | [2016-11-10 Thu] |
|
|
741
|
+
| '05-3We' | [2025-05-21 Wed] | [2025-05-21 Wed] |
|
|
742
|
+
| '06-3Wed' | [2025-06-18 Wed] | [2025-06-18 Wed] |
|
|
743
|
+
| '3Su' | [2025-12-21 Sun] | [2025-12-21 Sun] |
|
|
744
|
+
| '4Sa' | [2025-12-27 Sat] | [2025-12-27 Sat] |
|
|
745
|
+
| '1830-E' | [1830-04-11 Sun] | [1830-04-11 Sun] |
|
|
746
|
+
| 'E' | [2025-04-20 Sun] | [2025-04-20 Sun] |
|
|
747
|
+
| '2012-E+10' | [2012-04-18 Wed] | [2012-04-18 Wed] |
|
|
748
|
+
| '2024-E+40' | [2024-05-10 Fri] | [2024-05-10 Fri] |
|
|
749
|
+
| '2026-E<Fri' | [2026-04-03 Fri] | [2026-04-03 Fri] |
|
|
750
|
+
| 'yestermonth' | [2025-11-01 Sat] | [2025-11-30 Sun] |
|
|
751
|
+
| 'lastmonth' | [2025-11-01 Sat] | [2025-11-30 Sun] |
|
|
752
|
+
| 'yesterfortnight' | [2025-12-08 Mon] | [2025-12-21 Sun] |
|
|
753
|
+
| 'thisfortnight' | [2025-12-22 Mon] | [2026-01-04 Sun] |
|
|
754
|
+
| 'nextfortnight' | [2026-01-05 Mon] | [2026-01-18 Sun] |
|
|
755
|
+
| '2025-E+50>=Su' | [2025-06-15 Sun] | [2025-06-15 Sun] |
|
|
756
|
+
</code></pre></li>
|
|
757
|
+
</ol>
|
|
758
|
+
|
|
759
|
+
<p><a id="org4b44d01"></a></p>
|
|
760
|
+
|
|
761
|
+
<h1 id="contributing">Contributing</h1>
|
|
762
|
+
|
|
763
|
+
<ol>
|
|
764
|
+
<li> Fork it (<a href="http://github.com/ddoherty03/fat_date/fork">http://github.com/ddoherty03/fat_date/fork</a> )</li>
|
|
765
|
+
<li> Create your feature branch (<code>git checkout -b my-new-feature</code>)</li>
|
|
766
|
+
<li> Commit your changes (<code>git commit -am 'Add some feature'</code>)</li>
|
|
767
|
+
<li> Push to the branch (<code>git push origin my-new-feature</code>)</li>
|
|
768
|
+
<li> Create new Pull Request</li>
|
|
769
|
+
</ol>
|
|
770
|
+
</div></div>
|
|
771
|
+
|
|
772
|
+
<div id="footer">
|
|
773
|
+
Generated on Wed Dec 24 05:26:32 2025 by
|
|
774
|
+
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
775
|
+
0.9.38 (ruby-3.4.1).
|
|
776
|
+
</div>
|
|
777
|
+
|
|
778
|
+
</div>
|
|
779
|
+
</body>
|
|
780
|
+
</html>
|