docs/Lazier/DateTime.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
Module: Lazier::DateTime
— 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";
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 (D)</a> »
<span class='title'><span class='object_link'><a href="../Lazier.html" title="Lazier (module)">Lazier</a></span></span>
»
<span class="title">DateTime</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
</h1>
<div class="box_info">
<dl>
<dt>Extended by:</dt>
<dd>ActiveSupport::Concern</dd>
</dl>
<dl>
<dt>Defined in:</dt>
<dd>lib/lazier/datetime.rb</dd>
</dl>
</div>
<h2>Overview</h2><div class="docstring">
<div class="discussion">
<p>Extensions for date and time objects.</p>
</div>
</div>
<div class="tags">
</div><h2>Defined Under Namespace</h2>
<p class="children">
<strong class="modules">Modules:</strong> <span class='object_link'><a href="DateTime/ClassMethods.html" title="Lazier::DateTime::ClassMethods (module)">ClassMethods</a></span>
</p>
<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="#format-instance_method" title="#format (instance method)">#<strong>format</strong>(format = nil, custom: true, change_time_zone: false) ⇒ String </a>
</span>
<span class="summary_desc"><div class='inline'><p>Formats a datetime, eventually looking up also custom formats and/or moving to the current timezone.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#months_since_year-instance_method" title="#months_since_year (instance method)">#<strong>months_since_year</strong>(base = nil) ⇒ Fixnum </a>
</span>
<span class="summary_desc"><div class='inline'><p>Returns the number of months passed between the beginning of the base year and the current date.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#padded_month-instance_method" title="#padded_month (instance method)">#<strong>padded_month</strong> ⇒ String </a>
</span>
<span class="summary_desc"><div class='inline'><p>Returns the current month number with a leading zero if needed.</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="format-instance_method">
#<strong>format</strong>(format = nil, custom: true, change_time_zone: false) ⇒ <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>Formats a datetime, eventually looking up also custom formats and/or moving to the current timezone.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Parameters:</p>
<ul class="param">
<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>|NilClass</tt>)</span>
<em class="default">(defaults to: <tt>nil</tt>)</em>
—
<div class='inline'><p>A format or a custom format name to use for formatting.</p>
</div>
</li>
<li>
<span class='name'>custom</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 use custom formats.</p>
</div>
</li>
<li>
<span class='name'>change_time_zone</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 move the date to the current timezone.</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 formatted date.</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">
171
172
173
174
175</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/lazier/datetime.rb', line 171</span>
<span class='kw'>def</span> <span class='id identifier rubyid_format'>format</span><span class='lparen'>(</span><span class='id identifier rubyid_format'>format</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>custom:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>change_time_zone:</span> <span class='kw'>false</span><span class='rparen'>)</span>
<span class='id identifier rubyid_target'>target</span> <span class='op'>=</span> <span class='id identifier rubyid_change_time_zone'>change_time_zone</span> <span class='op'>&&</span> <span class='id identifier rubyid_respond_to?'>respond_to?</span><span class='lparen'>(</span><span class='symbol'>:in_time_zone</span><span class='rparen'>)</span> <span class='op'>?</span> <span class='id identifier rubyid_in_time_zone'>in_time_zone</span> <span class='op'>:</span> <span class='kw'>self</span>
<span class='id identifier rubyid_format'>format</span> <span class='op'>=</span> <span class='id identifier rubyid_custom'>custom</span> <span class='op'>?</span> <span class='op'>::</span><span class='const'>DateTime</span><span class='period'>.</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='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_gsub'>gsub</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>(?<!%)(%[ab])</span><span class='regexp_end'>/i</span></span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_mo'>mo</span><span class='op'>|</span> <span class='id identifier rubyid_localize_time_component'>localize_time_component</span><span class='lparen'>(</span><span class='id identifier rubyid_mo'>mo</span><span class='rparen'>)</span> <span class='rbrace'>}</span> <span class='op'>:</span> <span class='id identifier rubyid_format'>format</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span>
<span class='id identifier rubyid_target'>target</span><span class='period'>.</span><span class='id identifier rubyid_strftime'>strftime</span><span class='lparen'>(</span><span class='id identifier rubyid_format'>format</span><span class='rparen'>)</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="months_since_year-instance_method">
#<strong>months_since_year</strong>(base = nil) ⇒ <tt>Fixnum</tt>
</h3><div class="docstring">
<div class="discussion">
<p>Returns the number of months passed between the beginning of the base year and the current date.</p>
<p>Example:</p>
<pre class="code ruby"><code class="ruby"><span class='const'>DateTime</span><span class='period'>.</span><span class='id identifier rubyid_civil'>civil</span><span class='lparen'>(</span><span class='int'>2013</span><span class='comma'>,</span> <span class='int'>6</span><span class='comma'>,</span> <span class='int'>1</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_in_months'>in_months</span><span class='lparen'>(</span><span class='int'>2011</span><span class='rparen'>)</span>
<span class='comment'># => 18
</span></code></pre>
</div>
</div>
<div class="tags">
<p class="tag_title">Parameters:</p>
<ul class="param">
<li>
<span class='name'>base</span>
<span class='type'>(<tt><span class='object_link'><a href="" title="Lazier::DateTime (module)">DateTime</a></span>|NilClass</tt>)</span>
<em class="default">(defaults to: <tt>nil</tt>)</em>
—
<div class='inline'><p>The base year to start computation from. Default to current year.</p>
</div>
</li>
</ul>
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt>Fixnum</tt>)</span>
—
<div class='inline'><p>Returns the number of months passed between the beginning of the base year and the current date.</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
153
154
155</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/lazier/datetime.rb', line 153</span>
<span class='kw'>def</span> <span class='id identifier rubyid_months_since_year'>months_since_year</span><span class='lparen'>(</span><span class='id identifier rubyid_base'>base</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span>
<span class='lparen'>(</span><span class='id identifier rubyid_year'>year</span> <span class='op'>-</span> <span class='lparen'>(</span><span class='id identifier rubyid_base'>base</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='rparen'>)</span><span class='rparen'>)</span> <span class='op'>*</span> <span class='int'>12</span> <span class='op'>+</span> <span class='id identifier rubyid_month'>month</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="padded_month-instance_method">
#<strong>padded_month</strong> ⇒ <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>Returns the current month number with a leading zero if needed.</p>
</div>
</div>
<div class="tags">
<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 current month number with leading zero if needed.</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
160
161
162</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/lazier/datetime.rb', line 160</span>
<span class='kw'>def</span> <span class='id identifier rubyid_padded_month'>padded_month</span>
<span class='id identifier rubyid_month'>month</span><span class='period'>.</span><span class='id identifier rubyid_indexize'>indexize</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>