docs/Lazier/DateTime/ClassMethods.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
Module: Lazier::DateTime::ClassMethods
— Documentation by YARD 0.9.5
</title>
<link rel="stylesheet" href="../../css/style.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="../../css/common.css" type="text/css" charset="utf-8" />
<script type="text/javascript" charset="utf-8">
pathId = "Lazier::DateTime::ClassMethods";
relpath = '../../';
</script>
<script type="text/javascript" charset="utf-8" src="../../js/jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="../../js/app.js"></script>
</head>
<body>
<div class="nav_wrap">
<iframe id="nav" src="../../class_list.html"></iframe>
<div id="resizer"></div>
</div>
<div id="main" tabindex="-1">
<div id="header">
<div id="menu">
<a href="../../_index.html">Index (C)</a> »
<span class='title'><span class='object_link'><a href="../../Lazier.html" title="Lazier (module)">Lazier</a></span></span> » <span class='title'><span class='object_link'><a href="../DateTime.html" title="Lazier::DateTime (module)">DateTime</a></span></span>
»
<span class="title">ClassMethods</span>
</div>
<div id="search">
<a class="full_list_link" id="class_list_link"
href="../../class_list.html">
<svg width="24" height="24">
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
</svg>
</a>
</div>
<div class="clear"></div>
</div>
<iframe id="search_frame" src="../../class_list.html"></iframe>
<div id="content"><h1>Module: Lazier::DateTime::ClassMethods
</h1>
<div class="box_info">
<dl>
<dt>Defined in:</dt>
<dd>lib/lazier/datetime.rb</dd>
</dl>
</div>
<h2>Overview</h2><div class="docstring">
<div class="discussion">
<p>General methods.</p>
</div>
</div>
<div class="tags">
</div>
<h2>
Instance Method Summary
<small><a href="#" class="summary_toggle">collapse</a></small>
</h2>
<ul class="summary">
<li class="public ">
<span class="summary_signature">
<a href="#custom_format-instance_method" title="#custom_format (instance method)">#<strong>custom_format</strong>(key) ⇒ String </a>
</span>
<span class="summary_desc"><div class='inline'><p>Lookups a custom datetime format.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#days-instance_method" title="#days (instance method)">#<strong>days</strong>(short = true) ⇒ Array </a>
</span>
<span class="summary_desc"><div class='inline'><p>Returns strings representations of days.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#easter-instance_method" title="#easter (instance method)">#<strong>easter</strong>(year = nil) ⇒ Date </a>
</span>
<span class="summary_desc"><div class='inline'><p>Returns the Easter (according to Gregorian calendar) date for the year.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#months-instance_method" title="#months (instance method)">#<strong>months</strong>(short = true) ⇒ Array </a>
</span>
<span class="summary_desc"><div class='inline'><p>Returns strings representations of months.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#valid%3F-instance_method" title="#valid? (instance method)">#<strong>valid?</strong>(value, format = "%F %T") ⇒ Boolean </a>
</span>
<span class="summary_desc"><div class='inline'><p>Checks if the date is valid against to a specific format.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#years-instance_method" title="#years (instance method)">#<strong>years</strong>(offset: 10, also_future: true, reference: nil, as_objects: false) ⇒ Array </a>
</span>
<span class="summary_desc"><div class='inline'><p>Returns a range of years.</p>
</div></span>
</li>
</ul>
<div id="instance_method_details" class="method_details_list">
<h2>Instance Method Details</h2>
<div class="method_details first">
<h3 class="signature first" id="custom_format-instance_method">
#<strong>custom_format</strong>(key) ⇒ <tt><span class='object_link'><a href="../String.html" title="Lazier::String (module)">String</a></span></tt>
</h3><div class="docstring">
<div class="discussion">
<p>Lookups a custom datetime format.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Parameters:</p>
<ul class="param">
<li>
<span class='name'>key</span>
<span class='type'>(<tt>Symbol</tt>)</span>
—
<div class='inline'><p>The name of the format to search.</p>
</div>
</li>
</ul>
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt><span class='object_link'><a href="../String.html" title="Lazier::String (module)">String</a></span></tt>)</span>
—
<div class='inline'><p>The format or the name itself (if the format has not been found).</p>
</div>
</li>
</ul>
<p class="tag_title">See Also:</p>
<ul class="see">
<li><span class='object_link'><a href="../Settings.html#setup_date_formats-instance_method" title="Lazier::Settings#setup_date_formats (method)">Settings#setup_date_formats</a></span></li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
63
64
65</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/lazier/datetime.rb', line 63</span>
<span class='kw'>def</span> <span class='id identifier rubyid_custom_format'>custom_format</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span>
<span class='op'>::</span><span class='const'>Lazier</span><span class='period'>.</span><span class='id identifier rubyid_settings'>settings</span><span class='period'>.</span><span class='id identifier rubyid_date_formats'>date_formats</span><span class='period'>.</span><span class='id identifier rubyid_fetch'>fetch</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="days-instance_method">
#<strong>days</strong>(short = true) ⇒ <tt>Array</tt>
</h3><div class="docstring">
<div class="discussion">
<p>Returns strings representations of days.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Parameters:</p>
<ul class="param">
<li>
<span class='name'>short</span>
<span class='type'>(<tt><span class='object_link'><a href="../Boolean.html" title="Lazier::Boolean (module)">Boolean</a></span></tt>)</span>
<em class="default">(defaults to: <tt>true</tt>)</em>
—
<div class='inline'><p>If return the abbreviated representations.</p>
</div>
</li>
</ul>
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt>Array</tt>)</span>
—
<div class='inline'><p>Return string representations of days.</p>
</div>
</li>
</ul>
<p class="tag_title">See Also:</p>
<ul class="see">
<li><span class='object_link'><a href="../Settings.html#setup_date_names-instance_method" title="Lazier::Settings#setup_date_names (method)">Settings#setup_date_names</a></span></li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
18
19
20
21
22</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/lazier/datetime.rb', line 18</span>
<span class='kw'>def</span> <span class='id identifier rubyid_days'>days</span><span class='lparen'>(</span><span class='id identifier rubyid_short'>short</span> <span class='op'>=</span> <span class='kw'>true</span><span class='rparen'>)</span>
<span class='op'>::</span><span class='const'>Lazier</span><span class='period'>.</span><span class='id identifier rubyid_settings'>settings</span><span class='period'>.</span><span class='id identifier rubyid_date_names'>date_names</span><span class='lbracket'>[</span><span class='id identifier rubyid_short'>short</span> <span class='op'>?</span> <span class='symbol'>:short_days</span> <span class='op'>:</span> <span class='symbol'>:long_days</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span><span class='period'>.</span><span class='id identifier rubyid_with_index'>with_index</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_label'>label</span><span class='comma'>,</span> <span class='id identifier rubyid_index'>index</span><span class='op'>|</span>
<span class='lbrace'>{</span><span class='label'>value:</span> <span class='lparen'>(</span><span class='id identifier rubyid_index'>index</span> <span class='op'>+</span> <span class='int'>1</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='comma'>,</span> <span class='label'>label:</span> <span class='id identifier rubyid_label'>label</span><span class='rbrace'>}</span>
<span class='kw'>end</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="easter-instance_method">
#<strong>easter</strong>(year = nil) ⇒ <tt>Date</tt>
</h3><div class="docstring">
<div class="discussion">
<p>Returns the Easter (according to Gregorian calendar) date for the year.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Parameters:</p>
<ul class="param">
<li>
<span class='name'>year</span>
<span class='type'>(<tt>Fixnum|NilClass</tt>)</span>
<em class="default">(defaults to: <tt>nil</tt>)</em>
—
<div class='inline'><p>The year to compute the date for. Defaults to the current year.</p>
</div>
</li>
</ul>
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt>Date</tt>)</span>
—
<div class='inline'><p>The Easter date for the year.</p>
</div>
</li>
</ul>
<p class="tag_title">See Also:</p>
<ul class="see">
<li><a href="http://en.wikipedia.org/wiki/Computus#Anonymous_Gregorian_algorithm" target="_parent" title="http://en.wikipedia.org/wiki/Computus#Anonymous_Gregorian_algorithm">http://en.wikipedia.org/wiki/Computus#Anonymous_Gregorian_algorithm</a></li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
85
86
87
88
89
90
91
92
93
94
95
96</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/lazier/datetime.rb', line 85</span>
<span class='kw'>def</span> <span class='id identifier rubyid_easter'>easter</span><span class='lparen'>(</span><span class='id identifier rubyid_year'>year</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span>
<span class='id identifier rubyid_year'>year</span> <span class='op'>=</span> <span class='op'>::</span><span class='const'>Date</span><span class='period'>.</span><span class='id identifier rubyid_today'>today</span><span class='period'>.</span><span class='id identifier rubyid_year'>year</span> <span class='kw'>unless</span> <span class='id identifier rubyid_year'>year</span><span class='period'>.</span><span class='id identifier rubyid_integer?'>integer?</span>
<span class='comment'># Compute using Anonymous Gregorian Algorithm: http://en.wikipedia.org/wiki/Computus#Anonymous_Gregorian_algorithm
</span> <span class='id identifier rubyid_data'>data</span> <span class='op'>=</span> <span class='id identifier rubyid_easter_start'>easter_start</span><span class='lparen'>(</span><span class='id identifier rubyid_year'>year</span><span class='rparen'>)</span>
<span class='id identifier rubyid_data'>data</span> <span class='op'>=</span> <span class='id identifier rubyid_easter_divide'>easter_divide</span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span>
<span class='id identifier rubyid_data'>data</span> <span class='op'>=</span> <span class='id identifier rubyid_easter_aggregate'>easter_aggregate</span><span class='lparen'>(</span><span class='id identifier rubyid_year'>year</span><span class='comma'>,</span> <span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span>
<span class='id identifier rubyid_data'>data</span> <span class='op'>=</span> <span class='id identifier rubyid_easter_prepare'>easter_prepare</span><span class='lparen'>(</span><span class='id identifier rubyid_year'>year</span><span class='comma'>,</span> <span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span>
<span class='id identifier rubyid_day'>day</span><span class='comma'>,</span> <span class='id identifier rubyid_month'>month</span> <span class='op'>=</span> <span class='id identifier rubyid_easter_end'>easter_end</span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span>
<span class='op'>::</span><span class='const'>Date</span><span class='period'>.</span><span class='id identifier rubyid_civil'>civil</span><span class='lparen'>(</span><span class='id identifier rubyid_year'>year</span><span class='comma'>,</span> <span class='id identifier rubyid_month'>month</span><span class='comma'>,</span> <span class='id identifier rubyid_day'>day</span><span class='rparen'>)</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="months-instance_method">
#<strong>months</strong>(short = true) ⇒ <tt>Array</tt>
</h3><div class="docstring">
<div class="discussion">
<p>Returns strings representations of months.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Parameters:</p>
<ul class="param">
<li>
<span class='name'>short</span>
<span class='type'>(<tt><span class='object_link'><a href="../Boolean.html" title="Lazier::Boolean (module)">Boolean</a></span></tt>)</span>
<em class="default">(defaults to: <tt>true</tt>)</em>
—
<div class='inline'><p>If return the abbreviated representations.</p>
</div>
</li>
</ul>
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt>Array</tt>)</span>
—
<div class='inline'><p>Return string representations of months.</p>
</div>
</li>
</ul>
<p class="tag_title">See Also:</p>
<ul class="see">
<li><span class='object_link'><a href="../Settings.html#setup_date_names-instance_method" title="Lazier::Settings#setup_date_names (method)">Settings#setup_date_names</a></span></li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
29
30
31
32
33</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/lazier/datetime.rb', line 29</span>
<span class='kw'>def</span> <span class='id identifier rubyid_months'>months</span><span class='lparen'>(</span><span class='id identifier rubyid_short'>short</span> <span class='op'>=</span> <span class='kw'>true</span><span class='rparen'>)</span>
<span class='op'>::</span><span class='const'>Lazier</span><span class='period'>.</span><span class='id identifier rubyid_settings'>settings</span><span class='period'>.</span><span class='id identifier rubyid_date_names'>date_names</span><span class='lbracket'>[</span><span class='id identifier rubyid_short'>short</span> <span class='op'>?</span> <span class='symbol'>:short_months</span> <span class='op'>:</span> <span class='symbol'>:long_months</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span><span class='period'>.</span><span class='id identifier rubyid_with_index'>with_index</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_label'>label</span><span class='comma'>,</span> <span class='id identifier rubyid_index'>index</span><span class='op'>|</span>
<span class='lbrace'>{</span><span class='label'>value:</span> <span class='lparen'>(</span><span class='id identifier rubyid_index'>index</span> <span class='op'>+</span> <span class='int'>1</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='period'>.</span><span class='id identifier rubyid_rjust'>rjust</span><span class='lparen'>(</span><span class='int'>2</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>0</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='comma'>,</span> <span class='label'>label:</span> <span class='id identifier rubyid_label'>label</span><span class='rbrace'>}</span>
<span class='kw'>end</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="valid?-instance_method">
#<strong>valid?</strong>(value, format = "%F %T") ⇒ <tt><span class='object_link'><a href="../Boolean.html" title="Lazier::Boolean (module)">Boolean</a></span></tt>
</h3><div class="docstring">
<div class="discussion">
<p>Checks if the date is valid against to a specific format.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Parameters:</p>
<ul class="param">
<li>
<span class='name'>value</span>
<span class='type'>(<tt><span class='object_link'><a href="../String.html" title="Lazier::String (module)">String</a></span></tt>)</span>
—
<div class='inline'><p>The value to check.</p>
</div>
</li>
<li>
<span class='name'>format</span>
<span class='type'>(<tt><span class='object_link'><a href="../String.html" title="Lazier::String (module)">String</a></span></tt>)</span>
<em class="default">(defaults to: <tt>"%F %T"</tt>)</em>
—
<div class='inline'><p>The format to check the value against.</p>
</div>
</li>
</ul>
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt><span class='object_link'><a href="../Boolean.html" title="Lazier::Boolean (module)">Boolean</a></span></tt>)</span>
—
<div class='inline'><p><code>true</code> if the value is valid against the format, <code>false</code> otherwise.</p>
</div>
</li>
</ul>
<p class="tag_title">See Also:</p>
<ul class="see">
<li>DateTime#custom_format</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
73
74
75
76
77
78</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/lazier/datetime.rb', line 73</span>
<span class='kw'>def</span> <span class='id identifier rubyid_valid?'>valid?</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='comma'>,</span> <span class='id identifier rubyid_format'>format</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>%F %T</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
<span class='op'>::</span><span class='const'>DateTime</span><span class='period'>.</span><span class='id identifier rubyid_strptime'>strptime</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='comma'>,</span> <span class='id identifier rubyid_custom_format'>custom_format</span><span class='lparen'>(</span><span class='id identifier rubyid_format'>format</span><span class='rparen'>)</span><span class='rparen'>)</span>
<span class='kw'>true</span>
<span class='kw'>rescue</span>
<span class='kw'>false</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="years-instance_method">
#<strong>years</strong>(offset: 10, also_future: true, reference: nil, as_objects: false) ⇒ <tt>Array</tt>
</h3><div class="docstring">
<div class="discussion">
<p>Returns a range of years.</p>
<p><code>ruby
Date.years(3, false, 2010)
# => [2007, 2008, 2009, 2010]
</code></p>
<p><code>ruby
Date.years(1, true, 2010, true)
# => [{:value=>2009, :label=>2009}, {:value=>2010, :label=>2010}, {:value=>2011, :label=>2011}]
</code></p>
</div>
</div>
<div class="tags">
<p class="tag_title">Parameters:</p>
<ul class="param">
<li>
<span class='name'>offset</span>
<span class='type'>(<tt>Fixnum</tt>)</span>
—
<div class='inline'><p>The width of the range.</p>
</div>
</li>
<li>
<span class='name'>also_future</span>
<span class='type'>(<tt><span class='object_link'><a href="../Boolean.html" title="Lazier::Boolean (module)">Boolean</a></span></tt>)</span>
—
<div class='inline'><p>If return also future years.</p>
</div>
</li>
<li>
<span class='name'>reference</span>
<span class='type'>(<tt>Fixnum|NilClass</tt>)</span>
—
<div class='inline'><p>The ending (or middle, if <code>also_future</code> is <code>true</code>) value of the range. Defaults to the current year.</p>
</div>
</li>
<li>
<span class='name'>as_objects</span>
<span class='type'>(<tt><span class='object_link'><a href="../Boolean.html" title="Lazier::Boolean (module)">Boolean</a></span></tt>)</span>
—
<div class='inline'><p>Whether to return years in hashes with <code>:value</code> and <code>label</code> keys.</p>
</div>
</li>
</ul>
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt>Array</tt>)</span>
—
<div class='inline'><p>A range of years. Every entry is</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
53
54
55
56</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/lazier/datetime.rb', line 53</span>
<span class='kw'>def</span> <span class='id identifier rubyid_years'>years</span><span class='lparen'>(</span><span class='label'>offset:</span> <span class='int'>10</span><span class='comma'>,</span> <span class='label'>also_future:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>reference:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>as_objects:</span> <span class='kw'>false</span><span class='rparen'>)</span>
<span class='id identifier rubyid_y'>y</span> <span class='op'>=</span> <span class='id identifier rubyid_reference'>reference</span> <span class='op'>||</span> <span class='op'>::</span><span class='const'>Date</span><span class='period'>.</span><span class='id identifier rubyid_today'>today</span><span class='period'>.</span><span class='id identifier rubyid_year'>year</span>
<span class='lparen'>(</span><span class='id identifier rubyid_y'>y</span> <span class='op'>-</span> <span class='id identifier rubyid_offset'>offset</span><span class='op'>..</span><span class='lparen'>(</span><span class='id identifier rubyid_also_future'>also_future</span> <span class='op'>?</span> <span class='id identifier rubyid_y'>y</span> <span class='op'>+</span> <span class='id identifier rubyid_offset'>offset</span> <span class='op'>:</span> <span class='id identifier rubyid_y'>y</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_year'>year</span><span class='op'>|</span> <span class='id identifier rubyid_as_objects'>as_objects</span> <span class='op'>?</span> <span class='lbrace'>{</span><span class='label'>value:</span> <span class='id identifier rubyid_year'>year</span><span class='comma'>,</span> <span class='label'>label:</span> <span class='id identifier rubyid_year'>year</span><span class='rbrace'>}</span> <span class='op'>:</span> <span class='id identifier rubyid_year'>year</span> <span class='rbrace'>}</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
</div>
</div>
<div id="footer">
Generated on Thu Nov 10 11:39:24 2016 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.9.5 (ruby-2.3.0).
</div>
</div>
</body>
</html>