cowtech-extensions 2.7.1 → 2.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/.travis.yml +4 -2
- data/README.md +4 -1
- data/doc/Cowtech.html +2 -2
- data/doc/Cowtech/Extensions.html +96 -93
- data/doc/Cowtech/Extensions/Boolean.html +10 -8
- data/doc/Cowtech/Extensions/DateTime.html +58 -52
- data/doc/Cowtech/Extensions/DateTime/ClassMethods.html +91 -79
- data/doc/Cowtech/Extensions/Exceptions.html +2 -2
- data/doc/Cowtech/Extensions/Exceptions/Dump.html +2 -2
- data/doc/Cowtech/Extensions/Hash.html +20 -18
- data/doc/Cowtech/Extensions/Math.html +2 -2
- data/doc/Cowtech/Extensions/Math/ClassMethods.html +24 -22
- data/doc/Cowtech/Extensions/Object.html +95 -81
- data/doc/Cowtech/Extensions/Pathname.html +11 -10
- data/doc/Cowtech/Extensions/Settings.html +80 -70
- data/doc/Cowtech/Extensions/String.html +26 -22
- data/doc/Cowtech/Extensions/TimeZone.html +98 -86
- data/doc/Cowtech/Extensions/TimeZone/ClassMethods.html +79 -72
- data/doc/Cowtech/Extensions/Version.html +11 -7
- data/doc/_index.html +2 -2
- data/doc/file.README.html +9 -6
- data/doc/index.html +9 -6
- data/doc/top-level-namespace.html +2 -2
- data/lib/cowtech-extensions.rb +2 -1
- data/lib/cowtech-extensions/version.rb +2 -2
- data/spec/cowtech-extensions/boolean_spec.rb +9 -4
- data/spec/cowtech-extensions/datetime_spec.rb +106 -100
- data/spec/cowtech-extensions/hash_spec.rb +4 -4
- data/spec/cowtech-extensions/math_spec.rb +8 -8
- data/spec/cowtech-extensions/object_spec.rb +115 -103
- data/spec/cowtech-extensions/pathname_spec.rb +3 -1
- data/spec/cowtech-extensions/settings_spec.rb +30 -30
- data/spec/cowtech-extensions/string_spec.rb +13 -7
- data/spec/cowtech-extensions_spec.rb +21 -11
- data/spec/spec_helper.rb +7 -1
- metadata +4 -4
@@ -364,11 +364,12 @@
|
|
364
364
|
<td>
|
365
365
|
<pre class="code"><span class="info file"># File 'lib/cowtech-extensions/datetime.rb', line 378</span>
|
366
366
|
|
367
|
-
<span class='kw'>def</span> <span class='
|
368
|
-
<span class='
|
369
|
-
<span class='
|
370
|
-
<span class='
|
371
|
-
<span class='kw'>end</span
|
367
|
+
<span class='rubyid_def def kw'>def</span> <span class='rubyid_compare identifier id'>compare</span><span class='lparen token'>(</span><span class='rubyid_left identifier id'>left</span><span class='comma token'>,</span> <span class='rubyid_right identifier id'>right</span><span class='rparen token'>)</span>
|
368
|
+
<span class='rubyid_left identifier id'>left</span> <span class='assign token'>=</span> <span class='rubyid_left identifier id'>left</span><span class='dot token'>.</span><span class='rubyid_to_str identifier id'>to_str</span> <span class='rubyid_if if_mod kw'>if</span> <span class='rubyid_left identifier id'>left</span><span class='dot token'>.</span><span class='rubyid_is_a? fid id'>is_a?</span><span class='lparen token'>(</span><span class='colon3 op'>::</span><span class='rubyid_ActiveSupport constant id'>ActiveSupport</span><span class='colon2 op'>::</span><span class='rubyid_TimeZone constant id'>TimeZone</span><span class='rparen token'>)</span>
|
369
|
+
<span class='rubyid_right identifier id'>right</span> <span class='assign token'>=</span> <span class='rubyid_right identifier id'>right</span><span class='dot token'>.</span><span class='rubyid_to_str identifier id'>to_str</span> <span class='rubyid_if if_mod kw'>if</span> <span class='rubyid_right identifier id'>right</span><span class='dot token'>.</span><span class='rubyid_is_a? fid id'>is_a?</span><span class='lparen token'>(</span><span class='colon3 op'>::</span><span class='rubyid_ActiveSupport constant id'>ActiveSupport</span><span class='colon2 op'>::</span><span class='rubyid_TimeZone constant id'>TimeZone</span><span class='rparen token'>)</span>
|
370
|
+
<span class='rubyid_left identifier id'>left</span><span class='dot token'>.</span><span class='rubyid_ensure_string identifier id'>ensure_string</span><span class='dot token'>.</span><span class='rubyid_split identifier id'>split</span><span class='lparen token'>(</span><span class='string val'>" "</span><span class='comma token'>,</span> <span class='integer val'>2</span><span class='rparen token'>)</span><span class='lbrack token'>[</span><span class='integer val'>1</span><span class='rbrack token'>]</span> <span class='cmp op'><=></span> <span class='rubyid_right identifier id'>right</span><span class='dot token'>.</span><span class='rubyid_ensure_string identifier id'>ensure_string</span><span class='dot token'>.</span><span class='rubyid_split identifier id'>split</span><span class='lparen token'>(</span><span class='string val'>" "</span><span class='comma token'>,</span> <span class='integer val'>2</span><span class='rparen token'>)</span><span class='lbrack token'>[</span><span class='integer val'>1</span><span class='rbrack token'>]</span>
|
371
|
+
<span class='rubyid_end end kw'>end</span>
|
372
|
+
</pre>
|
372
373
|
</td>
|
373
374
|
</tr>
|
374
375
|
</table>
|
@@ -467,17 +468,18 @@
|
|
467
468
|
<td>
|
468
469
|
<pre class="code"><span class="info file"># File 'lib/cowtech-extensions/datetime.rb', line 290</span>
|
469
470
|
|
470
|
-
<span class='kw'>def</span> <span class='
|
471
|
-
<span class='
|
472
|
-
<span class='op'>::</span><span class='
|
473
|
-
<span class='
|
474
|
-
<span class='
|
475
|
-
<span class='kw'>end</span>
|
476
|
-
<span class='kw'>end</span>
|
477
|
-
|
478
|
-
<span class='kw'>nil</span>
|
479
|
-
<span class='kw'>end</span>
|
480
|
-
<span class='kw'>end</span
|
471
|
+
<span class='rubyid_def def kw'>def</span> <span class='rubyid_find identifier id'>find</span><span class='lparen token'>(</span><span class='rubyid_name identifier id'>name</span><span class='comma token'>,</span> <span class='rubyid_dst_label identifier id'>dst_label</span> <span class='assign token'>=</span> <span class='rubyid_nil nil kw'>nil</span><span class='rparen token'>)</span>
|
472
|
+
<span class='rubyid_catch identifier id'>catch</span><span class='lparen token'>(</span><span class='symbol val'>:zone</span><span class='rparen token'>)</span> <span class='rubyid_do do kw'>do</span>
|
473
|
+
<span class='colon3 op'>::</span><span class='rubyid_ActiveSupport constant id'>ActiveSupport</span><span class='colon2 op'>::</span><span class='rubyid_TimeZone constant id'>TimeZone</span><span class='dot token'>.</span><span class='rubyid_all identifier id'>all</span><span class='dot token'>.</span><span class='rubyid_each identifier id'>each</span> <span class='rubyid_do do kw'>do</span> <span class='bitor op'>|</span><span class='rubyid_zone identifier id'>zone</span><span class='bitor op'>|</span>
|
474
|
+
<span class='rubyid_zone identifier id'>zone</span><span class='dot token'>.</span><span class='rubyid_aliases identifier id'>aliases</span><span class='dot token'>.</span><span class='rubyid_each identifier id'>each</span> <span class='rubyid_do do kw'>do</span> <span class='bitor op'>|</span><span class='rubyid_zone_alias identifier id'>zone_alias</span><span class='bitor op'>|</span>
|
475
|
+
<span class='rubyid_throw identifier id'>throw</span><span class='lparen token'>(</span><span class='symbol val'>:zone</span><span class='comma token'>,</span> <span class='rubyid_zone identifier id'>zone</span><span class='rparen token'>)</span> <span class='rubyid_if if_mod kw'>if</span> <span class='lbrack token'>[</span><span class='rubyid_zone identifier id'>zone</span><span class='dot token'>.</span><span class='rubyid_to_str identifier id'>to_str</span><span class='lparen token'>(</span><span class='rubyid_zone_alias identifier id'>zone_alias</span><span class='rparen token'>)</span><span class='comma token'>,</span> <span class='rubyid_zone identifier id'>zone</span><span class='dot token'>.</span><span class='rubyid_to_str_with_dst identifier id'>to_str_with_dst</span><span class='lparen token'>(</span><span class='rubyid_dst_label identifier id'>dst_label</span><span class='comma token'>,</span> <span class='rubyid_nil nil kw'>nil</span><span class='comma token'>,</span> <span class='rubyid_zone_alias identifier id'>zone_alias</span><span class='rparen token'>)</span><span class='rbrack token'>]</span><span class='dot token'>.</span><span class='rubyid_include? fid id'>include?</span><span class='lparen token'>(</span><span class='rubyid_name identifier id'>name</span><span class='rparen token'>)</span>
|
476
|
+
<span class='rubyid_end end kw'>end</span>
|
477
|
+
<span class='rubyid_end end kw'>end</span>
|
478
|
+
|
479
|
+
<span class='rubyid_nil nil kw'>nil</span>
|
480
|
+
<span class='rubyid_end end kw'>end</span>
|
481
|
+
<span class='rubyid_end end kw'>end</span>
|
482
|
+
</pre>
|
481
483
|
</td>
|
482
484
|
</tr>
|
483
485
|
</table>
|
@@ -569,10 +571,11 @@
|
|
569
571
|
<td>
|
570
572
|
<pre class="code"><span class="info file"># File 'lib/cowtech-extensions/datetime.rb', line 280</span>
|
571
573
|
|
572
|
-
<span class='kw'>def</span> <span class='
|
573
|
-
<span class='
|
574
|
-
<span class='
|
575
|
-
<span class='kw'>end</span
|
574
|
+
<span class='rubyid_def def kw'>def</span> <span class='rubyid_format_offset identifier id'>format_offset</span><span class='lparen token'>(</span><span class='rubyid_offset identifier id'>offset</span><span class='comma token'>,</span> <span class='rubyid_colon identifier id'>colon</span> <span class='assign token'>=</span> <span class='rubyid_true true kw'>true</span><span class='rparen token'>)</span>
|
575
|
+
<span class='rubyid_offset identifier id'>offset</span> <span class='assign token'>=</span> <span class='lparen token'>(</span><span class='rubyid_offset identifier id'>offset</span> <span class='mult op'>*</span> <span class='integer val'>86400</span><span class='rparen token'>)</span><span class='dot token'>.</span><span class='rubyid_to_i identifier id'>to_i</span> <span class='rubyid_if if_mod kw'>if</span> <span class='rubyid_offset identifier id'>offset</span><span class='dot token'>.</span><span class='rubyid_is_a? fid id'>is_a?</span><span class='lparen token'>(</span><span class='colon3 op'>::</span><span class='rubyid_Rational constant id'>Rational</span><span class='rparen token'>)</span>
|
576
|
+
<span class='rubyid_offset identifier id'>offset</span><span class='dot token'>.</span><span class='rubyid_is_a? fid id'>is_a?</span><span class='lparen token'>(</span><span class='colon3 op'>::</span><span class='rubyid_Fixnum constant id'>Fixnum</span><span class='rparen token'>)</span> <span class='question op'>?</span> <span class='rubyid_self self kw'>self</span><span class='dot token'>.</span><span class='rubyid_seconds_to_utc_offset identifier id'>seconds_to_utc_offset</span><span class='lparen token'>(</span><span class='rubyid_offset identifier id'>offset</span><span class='comma token'>,</span> <span class='rubyid_colon identifier id'>colon</span><span class='rparen token'>)</span> <span class='colon op'>:</span> <span class='rubyid_nil nil kw'>nil</span>
|
577
|
+
<span class='rubyid_end end kw'>end</span>
|
578
|
+
</pre>
|
576
579
|
</td>
|
577
580
|
</tr>
|
578
581
|
</table>
|
@@ -682,26 +685,27 @@
|
|
682
685
|
<td>
|
683
686
|
<pre class="code"><span class="info file"># File 'lib/cowtech-extensions/datetime.rb', line 307</span>
|
684
687
|
|
685
|
-
<span class='kw'>def</span> <span class='
|
686
|
-
<span class='
|
687
|
-
<span class='
|
688
|
-
<span class='ivar'>@zones_names</span> <span class='op'>||=</span> <span class='lbrace'>{</span> <span class='
|
688
|
+
<span class='rubyid_def def kw'>def</span> <span class='rubyid_list_all identifier id'>list_all</span><span class='lparen token'>(</span><span class='rubyid_with_dst identifier id'>with_dst</span> <span class='assign token'>=</span> <span class='rubyid_true true kw'>true</span><span class='comma token'>,</span> <span class='rubyid_dst_label identifier id'>dst_label</span> <span class='assign token'>=</span> <span class='rubyid_nil nil kw'>nil</span><span class='rparen token'>)</span>
|
689
|
+
<span class='rubyid_dst_label identifier id'>dst_label</span> <span class='opasgn op'>||=</span> <span class='string val'>"(DST)"</span>
|
690
|
+
<span class='rubyid_dst_key identifier id'>dst_key</span> <span class='assign token'>=</span> <span class='dstring node'>"DST-#{dst_label}"</span>
|
691
|
+
<span class='rubyid_@zones_names ivar id'>@zones_names</span> <span class='opasgn op'>||=</span> <span class='lbrace token'>{</span> <span class='string val'>"STANDARD"</span> <span class='assign token'>=</span><span class='gt op'>></span> <span class='colon3 op'>::</span><span class='rubyid_ActiveSupport constant id'>ActiveSupport</span><span class='colon2 op'>::</span><span class='rubyid_TimeZone constant id'>TimeZone</span><span class='dot token'>.</span><span class='rubyid_all identifier id'>all</span><span class='dot token'>.</span><span class='rubyid_collect identifier id'>collect</span><span class='lparen token'>(</span><span class='bitand op'>&</span><span class='symbol val'>:to_s</span><span class='rparen token'>)</span> <span class='rbrace token'>}</span>
|
689
692
|
|
690
|
-
<span class='kw'>if</span> <span class='
|
691
|
-
<span class='ivar'>@zones_names</span><span class='
|
693
|
+
<span class='rubyid_if if kw'>if</span> <span class='rubyid_with_dst identifier id'>with_dst</span> <span class='andop op'>&&</span> <span class='rubyid_@zones_names ivar id'>@zones_names</span><span class='lbrack token'>[</span><span class='rubyid_dst_key identifier id'>dst_key</span><span class='rbrack token'>]</span><span class='dot token'>.</span><span class='rubyid_blank? fid id'>blank?</span> <span class='rubyid_then then kw'>then</span>
|
694
|
+
<span class='rubyid_@zones_names ivar id'>@zones_names</span><span class='lbrack token'>[</span><span class='rubyid_dst_key identifier id'>dst_key</span><span class='rbrack token'>]</span> <span class='assign token'>=</span> <span class='lbrack token'>[</span><span class='rbrack token'>]</span>
|
692
695
|
|
693
|
-
<span class='op'>::</span><span class='
|
694
|
-
<span class='
|
695
|
-
<span class='ivar'>@zones_names</span><span class='
|
696
|
-
<span class='ivar'>@zones_names</span><span class='
|
697
|
-
<span class='kw'>end</span>
|
698
|
-
<span class='kw'>end</span>
|
696
|
+
<span class='colon3 op'>::</span><span class='rubyid_ActiveSupport constant id'>ActiveSupport</span><span class='colon2 op'>::</span><span class='rubyid_TimeZone constant id'>TimeZone</span><span class='dot token'>.</span><span class='rubyid_all identifier id'>all</span><span class='dot token'>.</span><span class='rubyid_each identifier id'>each</span> <span class='rubyid_do do kw'>do</span> <span class='bitor op'>|</span><span class='rubyid_zone identifier id'>zone</span><span class='bitor op'>|</span>
|
697
|
+
<span class='rubyid_zone identifier id'>zone</span><span class='dot token'>.</span><span class='rubyid_aliases identifier id'>aliases</span><span class='dot token'>.</span><span class='rubyid_each identifier id'>each</span> <span class='rubyid_do do kw'>do</span> <span class='bitor op'>|</span><span class='rubyid_zone_alias identifier id'>zone_alias</span><span class='bitor op'>|</span>
|
698
|
+
<span class='rubyid_@zones_names ivar id'>@zones_names</span><span class='lbrack token'>[</span><span class='rubyid_dst_key identifier id'>dst_key</span><span class='rbrack token'>]</span> <span class='lshft op'><<</span> <span class='rubyid_zone identifier id'>zone</span><span class='dot token'>.</span><span class='rubyid_to_str identifier id'>to_str</span><span class='lparen token'>(</span><span class='rubyid_zone_alias identifier id'>zone_alias</span><span class='rparen token'>)</span>
|
699
|
+
<span class='rubyid_@zones_names ivar id'>@zones_names</span><span class='lbrack token'>[</span><span class='rubyid_dst_key identifier id'>dst_key</span><span class='rbrack token'>]</span> <span class='lshft op'><<</span> <span class='rubyid_zone identifier id'>zone</span><span class='dot token'>.</span><span class='rubyid_to_str_with_dst identifier id'>to_str_with_dst</span><span class='lparen token'>(</span><span class='rubyid_dst_label identifier id'>dst_label</span><span class='comma token'>,</span> <span class='rubyid_nil nil kw'>nil</span><span class='comma token'>,</span> <span class='rubyid_zone_alias identifier id'>zone_alias</span><span class='rparen token'>)</span> <span class='rubyid_if if_mod kw'>if</span> <span class='rubyid_zone identifier id'>zone</span><span class='dot token'>.</span><span class='rubyid_uses_dst? fid id'>uses_dst?</span> <span class='andop op'>&&</span> <span class='rubyid_zone_alias identifier id'>zone_alias</span> <span class='nmatch op'>!~</span> <span class='dregexp node'>/(#{Regexp.quote(dst_label)})$/</span>
|
700
|
+
<span class='rubyid_end end kw'>end</span>
|
701
|
+
<span class='rubyid_end end kw'>end</span>
|
699
702
|
|
700
|
-
<span class='ivar'>@zones_names</span><span class='
|
701
|
-
|
703
|
+
<span class='rubyid_@zones_names ivar id'>@zones_names</span><span class='lbrack token'>[</span><span class='rubyid_dst_key identifier id'>dst_key</span><span class='rbrack token'>]</span><span class='assign token'>=</span> <span class='rubyid_@zones_names ivar id'>@zones_names</span><span class='lbrack token'>[</span><span class='rubyid_dst_key identifier id'>dst_key</span><span class='rbrack token'>]</span><span class='dot token'>.</span><span class='rubyid_uniq identifier id'>uniq</span><span class='dot token'>.</span><span class='rubyid_compact identifier id'>compact</span><span class='dot token'>.</span><span class='rubyid_sort identifier id'>sort</span> <span class='lbrace token'>{</span> <span class='bitor op'>|</span><span class='rubyid_a identifier id'>a</span><span class='comma token'>,</span><span class='rubyid_b identifier id'>b</span><span class='bitor op'>|</span> <span class='colon3 op'>::</span><span class='rubyid_ActiveSupport constant id'>ActiveSupport</span><span class='colon2 op'>::</span><span class='rubyid_TimeZone constant id'>TimeZone</span><span class='dot token'>.</span><span class='rubyid_compare identifier id'>compare</span><span class='lparen token'>(</span><span class='rubyid_a identifier id'>a</span><span class='comma token'>,</span> <span class='rubyid_b identifier id'>b</span><span class='rparen token'>)</span> <span class='rbrace token'>}</span> <span class='comment val'># Sort by name</span>
|
704
|
+
<span class='rubyid_end end kw'>end</span>
|
702
705
|
|
703
|
-
<span class='ivar'>@zones_names</span><span class='
|
704
|
-
<span class='kw'>end</span
|
706
|
+
<span class='rubyid_@zones_names ivar id'>@zones_names</span><span class='lbrack token'>[</span><span class='rubyid_with_dst identifier id'>with_dst</span> <span class='integer val'>? </span><span class='rubyid_dst_key identifier id'>dst_key</span> <span class='colon op'>:</span> <span class='string val'>"STANDARD"</span><span class='rbrack token'>]</span>
|
707
|
+
<span class='rubyid_end end kw'>end</span>
|
708
|
+
</pre>
|
705
709
|
</td>
|
706
710
|
</tr>
|
707
711
|
</table>
|
@@ -720,9 +724,9 @@
|
|
720
724
|
<div class="discussion">
|
721
725
|
<p>Returns a string representation of a timezone.</p>
|
722
726
|
|
723
|
-
<pre class="code ruby"><code><span class='
|
724
|
-
<span class='comment'># => "-0800@pacific-time-us-canada"
|
725
|
-
</
|
727
|
+
<pre class="code ruby"><code><span class='rubyid_DateTime constant id'>DateTime</span><span class='dot token'>.</span><span class='rubyid_parameterize_zone identifier id'>parameterize_zone</span><span class='lparen token'>(</span><span class='rubyid_ActiveSupport constant id'>ActiveSupport</span><span class='colon2 op'>::</span><span class='rubyid_TimeZone constant id'>TimeZone</span><span class='lbrack token'>[</span><span class='string val'>"Pacific Time (US & Canada)"</span><span class='rbrack token'>]</span><span class='rparen token'>)</span>
|
728
|
+
<span class='comment val'># => "-0800@pacific-time-us-canada"</span>
|
729
|
+
</code></pre>
|
726
730
|
|
727
731
|
|
728
732
|
</div>
|
@@ -804,17 +808,18 @@
|
|
804
808
|
<td>
|
805
809
|
<pre class="code"><span class="info file"># File 'lib/cowtech-extensions/datetime.rb', line 337</span>
|
806
810
|
|
807
|
-
<span class='kw'>def</span> <span class='
|
808
|
-
<span class='
|
809
|
-
|
810
|
-
<span class='kw'>if</span> <span class='
|
811
|
-
<span class='
|
812
|
-
<span class='kw'>elsif</span> <span class='op'>!</span><span class='
|
813
|
-
<span class='
|
814
|
-
<span class='kw'>else</span>
|
815
|
-
<span class='
|
816
|
-
<span class='kw'>end</span>
|
817
|
-
<span class='kw'>end</span
|
811
|
+
<span class='rubyid_def def kw'>def</span> <span class='rubyid_parameterize_zone identifier id'>parameterize_zone</span><span class='lparen token'>(</span><span class='rubyid_tz identifier id'>tz</span><span class='comma token'>,</span> <span class='rubyid_with_offset identifier id'>with_offset</span> <span class='assign token'>=</span> <span class='rubyid_true true kw'>true</span><span class='rparen token'>)</span>
|
812
|
+
<span class='rubyid_tz identifier id'>tz</span> <span class='assign token'>=</span> <span class='rubyid_tz identifier id'>tz</span><span class='dot token'>.</span><span class='rubyid_to_s identifier id'>to_s</span> <span class='rubyid_if if_mod kw'>if</span> <span class='notop op'>!</span><span class='rubyid_tz identifier id'>tz</span><span class='dot token'>.</span><span class='rubyid_is_a? fid id'>is_a?</span><span class='lparen token'>(</span><span class='colon3 op'>::</span><span class='rubyid_String constant id'>String</span><span class='rparen token'>)</span>
|
813
|
+
|
814
|
+
<span class='rubyid_if if kw'>if</span> <span class='rubyid_tz identifier id'>tz</span> <span class='match op'>=~</span> <span class='regexp val'>/^(\([a-z]+([+-])(\d{2})(:?)(\d{2})\)\s(.+))$/i</span> <span class='rubyid_then then kw'>then</span>
|
815
|
+
<span class='rubyid_with_offset identifier id'>with_offset</span> <span class='integer val'>? </span><span class='dstring node'>"#{$2}#{$3}#{$5}@#{$6.parameterize}"</span> <span class='colon op'>:</span> <span class='rubyid_$6 nth_ref id'>$6</span><span class='dot token'>.</span><span class='rubyid_parameterize identifier id'>parameterize</span>
|
816
|
+
<span class='rubyid_elsif elsif kw'>elsif</span> <span class='notop op'>!</span><span class='rubyid_with_offset identifier id'>with_offset</span> <span class='rubyid_then then kw'>then</span>
|
817
|
+
<span class='rubyid_tz identifier id'>tz</span><span class='dot token'>.</span><span class='rubyid_gsub identifier id'>gsub</span><span class='lparen token'>(</span><span class='regexp val'>/^([+-]?(\d{2})(:?)(\d{2})@)/</span><span class='comma token'>,</span> <span class='string val'>""</span><span class='rparen token'>)</span>
|
818
|
+
<span class='rubyid_else else kw'>else</span>
|
819
|
+
<span class='rubyid_tz identifier id'>tz</span><span class='dot token'>.</span><span class='rubyid_parameterize identifier id'>parameterize</span>
|
820
|
+
<span class='rubyid_end end kw'>end</span>
|
821
|
+
<span class='rubyid_end end kw'>end</span>
|
822
|
+
</pre>
|
818
823
|
</td>
|
819
824
|
</tr>
|
820
825
|
</table>
|
@@ -889,10 +894,11 @@
|
|
889
894
|
<td>
|
890
895
|
<pre class="code"><span class="info file"># File 'lib/cowtech-extensions/datetime.rb', line 270</span>
|
891
896
|
|
892
|
-
<span class='kw'>def</span> <span class='
|
893
|
-
<span class='
|
894
|
-
<span class='op'>::</span><span class='
|
895
|
-
<span class='kw'>end</span
|
897
|
+
<span class='rubyid_def def kw'>def</span> <span class='rubyid_rationalize_offset identifier id'>rationalize_offset</span><span class='lparen token'>(</span><span class='rubyid_offset identifier id'>offset</span><span class='rparen token'>)</span>
|
898
|
+
<span class='rubyid_offset identifier id'>offset</span> <span class='assign token'>=</span> <span class='rubyid_offset identifier id'>offset</span><span class='dot token'>.</span><span class='rubyid_try identifier id'>try</span><span class='lparen token'>(</span><span class='symbol val'>:offset</span><span class='rparen token'>)</span> <span class='rubyid_if if_mod kw'>if</span> <span class='notop op'>!</span><span class='rubyid_offset identifier id'>offset</span><span class='dot token'>.</span><span class='rubyid_is_a? fid id'>is_a?</span><span class='lparen token'>(</span><span class='colon3 op'>::</span><span class='rubyid_Fixnum constant id'>Fixnum</span><span class='rparen token'>)</span>
|
899
|
+
<span class='colon3 op'>::</span><span class='rubyid_TZInfo constant id'>TZInfo</span><span class='colon2 op'>::</span><span class='rubyid_OffsetRationals constant id'>OffsetRationals</span><span class='dot token'>.</span><span class='rubyid_rational_for_offset identifier id'>rational_for_offset</span><span class='lparen token'>(</span><span class='rubyid_offset identifier id'>offset</span><span class='dot token'>.</span><span class='rubyid_to_integer identifier id'>to_integer</span><span class='rparen token'>)</span>
|
900
|
+
<span class='rubyid_end end kw'>end</span>
|
901
|
+
</pre>
|
896
902
|
</td>
|
897
903
|
</tr>
|
898
904
|
</table>
|
@@ -1020,22 +1026,23 @@
|
|
1020
1026
|
<td>
|
1021
1027
|
<pre class="code"><span class="info file"># File 'lib/cowtech-extensions/datetime.rb', line 356</span>
|
1022
1028
|
|
1023
|
-
<span class='kw'>def</span> <span class='
|
1024
|
-
<span class='
|
1025
|
-
<span class='
|
1026
|
-
<span class='kw'>self</span><span class='
|
1027
|
-
<span class='
|
1028
|
-
<span class='kw'>end</span>
|
1029
|
-
|
1030
|
-
<span class='kw'>nil</span>
|
1031
|
-
<span class='kw'>end</span>
|
1032
|
-
|
1033
|
-
<span class='kw'>if</span> <span class='
|
1034
|
-
<span class='lparen'>(</span><span class='
|
1035
|
-
<span class='kw'>else</span>
|
1036
|
-
<span class='kw'>nil</span>
|
1037
|
-
<span class='kw'>end</span>
|
1038
|
-
<span class='kw'>end</span
|
1029
|
+
<span class='rubyid_def def kw'>def</span> <span class='rubyid_unparameterize_zone identifier id'>unparameterize_zone</span><span class='lparen token'>(</span><span class='rubyid_tz identifier id'>tz</span><span class='comma token'>,</span> <span class='rubyid_as_string identifier id'>as_string</span> <span class='assign token'>=</span> <span class='rubyid_false false kw'>false</span><span class='comma token'>,</span> <span class='rubyid_dst_label identifier id'>dst_label</span> <span class='assign token'>=</span> <span class='rubyid_nil nil kw'>nil</span><span class='rparen token'>)</span>
|
1030
|
+
<span class='rubyid_tz identifier id'>tz</span> <span class='assign token'>=</span> <span class='rubyid_self self kw'>self</span><span class='dot token'>.</span><span class='rubyid_parameterize_zone identifier id'>parameterize_zone</span><span class='lparen token'>(</span><span class='rubyid_tz identifier id'>tz</span><span class='comma token'>,</span> <span class='rubyid_false false kw'>false</span><span class='rparen token'>)</span>
|
1031
|
+
<span class='rubyid_rv identifier id'>rv</span> <span class='assign token'>=</span> <span class='rubyid_catch identifier id'>catch</span><span class='lparen token'>(</span><span class='symbol val'>:zone</span><span class='rparen token'>)</span> <span class='rubyid_do do kw'>do</span>
|
1032
|
+
<span class='rubyid_self self kw'>self</span><span class='dot token'>.</span><span class='rubyid_list_all identifier id'>list_all</span><span class='lparen token'>(</span><span class='rubyid_true true kw'>true</span><span class='comma token'>,</span> <span class='rubyid_dst_label identifier id'>dst_label</span><span class='rparen token'>)</span><span class='dot token'>.</span><span class='rubyid_each identifier id'>each</span> <span class='rubyid_do do kw'>do</span> <span class='bitor op'>|</span><span class='rubyid_zone identifier id'>zone</span><span class='bitor op'>|</span>
|
1033
|
+
<span class='rubyid_throw identifier id'>throw</span><span class='lparen token'>(</span><span class='symbol val'>:zone</span><span class='comma token'>,</span> <span class='rubyid_zone identifier id'>zone</span><span class='rparen token'>)</span> <span class='rubyid_if if_mod kw'>if</span> <span class='rubyid_self self kw'>self</span><span class='dot token'>.</span><span class='rubyid_parameterize_zone identifier id'>parameterize_zone</span><span class='lparen token'>(</span><span class='rubyid_zone identifier id'>zone</span><span class='comma token'>,</span> <span class='rubyid_false false kw'>false</span><span class='rparen token'>)</span> <span class='match op'>=~</span> <span class='dregexp node'>/(#{Regexp.quote(tz)})$/</span>
|
1034
|
+
<span class='rubyid_end end kw'>end</span>
|
1035
|
+
|
1036
|
+
<span class='rubyid_nil nil kw'>nil</span>
|
1037
|
+
<span class='rubyid_end end kw'>end</span>
|
1038
|
+
|
1039
|
+
<span class='rubyid_if if kw'>if</span> <span class='rubyid_rv identifier id'>rv</span> <span class='rubyid_then then kw'>then</span>
|
1040
|
+
<span class='lparen token'>(</span><span class='rubyid_as_string identifier id'>as_string</span> <span class='integer val'>? </span><span class='rubyid_rv identifier id'>rv</span> <span class='colon op'>:</span> <span class='rubyid_self self kw'>self</span><span class='dot token'>.</span><span class='rubyid_find identifier id'>find</span><span class='lparen token'>(</span><span class='rubyid_rv identifier id'>rv</span><span class='comma token'>,</span> <span class='rubyid_dst_label identifier id'>dst_label</span><span class='rparen token'>)</span><span class='rparen token'>)</span>
|
1041
|
+
<span class='rubyid_else else kw'>else</span>
|
1042
|
+
<span class='rubyid_nil nil kw'>nil</span>
|
1043
|
+
<span class='rubyid_end end kw'>end</span>
|
1044
|
+
<span class='rubyid_end end kw'>end</span>
|
1045
|
+
</pre>
|
1039
1046
|
</td>
|
1040
1047
|
</tr>
|
1041
1048
|
</table>
|
@@ -1046,9 +1053,9 @@
|
|
1046
1053
|
</div>
|
1047
1054
|
|
1048
1055
|
<div id="footer">
|
1049
|
-
Generated on
|
1056
|
+
Generated on Sat Jul 28 11:24:55 2012 by
|
1050
1057
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
1051
|
-
0.8.2.1 (ruby-1.
|
1058
|
+
0.8.2.1 (ruby-1.8.7).
|
1052
1059
|
</div>
|
1053
1060
|
|
1054
1061
|
</body>
|
@@ -86,7 +86,7 @@
|
|
86
86
|
|
87
87
|
<h2>Overview</h2><div class="docstring">
|
88
88
|
<div class="discussion">
|
89
|
-
<p>The current version of cowtech-extensions, according semantic versioning.</p>
|
89
|
+
<p>The current version of cowtech-extensions, according to semantic versioning.</p>
|
90
90
|
|
91
91
|
|
92
92
|
</div>
|
@@ -119,7 +119,8 @@
|
|
119
119
|
|
120
120
|
</div>
|
121
121
|
</dt>
|
122
|
-
<dd><pre class="code"><span class='
|
122
|
+
<dd><pre class="code"><span class='integer val'>2</span>
|
123
|
+
</pre></dd>
|
123
124
|
|
124
125
|
<dt id="MINOR-constant" class="">MINOR =
|
125
126
|
<div class="docstring">
|
@@ -134,7 +135,8 @@
|
|
134
135
|
|
135
136
|
</div>
|
136
137
|
</dt>
|
137
|
-
<dd><pre class="code"><span class='
|
138
|
+
<dd><pre class="code"><span class='integer val'>7</span>
|
139
|
+
</pre></dd>
|
138
140
|
|
139
141
|
<dt id="PATCH-constant" class="">PATCH =
|
140
142
|
<div class="docstring">
|
@@ -149,7 +151,8 @@
|
|
149
151
|
|
150
152
|
</div>
|
151
153
|
</dt>
|
152
|
-
<dd><pre class="code"><span class='
|
154
|
+
<dd><pre class="code"><span class='integer val'>2</span>
|
155
|
+
</pre></dd>
|
153
156
|
|
154
157
|
<dt id="STRING-constant" class="">STRING =
|
155
158
|
<div class="docstring">
|
@@ -164,7 +167,8 @@
|
|
164
167
|
|
165
168
|
</div>
|
166
169
|
</dt>
|
167
|
-
<dd><pre class="code"><span class='
|
170
|
+
<dd><pre class="code"><span class='lbrack token'>[</span><span class='rubyid_MAJOR constant id'>MAJOR</span><span class='comma token'>,</span> <span class='rubyid_MINOR constant id'>MINOR</span><span class='comma token'>,</span> <span class='rubyid_PATCH constant id'>PATCH</span><span class='rbrack token'>]</span><span class='dot token'>.</span><span class='rubyid_compact identifier id'>compact</span><span class='dot token'>.</span><span class='rubyid_join identifier id'>join</span><span class='lparen token'>(</span><span class='string val'>"."</span><span class='rparen token'>)</span>
|
171
|
+
</pre></dd>
|
168
172
|
|
169
173
|
</dl>
|
170
174
|
|
@@ -180,9 +184,9 @@
|
|
180
184
|
</div>
|
181
185
|
|
182
186
|
<div id="footer">
|
183
|
-
Generated on
|
187
|
+
Generated on Sat Jul 28 11:24:54 2012 by
|
184
188
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
185
|
-
0.8.2.1 (ruby-1.
|
189
|
+
0.8.2.1 (ruby-1.8.7).
|
186
190
|
</div>
|
187
191
|
|
188
192
|
</body>
|
data/doc/_index.html
CHANGED
@@ -296,9 +296,9 @@
|
|
296
296
|
</div>
|
297
297
|
|
298
298
|
<div id="footer">
|
299
|
-
Generated on
|
299
|
+
Generated on Sat Jul 28 11:24:53 2012 by
|
300
300
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
301
|
-
0.8.2.1 (ruby-1.
|
301
|
+
0.8.2.1 (ruby-1.8.7).
|
302
302
|
</div>
|
303
303
|
|
304
304
|
</body>
|
data/doc/file.README.html
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
3
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
4
|
<head>
|
5
|
-
<meta http-equiv="Content-Type" content="text/html; charset=
|
5
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
6
6
|
<title>
|
7
7
|
File: README
|
8
8
|
|
@@ -61,15 +61,18 @@
|
|
61
61
|
|
62
62
|
<iframe id="search_frame"></iframe>
|
63
63
|
|
64
|
-
<div id="content"><div id='filecontents'><h1>cowtech-
|
64
|
+
<div id="content"><div id='filecontents'><h1>cowtech-extensions</h1>
|
65
|
+
|
66
|
+
<p><a href="http://travis-ci.org/ShogunPanda/cowtech-extensions"><img src="https://secure.travis-ci.org/ShogunPanda/cowtech-extensions.png?branch=master" alt="Build Status"></a>
|
67
|
+
<a href="https://gemnasium.com/ShogunPanda/cowtech-extensions"><img src="https://gemnasium.com/ShogunPanda/cowtech-extensions.png?travis" alt="Dependency Status"></a></p>
|
65
68
|
|
66
69
|
<p>Several Ruby object enhancements
|
67
70
|
<a href="http://github.com/ShogunPanda/cowtech-extensions">http://github.com/ShogunPanda/cowtech-extensions</a></p>
|
68
71
|
|
69
72
|
<h2>Usage</h2>
|
70
73
|
|
71
|
-
<pre class="code ruby"><code><span class='
|
72
|
-
<span class='
|
74
|
+
<pre class="code ruby"><code><span class='rubyid_require identifier id'>require</span> <span class='string val'>"cowtech-extensions"</span>
|
75
|
+
<span class='rubyid_Cowtech constant id'>Cowtech</span><span class='colon2 op'>::</span><span class='rubyid_Extensions constant id'>Extensions</span><span class='dot token'>.</span><span class='rubyid_load! fid id'>load!</span>
|
73
76
|
</code></pre>
|
74
77
|
|
75
78
|
<p>That's all!
|
@@ -94,9 +97,9 @@ Licensed under the MIT license, which can be found at <a href="http://www.openso
|
|
94
97
|
</div></div>
|
95
98
|
|
96
99
|
<div id="footer">
|
97
|
-
Generated on
|
100
|
+
Generated on Sat Jul 28 11:24:53 2012 by
|
98
101
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
99
|
-
0.8.2.1 (ruby-1.
|
102
|
+
0.8.2.1 (ruby-1.8.7).
|
100
103
|
</div>
|
101
104
|
|
102
105
|
</body>
|
data/doc/index.html
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
3
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
4
|
<head>
|
5
|
-
<meta http-equiv="Content-Type" content="text/html; charset=
|
5
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
6
6
|
<title>
|
7
7
|
File: README
|
8
8
|
|
@@ -61,15 +61,18 @@
|
|
61
61
|
|
62
62
|
<iframe id="search_frame"></iframe>
|
63
63
|
|
64
|
-
<div id="content"><div id='filecontents'><h1>cowtech-
|
64
|
+
<div id="content"><div id='filecontents'><h1>cowtech-extensions</h1>
|
65
|
+
|
66
|
+
<p><a href="http://travis-ci.org/ShogunPanda/cowtech-extensions"><img src="https://secure.travis-ci.org/ShogunPanda/cowtech-extensions.png?branch=master" alt="Build Status"></a>
|
67
|
+
<a href="https://gemnasium.com/ShogunPanda/cowtech-extensions"><img src="https://gemnasium.com/ShogunPanda/cowtech-extensions.png?travis" alt="Dependency Status"></a></p>
|
65
68
|
|
66
69
|
<p>Several Ruby object enhancements
|
67
70
|
<a href="http://github.com/ShogunPanda/cowtech-extensions">http://github.com/ShogunPanda/cowtech-extensions</a></p>
|
68
71
|
|
69
72
|
<h2>Usage</h2>
|
70
73
|
|
71
|
-
<pre class="code ruby"><code><span class='
|
72
|
-
<span class='
|
74
|
+
<pre class="code ruby"><code><span class='rubyid_require identifier id'>require</span> <span class='string val'>"cowtech-extensions"</span>
|
75
|
+
<span class='rubyid_Cowtech constant id'>Cowtech</span><span class='colon2 op'>::</span><span class='rubyid_Extensions constant id'>Extensions</span><span class='dot token'>.</span><span class='rubyid_load! fid id'>load!</span>
|
73
76
|
</code></pre>
|
74
77
|
|
75
78
|
<p>That's all!
|
@@ -94,9 +97,9 @@ Licensed under the MIT license, which can be found at <a href="http://www.openso
|
|
94
97
|
</div></div>
|
95
98
|
|
96
99
|
<div id="footer">
|
97
|
-
Generated on
|
100
|
+
Generated on Sat Jul 28 11:24:53 2012 by
|
98
101
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
99
|
-
0.8.2.1 (ruby-1.
|
102
|
+
0.8.2.1 (ruby-1.8.7).
|
100
103
|
</div>
|
101
104
|
|
102
105
|
</body>
|
@@ -103,9 +103,9 @@
|
|
103
103
|
</div>
|
104
104
|
|
105
105
|
<div id="footer">
|
106
|
-
Generated on
|
106
|
+
Generated on Sat Jul 28 11:24:53 2012 by
|
107
107
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
108
|
-
0.8.2.1 (ruby-1.
|
108
|
+
0.8.2.1 (ruby-1.8.7).
|
109
109
|
</div>
|
110
110
|
|
111
111
|
</body>
|
data/lib/cowtech-extensions.rb
CHANGED
@@ -11,6 +11,7 @@ require "tzinfo"
|
|
11
11
|
require "active_support/all"
|
12
12
|
require "action_view"
|
13
13
|
|
14
|
+
require "cowtech-extensions/version" if !defined?(Cowtech::Extensions::Version)
|
14
15
|
require "cowtech-extensions/exceptions"
|
15
16
|
require "cowtech-extensions/settings"
|
16
17
|
require "cowtech-extensions/object"
|
@@ -126,4 +127,4 @@ module Cowtech
|
|
126
127
|
::Cowtech::Extensions::Settings.instance
|
127
128
|
end
|
128
129
|
end
|
129
|
-
end
|
130
|
+
end
|
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
module Cowtech
|
8
8
|
module Extensions
|
9
|
-
# The current version of cowtech-extensions, according semantic versioning.
|
9
|
+
# The current version of cowtech-extensions, according to semantic versioning.
|
10
10
|
#
|
11
11
|
# @see http://semver.org
|
12
12
|
module Version
|
@@ -17,7 +17,7 @@ module Cowtech
|
|
17
17
|
MINOR = 7
|
18
18
|
|
19
19
|
# The patch version.
|
20
|
-
PATCH =
|
20
|
+
PATCH = 2
|
21
21
|
|
22
22
|
# The current version of cowtech-extensions.
|
23
23
|
STRING = [MAJOR, MINOR, PATCH].compact.join(".")
|
@@ -12,14 +12,19 @@ describe Cowtech::Extensions::Boolean do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
describe "#to_i" do
|
15
|
-
it "should return 1 for true" do
|
16
|
-
|
15
|
+
it "should return 1 for true" do
|
16
|
+
expect(true.to_i).to eq(1)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should return 0 for false" do
|
20
|
+
expect(false.to_i).to eq(0)
|
21
|
+
end
|
17
22
|
end
|
18
23
|
|
19
24
|
describe "#value" do
|
20
25
|
it "should return self" do
|
21
|
-
true.value.
|
22
|
-
false.value.
|
26
|
+
expect(true.value).to be_true
|
27
|
+
expect(false.value).to be_false
|
23
28
|
end
|
24
29
|
end
|
25
30
|
end
|
@@ -18,47 +18,49 @@ describe Cowtech::Extensions::DateTime do
|
|
18
18
|
|
19
19
|
describe ".days" do
|
20
20
|
it "should return the list of the days of the week" do
|
21
|
-
::DateTime.days.
|
22
|
-
::DateTime.days[3].
|
23
|
-
::DateTime.days(false).
|
24
|
-
::DateTime.days(false)[3].
|
21
|
+
expect(::DateTime.days).to be_kind_of(::Array)
|
22
|
+
expect(::DateTime.days[3]).to eq({:value => "4", :label => "Wed"})
|
23
|
+
expect(::DateTime.days(false)).to be_kind_of(::Array)
|
24
|
+
expect(::DateTime.days(false)[3]).to eq({:value => "4", :label => "Wednesday"})
|
25
25
|
|
26
26
|
::Cowtech::Extensions.settings.setup_date_names(nil, nil, 7.times.collect {|i| (i + 1).to_s * 2}, 7.times.collect {|i| (i + 1).to_s})
|
27
|
-
::DateTime.days.
|
28
|
-
::DateTime.days[3].
|
29
|
-
::DateTime.days(false).
|
30
|
-
::DateTime.days(false)[3].
|
27
|
+
expect(::DateTime.days).to be_kind_of(::Array)
|
28
|
+
expect(::DateTime.days[3]).to eq({:value => "4", :label => "4"})
|
29
|
+
expect(::DateTime.days(false)).to be_kind_of(::Array)
|
30
|
+
expect(::DateTime.days(false)[3]).to eq({:value => "4", :label => "44"})
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
34
|
describe ".months" do
|
35
35
|
it "should return the list of the months of the year" do
|
36
|
-
::DateTime.months.
|
37
|
-
::DateTime.months[6].
|
38
|
-
::DateTime.months(false).
|
39
|
-
::DateTime.months(false)[6].
|
36
|
+
expect(::DateTime.months).to be_kind_of(::Array)
|
37
|
+
expect(::DateTime.months[6]).to eq({:value => "07", :label => "Jul"})
|
38
|
+
expect(::DateTime.months(false)).to be_kind_of(::Array)
|
39
|
+
expect(::DateTime.months(false)[6]).to eq({:value => "07", :label => "July"})
|
40
40
|
|
41
41
|
::Cowtech::Extensions.settings.setup_date_names(12.times.collect {|i| (i + 1).to_s * 2}, 12.times.collect {|i| (i + 1).to_s}, nil, nil)
|
42
|
-
::DateTime.months.
|
43
|
-
::DateTime.months[6].
|
44
|
-
::DateTime.months(false).
|
45
|
-
::DateTime.months(false)[6].
|
42
|
+
expect(::DateTime.months).to be_kind_of(::Array)
|
43
|
+
expect(::DateTime.months[6]).to eq({:value => "07", :label => "7"})
|
44
|
+
expect(::DateTime.months(false)).to be_kind_of(::Array)
|
45
|
+
expect(::DateTime.months(false)[6]).to eq({:value => "07", :label => "77"})
|
46
46
|
end
|
47
47
|
|
48
48
|
end
|
49
49
|
|
50
50
|
describe ".years" do
|
51
51
|
it "should return a range of years" do
|
52
|
-
::DateTime.years.
|
53
|
-
::DateTime.years(5).
|
54
|
-
::DateTime.years(5, true, nil, true).collect(&:value).
|
55
|
-
::DateTime.years(5, false).
|
56
|
-
::DateTime.years(5, false, 1900).
|
52
|
+
expect(::DateTime.years).to eq((::Date.today.year - 10..::Date.today.year + 10).to_a)
|
53
|
+
expect(::DateTime.years(5)).to eq((::Date.today.year - 5..::Date.today.year + 5).to_a)
|
54
|
+
expect(::DateTime.years(5, true, nil, true).collect(&:value)).to eq((::Date.today.year - 5..::Date.today.year + 5).to_a)
|
55
|
+
expect(::DateTime.years(5, false)).to eq((::Date.today.year - 5..::Date.today.year).to_a)
|
56
|
+
expect(::DateTime.years(5, false, 1900)).to eq((1895..1900).to_a)
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
60
|
describe ".timezones" do
|
61
|
-
it "should list all timezones" do
|
61
|
+
it "should list all timezones" do
|
62
|
+
expect(::DateTime.timezones).to eq(::ActiveSupport::TimeZone.all)
|
63
|
+
end
|
62
64
|
end
|
63
65
|
|
64
66
|
describe ".list_timezones" do
|
@@ -99,78 +101,82 @@ describe Cowtech::Extensions::DateTime do
|
|
99
101
|
describe ".easter" do
|
100
102
|
it "should compute the valid Easter day" do
|
101
103
|
{1984 => "0422", 1995 => "0416", 2006 => "0416", 2017 => "0416"}.each do |year, date|
|
102
|
-
::DateTime.easter(year).strftime("%Y%m%d").
|
104
|
+
expect(::DateTime.easter(year).strftime("%Y%m%d")).to eq("#{year}#{date}")
|
103
105
|
end
|
104
106
|
end
|
105
107
|
end
|
106
108
|
|
107
109
|
describe ".custom_format" do
|
108
110
|
it "should find the format" do
|
109
|
-
::DateTime.custom_format(:ct_date).
|
110
|
-
::DateTime.custom_format("ct_date").
|
111
|
+
expect(::DateTime.custom_format(:ct_date)).to eq("%Y-%m-%d")
|
112
|
+
expect(::DateTime.custom_format("ct_date")).to eq("%Y-%m-%d")
|
111
113
|
|
112
114
|
::Cowtech::Extensions.settings.setup_date_formats({:ct_foo => "%ABC"})
|
113
115
|
|
114
|
-
::DateTime.custom_format(:ct_foo).
|
115
|
-
::DateTime.custom_format("ct_foo").
|
116
|
+
expect(::DateTime.custom_format(:ct_foo)).to eq("%ABC")
|
117
|
+
expect(::DateTime.custom_format("ct_foo")).to eq("%ABC")
|
116
118
|
end
|
117
119
|
|
118
|
-
it "should return the key if format is not found" do
|
120
|
+
it "should return the key if format is not found" do
|
121
|
+
::DateTime.custom_format(:ct_unused) == "ct_unused"
|
122
|
+
end
|
119
123
|
end
|
120
124
|
|
121
125
|
describe ".is_valid?" do
|
122
126
|
it "should recognize a valid date" do
|
123
|
-
::DateTime.is_valid?("2012-04-05", "%F").
|
124
|
-
::DateTime.is_valid?("2012-04-05", :ct_date).
|
127
|
+
expect(::DateTime.is_valid?("2012-04-05", "%F")).to be_true
|
128
|
+
expect(::DateTime.is_valid?("2012-04-05", :ct_date)).to be_true
|
125
129
|
end
|
126
130
|
|
127
131
|
it "should fail if the argument or the format is not valid" do
|
128
|
-
::DateTime.is_valid?("ABC", "%F").
|
129
|
-
::DateTime.is_valid?("2012-04-05", "%X").
|
132
|
+
expect(::DateTime.is_valid?("ABC", "%F")).to be_false
|
133
|
+
expect(::DateTime.is_valid?("2012-04-05", "%X")).to be_false
|
130
134
|
end
|
131
135
|
end
|
132
136
|
|
133
137
|
describe "#utc_time" do
|
134
|
-
it "should convert to UTC Time" do
|
138
|
+
it "should convert to UTC Time" do
|
139
|
+
expect(random_reference.utc_time).to be_a(::Time)
|
140
|
+
end
|
135
141
|
end
|
136
142
|
|
137
143
|
describe "#in_months" do
|
138
144
|
it "should return the amount of months passed since the start of the reference year" do
|
139
|
-
::Date.today.in_months.
|
140
|
-
fixed_reference.in_months(2000).
|
145
|
+
expect(::Date.today.in_months).to eq(::Date.today.month)
|
146
|
+
expect(fixed_reference.in_months(2000)).to eq(66)
|
141
147
|
end
|
142
148
|
end
|
143
149
|
|
144
150
|
describe "#padded_month" do
|
145
151
|
it "should pad the month number" do
|
146
|
-
random_reference.padded_month.
|
147
|
-
::Date.civil(2000, 8, 8).padded_month.
|
152
|
+
expect(random_reference.padded_month).to eq(random_reference.month.to_s.rjust(2, "0"))
|
153
|
+
expect(::Date.civil(2000, 8, 8).padded_month).to eq("08")
|
148
154
|
end
|
149
155
|
end
|
150
156
|
|
151
157
|
describe "#lstrftime" do
|
152
158
|
it "should return corrected formatted string" do
|
153
|
-
fixed_reference.lstrftime(:db).
|
154
|
-
fixed_reference.lstrftime("%F").
|
155
|
-
fixed_reference.lstrftime(:ct_iso_8601).
|
159
|
+
expect(fixed_reference.lstrftime(:db)).to eq("db")
|
160
|
+
expect(fixed_reference.lstrftime("%F")).to eq("2005-06-07")
|
161
|
+
expect(fixed_reference.lstrftime(:ct_iso_8601)).to eq("2005-06-07T08:09:10+0700")
|
156
162
|
|
157
163
|
::Cowtech::Extensions.settings.setup_date_names
|
158
164
|
::Cowtech::Extensions.settings.setup_date_formats({:ct_local_test => "%a %A %b %B %d %Y %H"})
|
159
|
-
fixed_reference.lstrftime(:ct_local_test).
|
165
|
+
expect(fixed_reference.lstrftime(:ct_local_test)).to eq("Tue Tuesday Jun June 07 2005 08")
|
160
166
|
|
161
167
|
::Cowtech::Extensions.settings.setup_date_names(
|
162
168
|
12.times.collect {|i| (i + 1).to_s * 2}, 12.times.collect {|i| (i + 1).to_s},
|
163
169
|
7.times.collect {|i| (i + 1).to_s * 2}, 7.times.collect {|i| (i + 1).to_s}
|
164
170
|
)
|
165
171
|
|
166
|
-
fixed_reference.lstrftime(:ct_local_test).
|
172
|
+
expect(fixed_reference.lstrftime(:ct_local_test)).to eq("3 33 6 66 07 2005 08")
|
167
173
|
end
|
168
174
|
|
169
175
|
it "should fix Ruby 1.8 %z and %Z bug" do
|
170
176
|
original_ruby_version = RUBY_VERSION
|
171
177
|
::Kernel::silence_warnings { Object.const_set("RUBY_VERSION", "1.9.3") }
|
172
|
-
fixed_reference.lstrftime("%z").
|
173
|
-
fixed_reference.lstrftime("%:z").
|
178
|
+
expect(fixed_reference.lstrftime("%z")).to eq("+0700")
|
179
|
+
expect(fixed_reference.lstrftime("%:z")).to eq("+07:00")
|
174
180
|
::Kernel::silence_warnings { Object.const_set("RUBY_VERSION", original_ruby_version) }
|
175
181
|
end
|
176
182
|
end
|
@@ -179,7 +185,7 @@ describe Cowtech::Extensions::DateTime do
|
|
179
185
|
it "should retrieve the date in the current timezone" do
|
180
186
|
::Time.zone = ::ActiveSupport::TimeZone[0]
|
181
187
|
::Cowtech::Extensions.settings.setup_date_formats({:ct_local_test => "%a %A %b %B %d %Y %H"})
|
182
|
-
fixed_reference.local_strftime(:ct_local_test).
|
188
|
+
expect(fixed_reference.local_strftime(:ct_local_test)).to eq("Tue Tuesday Jun June 07 2005 01")
|
183
189
|
end
|
184
190
|
end
|
185
191
|
|
@@ -195,7 +201,7 @@ describe Cowtech::Extensions::DateTime do
|
|
195
201
|
7.times.collect {|i| (i + 1).to_s * 2}, 7.times.collect {|i| (i + 1).to_s}
|
196
202
|
)
|
197
203
|
|
198
|
-
fixed_reference.local_lstrftime(:ct_local_test).
|
204
|
+
expect(fixed_reference.local_lstrftime(:ct_local_test)).to eq("3 33 6 66 07 2005 01")
|
199
205
|
end
|
200
206
|
end
|
201
207
|
end
|
@@ -210,135 +216,135 @@ describe Cowtech::Extensions::TimeZone do
|
|
210
216
|
|
211
217
|
describe ".rationalize_offset" do
|
212
218
|
it "should return the correct rational value" do
|
213
|
-
::ActiveSupport::TimeZone.rationalize_offset(::ActiveSupport::TimeZone[4]).
|
214
|
-
::ActiveSupport::TimeZone.rationalize_offset(-25200).
|
219
|
+
expect(::ActiveSupport::TimeZone.rationalize_offset(::ActiveSupport::TimeZone[4])).to eq(Rational(1, 6))
|
220
|
+
expect(::ActiveSupport::TimeZone.rationalize_offset(-25200)).to eq(Rational(-7, 24))
|
215
221
|
end
|
216
222
|
end
|
217
223
|
|
218
224
|
describe ".format_offset" do
|
219
225
|
it "should correctly format an offset" do
|
220
|
-
::ActiveSupport::TimeZone.format_offset(-25200).
|
221
|
-
::ActiveSupport::TimeZone.format_offset(Rational(-4, 24), false).
|
226
|
+
expect(::ActiveSupport::TimeZone.format_offset(-25200)).to eq("-07:00")
|
227
|
+
expect(::ActiveSupport::TimeZone.format_offset(Rational(-4, 24), false)).to eq("-0400")
|
222
228
|
end
|
223
229
|
end
|
224
230
|
|
225
231
|
describe ".parameterize_zone" do
|
226
232
|
it "should return the parameterized version of the zone" do
|
227
|
-
::ActiveSupport::TimeZone.parameterize_zone(reference_zone.to_str).
|
228
|
-
::ActiveSupport::TimeZone.parameterize_zone(reference_zone.to_str).
|
229
|
-
::ActiveSupport::TimeZone.parameterize_zone(reference_zone.to_str, false).
|
230
|
-
::ActiveSupport::TimeZone.parameterize_zone("INVALID").
|
233
|
+
expect(::ActiveSupport::TimeZone.parameterize_zone(reference_zone.to_str)).to eq(reference_zone.to_str_parameterized)
|
234
|
+
expect(::ActiveSupport::TimeZone.parameterize_zone(reference_zone.to_str)).to eq(reference_zone.to_str_parameterized)
|
235
|
+
expect(::ActiveSupport::TimeZone.parameterize_zone(reference_zone.to_str, false)).to eq(reference_zone.to_str_parameterized(false))
|
236
|
+
expect(::ActiveSupport::TimeZone.parameterize_zone("INVALID")).to eq("invalid")
|
231
237
|
end
|
232
238
|
end
|
233
239
|
|
234
240
|
describe ".unparameterize_zone" do
|
235
241
|
it "should return the parameterized version of the zone" do
|
236
|
-
::ActiveSupport::TimeZone.unparameterize_zone(reference_zone.to_str_parameterized).
|
237
|
-
::ActiveSupport::TimeZone.unparameterize_zone(reference_zone.to_str_parameterized, true).
|
238
|
-
::ActiveSupport::TimeZone.unparameterize_zone(reference_zone.to_str_with_dst_parameterized).
|
239
|
-
::ActiveSupport::TimeZone.unparameterize_zone(reference_zone.to_str_with_dst_parameterized, true).
|
240
|
-
::ActiveSupport::TimeZone.unparameterize_zone("INVALID").
|
242
|
+
expect(::ActiveSupport::TimeZone.unparameterize_zone(reference_zone.to_str_parameterized)).to eq(reference_zone)
|
243
|
+
expect(::ActiveSupport::TimeZone.unparameterize_zone(reference_zone.to_str_parameterized, true)).to eq(reference_zone.to_str)
|
244
|
+
expect(::ActiveSupport::TimeZone.unparameterize_zone(reference_zone.to_str_with_dst_parameterized)).to eq(reference_zone)
|
245
|
+
expect(::ActiveSupport::TimeZone.unparameterize_zone(reference_zone.to_str_with_dst_parameterized, true)).to eq(reference_zone.to_str_with_dst)
|
246
|
+
expect(::ActiveSupport::TimeZone.unparameterize_zone("INVALID")).to eq(nil)
|
241
247
|
end
|
242
248
|
end
|
243
249
|
|
244
250
|
describe ".find" do
|
245
251
|
it "should find timezones" do
|
246
|
-
::ActiveSupport::TimeZone.find("(GMT-07:00) Mountain Time (US & Canada)").
|
247
|
-
::ActiveSupport::TimeZone.find("(GMT-06:00) Mountain Time (US & Canada) (DST)").
|
248
|
-
::ActiveSupport::TimeZone.find("(GMT-06:00) Mountain Time (US & Canada) Daylight Saving Time", "Daylight Saving Time").
|
249
|
-
::ActiveSupport::TimeZone.find("INVALID", "INVALID").
|
252
|
+
expect(::ActiveSupport::TimeZone.find("(GMT-07:00) Mountain Time (US & Canada)")).to eq(reference_zone)
|
253
|
+
expect(::ActiveSupport::TimeZone.find("(GMT-06:00) Mountain Time (US & Canada) (DST)")).to eq(reference_zone)
|
254
|
+
expect(::ActiveSupport::TimeZone.find("(GMT-06:00) Mountain Time (US & Canada) Daylight Saving Time", "Daylight Saving Time")).to eq(reference_zone)
|
255
|
+
expect(::ActiveSupport::TimeZone.find("INVALID", "INVALID")).to be_nil
|
250
256
|
end
|
251
257
|
end
|
252
258
|
|
253
259
|
describe ".list_all" do
|
254
260
|
it "should list all timezones" do
|
255
|
-
::ActiveSupport::TimeZone.list_all(false).
|
256
|
-
::ActiveSupport::TimeZone.list_all(true).
|
257
|
-
::ActiveSupport::TimeZone.list_all(true, "Daylight Saving Time").
|
261
|
+
expect(::ActiveSupport::TimeZone.list_all(false)).to eq(::ActiveSupport::TimeZone.all.collect(&:to_s))
|
262
|
+
expect(::ActiveSupport::TimeZone.list_all(true)).to include("(GMT-06:00) #{reference_zone.aliases.first} (DST)")
|
263
|
+
expect(::ActiveSupport::TimeZone.list_all(true, "Daylight Saving Time")).to include("(GMT-06:00) #{reference_zone.aliases.first} Daylight Saving Time")
|
258
264
|
end
|
259
265
|
end
|
260
266
|
|
261
267
|
describe "#offset" do
|
262
268
|
it "should correctly return zone offset" do
|
263
|
-
reference_zone.offset.
|
269
|
+
expect(reference_zone.offset).to eq(reference_zone.utc_offset)
|
264
270
|
end
|
265
271
|
end
|
266
272
|
|
267
273
|
describe "#current_offset" do
|
268
274
|
it "should correctly return current zone offset" do
|
269
|
-
reference_zone.current_offset(false, ::DateTime.civil(2012, 1, 15)).
|
270
|
-
reference_zone.current_offset(true, ::DateTime.civil(2012, 7, 15)).
|
275
|
+
expect(reference_zone.current_offset(false, ::DateTime.civil(2012, 1, 15))).to eq(reference_zone.offset)
|
276
|
+
expect(reference_zone.current_offset(true, ::DateTime.civil(2012, 7, 15))).to eq(reference_zone.dst_offset(true))
|
271
277
|
end
|
272
278
|
end
|
273
279
|
|
274
280
|
describe "#dst_period" do
|
275
281
|
it "should correctly return zone offset" do
|
276
|
-
reference_zone.dst_period.
|
277
|
-
reference_zone.dst_period(1000).
|
278
|
-
zone_without_dst.dst_period.
|
282
|
+
expect(reference_zone.dst_period).to be_a(::TZInfo::TimezonePeriod)
|
283
|
+
expect(reference_zone.dst_period(1000)).to be_nil
|
284
|
+
expect(zone_without_dst.dst_period).to be_nil
|
279
285
|
end
|
280
286
|
end
|
281
287
|
|
282
288
|
describe "#uses_dst?" do
|
283
289
|
it "should correctly detect offset usage" do
|
284
|
-
reference_zone.uses_dst
|
285
|
-
reference_zone.uses_dst?(1000).
|
286
|
-
zone_without_dst.uses_dst
|
290
|
+
expect(reference_zone.uses_dst?).to be_true
|
291
|
+
expect(reference_zone.uses_dst?(1000)).to be_false
|
292
|
+
expect(zone_without_dst.uses_dst?).to be_false
|
287
293
|
end
|
288
294
|
end
|
289
295
|
|
290
296
|
describe "#dst_name" do
|
291
297
|
it "should correctly get zone name with Daylight Saving Time" do
|
292
|
-
reference_zone.dst_name.
|
293
|
-
reference_zone.dst_name("Daylight Saving Time").
|
294
|
-
reference_zone.dst_name(nil, 1000).
|
295
|
-
zone_without_dst.to_str_with_dst.
|
298
|
+
expect(reference_zone.dst_name).to eq("Mountain Time (US & Canada) (DST)")
|
299
|
+
expect(reference_zone.dst_name("Daylight Saving Time")).to eq("Mountain Time (US & Canada) Daylight Saving Time")
|
300
|
+
expect(reference_zone.dst_name(nil, 1000)).to be_nil
|
301
|
+
expect(zone_without_dst.to_str_with_dst).to be_nil
|
296
302
|
end
|
297
303
|
end
|
298
304
|
|
299
305
|
describe "#dst_correction" do
|
300
306
|
it "should correctly detect offset usage" do
|
301
|
-
reference_zone.dst_correction.
|
302
|
-
reference_zone.dst_correction(true).
|
303
|
-
reference_zone.dst_correction(false, 1000).
|
304
|
-
zone_without_dst.dst_correction.
|
307
|
+
expect(reference_zone.dst_correction).to eq(3600)
|
308
|
+
expect(reference_zone.dst_correction(true)).to eq(Rational(1, 24))
|
309
|
+
expect(reference_zone.dst_correction(false, 1000)).to eq(0)
|
310
|
+
expect(zone_without_dst.dst_correction).to eq(0)
|
305
311
|
end
|
306
312
|
end
|
307
313
|
|
308
314
|
describe "#dst_offset" do
|
309
315
|
it "should correctly return zone offset" do
|
310
|
-
reference_zone.dst_offset.
|
311
|
-
reference_zone.dst_offset(true).
|
312
|
-
zone_without_dst.dst_offset(false, 1000).
|
313
|
-
zone_without_dst.dst_offset.
|
316
|
+
expect(reference_zone.dst_offset).to eq(reference_zone.dst_correction + reference_zone.utc_offset)
|
317
|
+
expect(reference_zone.dst_offset(true)).to eq(::ActiveSupport::TimeZone.rationalize_offset(reference_zone.dst_correction + reference_zone.utc_offset))
|
318
|
+
expect(zone_without_dst.dst_offset(false, 1000)).to eq(0)
|
319
|
+
expect(zone_without_dst.dst_offset).to eq(0)
|
314
320
|
end
|
315
321
|
end
|
316
322
|
|
317
323
|
describe "#to_str_with_dst" do
|
318
324
|
it "should correctly format zone with Daylight Saving Time" do
|
319
|
-
reference_zone.to_str_with_dst.
|
320
|
-
reference_zone.to_str_with_dst("Daylight Saving Time").
|
321
|
-
reference_zone.to_str_with_dst("Daylight Saving Time", nil, "NAME").
|
322
|
-
reference_zone.to_str_with_dst(nil, 1000).
|
323
|
-
zone_without_dst.to_str_with_dst.
|
325
|
+
expect(reference_zone.to_str_with_dst).to eq("(GMT-06:00) #{reference_zone.aliases.first} (DST)")
|
326
|
+
expect(reference_zone.to_str_with_dst("Daylight Saving Time")).to eq("(GMT-06:00) #{reference_zone.aliases.first} Daylight Saving Time")
|
327
|
+
expect(reference_zone.to_str_with_dst("Daylight Saving Time", nil, "NAME")).to eq("(GMT-06:00) NAME Daylight Saving Time")
|
328
|
+
expect(reference_zone.to_str_with_dst(nil, 1000)).to be_nil
|
329
|
+
expect(zone_without_dst.to_str_with_dst).to be_nil
|
324
330
|
end
|
325
331
|
end
|
326
332
|
|
327
333
|
describe "#to_str_parameterized" do
|
328
334
|
it "should correctly format (parameterized) zone" do
|
329
|
-
reference_zone.to_str_parameterized.
|
330
|
-
reference_zone.to_str_parameterized(false).
|
331
|
-
reference_zone.to_str_parameterized(false, "NAME SPACE").
|
335
|
+
expect(reference_zone.to_str_parameterized).to eq(::ActiveSupport::TimeZone.parameterize_zone(reference_zone.to_str))
|
336
|
+
expect(reference_zone.to_str_parameterized(false)).to eq(::ActiveSupport::TimeZone.parameterize_zone(reference_zone.to_str, false))
|
337
|
+
expect(reference_zone.to_str_parameterized(false, "NAME SPACE")).to eq(::ActiveSupport::TimeZone.parameterize_zone("NAME SPACE", false))
|
332
338
|
end
|
333
339
|
end
|
334
340
|
|
335
341
|
describe "#to_str_with_dst_parameterized" do
|
336
342
|
it "should correctly format (parameterized) zone with Daylight Saving Time" do
|
337
|
-
reference_zone.to_str_with_dst_parameterized.
|
338
|
-
reference_zone.to_str_with_dst_parameterized("Daylight Saving Time").
|
339
|
-
reference_zone.to_str_with_dst_parameterized(nil, false, 1000).
|
340
|
-
reference_zone.to_str_with_dst_parameterized("Daylight Saving Time", true, nil, "NAME SPACE").
|
341
|
-
zone_without_dst.to_str_with_dst_parameterized.
|
343
|
+
expect(reference_zone.to_str_with_dst_parameterized).to eq("-0600@america-denver-dst")
|
344
|
+
expect(reference_zone.to_str_with_dst_parameterized("Daylight Saving Time")).to eq("-0600@america-denver-daylight-saving-time")
|
345
|
+
expect(reference_zone.to_str_with_dst_parameterized(nil, false, 1000)).to be_nil
|
346
|
+
expect(reference_zone.to_str_with_dst_parameterized("Daylight Saving Time", true, nil, "NAME SPACE")).to eq("-0600@name-space-daylight-saving-time")
|
347
|
+
expect(zone_without_dst.to_str_with_dst_parameterized).to be_nil
|
342
348
|
end
|
343
349
|
end
|
344
350
|
end
|