lazier 3.5.2 → 3.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/doc/Lazier.html +38 -38
- data/doc/Lazier/Boolean.html +1 -1
- data/doc/Lazier/Configuration.html +1 -1
- data/doc/Lazier/DateTime.html +1 -1
- data/doc/Lazier/DateTime/ClassMethods.html +1 -1
- data/doc/Lazier/Exceptions.html +1 -1
- data/doc/Lazier/Exceptions/Debug.html +1 -1
- data/doc/Lazier/Exceptions/MissingTranslation.html +1 -1
- data/doc/Lazier/Hash.html +1 -1
- data/doc/Lazier/I18n.html +1 -1
- data/doc/Lazier/Localizer.html +1 -1
- data/doc/Lazier/Math.html +1 -1
- data/doc/Lazier/Math/ClassMethods.html +1 -1
- data/doc/Lazier/Object.html +1 -1
- data/doc/Lazier/Pathname.html +1 -1
- data/doc/Lazier/Settings.html +1 -1
- data/doc/Lazier/String.html +1 -1
- data/doc/Lazier/TimeZone.html +79 -79
- data/doc/Lazier/TimeZone/ClassMethods.html +65 -65
- data/doc/Lazier/Version.html +2 -2
- data/doc/_index.html +1 -1
- data/doc/file.README.html +1 -1
- data/doc/index.html +1 -1
- data/doc/method_list.html +24 -24
- data/doc/top-level-namespace.html +1 -1
- data/lib/lazier.rb +1 -0
- data/lib/lazier/datetime.rb +0 -292
- data/lib/lazier/timezone.rb +299 -0
- data/lib/lazier/version.rb +1 -1
- data/spec/lazier/datetime_spec.rb +0 -157
- data/spec/lazier/timezone_spec.rb +164 -0
- metadata +5 -2
@@ -79,7 +79,7 @@
|
|
79
79
|
|
80
80
|
|
81
81
|
<dt class="r1 last">Defined in:</dt>
|
82
|
-
<dd class="r1 last">lib/lazier/
|
82
|
+
<dd class="r1 last">lib/lazier/timezone.rb</dd>
|
83
83
|
|
84
84
|
</dl>
|
85
85
|
<div class="clear"></div>
|
@@ -355,14 +355,14 @@
|
|
355
355
|
<pre class="lines">
|
356
356
|
|
357
357
|
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
358
|
+
109
|
359
|
+
110
|
360
|
+
111
|
361
|
+
112
|
362
|
+
113</pre>
|
363
363
|
</td>
|
364
364
|
<td>
|
365
|
-
<pre class="code"><span class="info file"># File 'lib/lazier/
|
365
|
+
<pre class="code"><span class="info file"># File 'lib/lazier/timezone.rb', line 109</span>
|
366
366
|
|
367
367
|
<span class='kw'>def</span> <span class='id identifier rubyid_compare'>compare</span><span class='lparen'>(</span><span class='id identifier rubyid_left'>left</span><span class='comma'>,</span> <span class='id identifier rubyid_right'>right</span><span class='rparen'>)</span>
|
368
368
|
<span class='id identifier rubyid_left'>left</span> <span class='op'>=</span> <span class='id identifier rubyid_left'>left</span><span class='period'>.</span><span class='id identifier rubyid_to_str'>to_str</span> <span class='kw'>if</span> <span class='id identifier rubyid_left'>left</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>ActiveSupport</span><span class='op'>::</span><span class='const'>TimeZone</span><span class='rparen'>)</span>
|
@@ -452,20 +452,20 @@
|
|
452
452
|
<pre class="lines">
|
453
453
|
|
454
454
|
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
455
|
+
36
|
456
|
+
37
|
457
|
+
38
|
458
|
+
39
|
459
|
+
40
|
460
|
+
41
|
461
|
+
42
|
462
|
+
43
|
463
|
+
44
|
464
|
+
45
|
465
|
+
46</pre>
|
466
466
|
</td>
|
467
467
|
<td>
|
468
|
-
<pre class="code"><span class="info file"># File 'lib/lazier/
|
468
|
+
<pre class="code"><span class="info file"># File 'lib/lazier/timezone.rb', line 36</span>
|
469
469
|
|
470
470
|
<span class='kw'>def</span> <span class='id identifier rubyid_find'>find</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='comma'>,</span> <span class='id identifier rubyid_dst_label'>dst_label</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span>
|
471
471
|
<span class='id identifier rubyid_catch'>catch</span><span class='lparen'>(</span><span class='symbol'>:zone</span><span class='rparen'>)</span> <span class='kw'>do</span>
|
@@ -561,12 +561,12 @@
|
|
561
561
|
<pre class="lines">
|
562
562
|
|
563
563
|
|
564
|
-
|
565
|
-
|
566
|
-
|
564
|
+
27
|
565
|
+
28
|
566
|
+
29</pre>
|
567
567
|
</td>
|
568
568
|
<td>
|
569
|
-
<pre class="code"><span class="info file"># File 'lib/lazier/
|
569
|
+
<pre class="code"><span class="info file"># File 'lib/lazier/timezone.rb', line 27</span>
|
570
570
|
|
571
571
|
<span class='kw'>def</span> <span class='id identifier rubyid_format_offset'>format_offset</span><span class='lparen'>(</span><span class='id identifier rubyid_offset'>offset</span><span class='comma'>,</span> <span class='id identifier rubyid_colon'>colon</span> <span class='op'>=</span> <span class='kw'>true</span><span class='rparen'>)</span>
|
572
572
|
<span class='id identifier rubyid_seconds_to_utc_offset'>seconds_to_utc_offset</span><span class='lparen'>(</span><span class='id identifier rubyid_offset'>offset</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>Rational</span><span class='rparen'>)</span> <span class='op'>?</span> <span class='lparen'>(</span><span class='id identifier rubyid_offset'>offset</span> <span class='op'>*</span> <span class='int'>86_400</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_i'>to_i</span> <span class='op'>:</span> <span class='id identifier rubyid_offset'>offset</span><span class='comma'>,</span> <span class='id identifier rubyid_colon'>colon</span><span class='rparen'>)</span>
|
@@ -656,27 +656,27 @@
|
|
656
656
|
<pre class="lines">
|
657
657
|
|
658
658
|
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
659
|
+
53
|
660
|
+
54
|
661
|
+
55
|
662
|
+
56
|
663
|
+
57
|
664
|
+
58
|
665
|
+
59
|
666
|
+
60
|
667
|
+
61
|
668
|
+
62</pre>
|
669
669
|
</td>
|
670
670
|
<td>
|
671
|
-
<pre class="code"><span class="info file"># File 'lib/lazier/
|
671
|
+
<pre class="code"><span class="info file"># File 'lib/lazier/timezone.rb', line 53</span>
|
672
672
|
|
673
673
|
<span class='kw'>def</span> <span class='id identifier rubyid_list_all'>list_all</span><span class='lparen'>(</span><span class='id identifier rubyid_with_dst'>with_dst</span> <span class='op'>=</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='id identifier rubyid_dst_label'>dst_label</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span>
|
674
674
|
<span class='id identifier rubyid_dst_label'>dst_label</span> <span class='op'>||=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>(DST)</span><span class='tstring_end'>"</span></span>
|
675
675
|
|
676
676
|
<span class='ivar'>@zones_names</span> <span class='op'>||=</span> <span class='lbrace'>{</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>STANDARD</span><span class='tstring_end'>"</span></span> <span class='op'>=></span> <span class='op'>::</span><span class='const'>ActiveSupport</span><span class='op'>::</span><span class='const'>TimeZone</span><span class='period'>.</span><span class='id identifier rubyid_all'>all</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span><span class='lparen'>(</span><span class='op'>&</span><span class='symbol'>:to_s</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
|
677
677
|
<span class='ivar'>@zones_names</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>DST[</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_dst_label'>dst_label</span><span class='embexpr_end'>}</span><span class='tstring_content'>]-STANDARD</span><span class='tstring_end'>"</span></span><span class='rbracket'>]</span> <span class='op'>||=</span> <span class='op'>::</span><span class='const'>ActiveSupport</span><span class='op'>::</span><span class='const'>TimeZone</span><span class='period'>.</span><span class='id identifier rubyid_all'>all</span><span class='period'>
|
678
|
-
</span><span class='id identifier rubyid_
|
679
|
-
</span><span class='id identifier rubyid_
|
678
|
+
</span><span class='id identifier rubyid_ .map'> .map</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_zone'>zone</span><span class='op'>|</span> <span class='id identifier rubyid_fetch_aliases'>fetch_aliases</span><span class='lparen'>(</span><span class='id identifier rubyid_zone'>zone</span><span class='comma'>,</span> <span class='id identifier rubyid_dst_label'>dst_label</span><span class='rparen'>)</span> <span class='rbrace'>}</span><span class='period'>.</span><span class='id identifier rubyid_flatten'>flatten</span><span class='period'>.</span><span class='id identifier rubyid_compact'>compact</span><span class='period'>.</span><span class='id identifier rubyid_uniq'>uniq</span><span class='period'>
|
679
|
+
</span><span class='id identifier rubyid_ .sort'> .sort</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_a'>a</span><span class='comma'>,</span> <span class='id identifier rubyid_b'>b</span><span class='op'>|</span> <span class='op'>::</span><span class='const'>ActiveSupport</span><span class='op'>::</span><span class='const'>TimeZone</span><span class='period'>.</span><span class='id identifier rubyid_compare'>compare</span><span class='lparen'>(</span><span class='id identifier rubyid_a'>a</span><span class='comma'>,</span> <span class='id identifier rubyid_b'>b</span><span class='rparen'>)</span> <span class='rbrace'>}</span> <span class='comment'># Sort by name
|
680
680
|
</span>
|
681
681
|
<span class='ivar'>@zones_names</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_with_dst'>with_dst</span> <span class='op'>?</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>DST[</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_dst_label'>dst_label</span><span class='embexpr_end'>}</span><span class='tstring_content'>]-</span><span class='tstring_end'>"</span></span> <span class='op'>:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_end'>"</span></span><span class='embexpr_end'>}</span><span class='tstring_content'>STANDARD</span><span class='tstring_end'>"</span></span><span class='rbracket'>]</span>
|
682
682
|
<span class='kw'>end</span></pre>
|
@@ -768,21 +768,21 @@ DateTime.parameterize_zone(ActiveSupport::TimeZone["Pacific Time (US & Canad
|
|
768
768
|
<pre class="lines">
|
769
769
|
|
770
770
|
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
771
|
+
73
|
772
|
+
74
|
773
|
+
75
|
774
|
+
76
|
775
|
+
77
|
776
|
+
78
|
777
|
+
79
|
778
|
+
80
|
779
|
+
81
|
780
|
+
82
|
781
|
+
83
|
782
|
+
84</pre>
|
783
783
|
</td>
|
784
784
|
<td>
|
785
|
-
<pre class="code"><span class="info file"># File 'lib/lazier/
|
785
|
+
<pre class="code"><span class="info file"># File 'lib/lazier/timezone.rb', line 73</span>
|
786
786
|
|
787
787
|
<span class='kw'>def</span> <span class='id identifier rubyid_parameterize_zone'>parameterize_zone</span><span class='lparen'>(</span><span class='id identifier rubyid_tz'>tz</span><span class='comma'>,</span> <span class='id identifier rubyid_with_offset'>with_offset</span> <span class='op'>=</span> <span class='kw'>true</span><span class='rparen'>)</span>
|
788
788
|
<span class='id identifier rubyid_tz'>tz</span> <span class='op'>=</span> <span class='id identifier rubyid_tz'>tz</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span> <span class='kw'>unless</span> <span class='id identifier rubyid_tz'>tz</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>String</span><span class='rparen'>)</span>
|
@@ -862,12 +862,12 @@ DateTime.parameterize_zone(ActiveSupport::TimeZone["Pacific Time (US & Canad
|
|
862
862
|
<pre class="lines">
|
863
863
|
|
864
864
|
|
865
|
-
|
866
|
-
|
867
|
-
|
865
|
+
18
|
866
|
+
19
|
867
|
+
20</pre>
|
868
868
|
</td>
|
869
869
|
<td>
|
870
|
-
<pre class="code"><span class="info file"># File 'lib/lazier/
|
870
|
+
<pre class="code"><span class="info file"># File 'lib/lazier/timezone.rb', line 18</span>
|
871
871
|
|
872
872
|
<span class='kw'>def</span> <span class='id identifier rubyid_rationalize_offset'>rationalize_offset</span><span class='lparen'>(</span><span class='id identifier rubyid_offset'>offset</span><span class='rparen'>)</span>
|
873
873
|
<span class='op'>::</span><span class='const'>TZInfo</span><span class='op'>::</span><span class='const'>OffsetRationals</span><span class='period'>.</span><span class='id identifier rubyid_rational_for_offset'>rational_for_offset</span><span class='lparen'>(</span><span class='id identifier rubyid_offset'>offset</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>Fixnum</span><span class='rparen'>)</span> <span class='op'>?</span> <span class='id identifier rubyid_offset'>offset</span> <span class='op'>:</span> <span class='id identifier rubyid_offset'>offset</span><span class='period'>.</span><span class='id identifier rubyid_offset'>offset</span><span class='rparen'>)</span>
|
@@ -979,19 +979,19 @@ DateTime.parameterize_zone(ActiveSupport::TimeZone["Pacific Time (US & Canad
|
|
979
979
|
<pre class="lines">
|
980
980
|
|
981
981
|
|
982
|
-
|
983
|
-
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
|
982
|
+
93
|
983
|
+
94
|
984
|
+
95
|
985
|
+
96
|
986
|
+
97
|
987
|
+
98
|
988
|
+
99
|
989
|
+
100
|
990
|
+
101
|
991
|
+
102</pre>
|
992
992
|
</td>
|
993
993
|
<td>
|
994
|
-
<pre class="code"><span class="info file"># File 'lib/lazier/
|
994
|
+
<pre class="code"><span class="info file"># File 'lib/lazier/timezone.rb', line 93</span>
|
995
995
|
|
996
996
|
<span class='kw'>def</span> <span class='id identifier rubyid_unparameterize_zone'>unparameterize_zone</span><span class='lparen'>(</span><span class='id identifier rubyid_tz'>tz</span><span class='comma'>,</span> <span class='id identifier rubyid_as_string'>as_string</span> <span class='op'>=</span> <span class='kw'>false</span><span class='comma'>,</span> <span class='id identifier rubyid_dst_label'>dst_label</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span>
|
997
997
|
<span class='id identifier rubyid_tz'>tz</span> <span class='op'>=</span> <span class='id identifier rubyid_parameterize_zone'>parameterize_zone</span><span class='lparen'>(</span><span class='id identifier rubyid_tz'>tz</span><span class='comma'>,</span> <span class='kw'>false</span><span class='rparen'>)</span>
|
@@ -1013,7 +1013,7 @@ DateTime.parameterize_zone(ActiveSupport::TimeZone["Pacific Time (US & Canad
|
|
1013
1013
|
</div>
|
1014
1014
|
|
1015
1015
|
<div id="footer">
|
1016
|
-
Generated on
|
1016
|
+
Generated on Sat May 10 10:54:36 2014 by
|
1017
1017
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
1018
1018
|
0.8.7.4 (ruby-2.1.0).
|
1019
1019
|
</div>
|
data/doc/Lazier/Version.html
CHANGED
@@ -149,7 +149,7 @@
|
|
149
149
|
|
150
150
|
</div>
|
151
151
|
</dt>
|
152
|
-
<dd><pre class="code"><span class='int'>
|
152
|
+
<dd><pre class="code"><span class='int'>3</span></pre></dd>
|
153
153
|
|
154
154
|
<dt id="STRING-constant" class="">STRING =
|
155
155
|
<div class="docstring">
|
@@ -180,7 +180,7 @@
|
|
180
180
|
</div>
|
181
181
|
|
182
182
|
<div id="footer">
|
183
|
-
Generated on
|
183
|
+
Generated on Sat May 10 10:54:36 2014 by
|
184
184
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
185
185
|
0.8.7.4 (ruby-2.1.0).
|
186
186
|
</div>
|
data/doc/_index.html
CHANGED
@@ -333,7 +333,7 @@
|
|
333
333
|
</div>
|
334
334
|
|
335
335
|
<div id="footer">
|
336
|
-
Generated on
|
336
|
+
Generated on Sat May 10 10:54:35 2014 by
|
337
337
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
338
338
|
0.8.7.4 (ruby-2.1.0).
|
339
339
|
</div>
|
data/doc/file.README.html
CHANGED
@@ -106,7 +106,7 @@ See documentation for more informations.</p>
|
|
106
106
|
</div></div>
|
107
107
|
|
108
108
|
<div id="footer">
|
109
|
-
Generated on
|
109
|
+
Generated on Sat May 10 10:54:35 2014 by
|
110
110
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
111
111
|
0.8.7.4 (ruby-2.1.0).
|
112
112
|
</div>
|
data/doc/index.html
CHANGED
@@ -106,7 +106,7 @@ See documentation for more informations.</p>
|
|
106
106
|
</div></div>
|
107
107
|
|
108
108
|
<div id="footer">
|
109
|
-
Generated on
|
109
|
+
Generated on Sat May 10 10:54:35 2014 by
|
110
110
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
111
111
|
0.8.7.4 (ruby-2.1.0).
|
112
112
|
</div>
|
data/doc/method_list.html
CHANGED
@@ -264,14 +264,14 @@
|
|
264
264
|
|
265
265
|
|
266
266
|
<li class="r1 ">
|
267
|
-
<span class='object_link'><a href="Lazier/
|
268
|
-
<small>Lazier::
|
267
|
+
<span class='object_link'><a href="Lazier/I18n.html#i18n-instance_method" title="Lazier::I18n#i18n (method)">#i18n</a></span>
|
268
|
+
<small>Lazier::I18n</small>
|
269
269
|
</li>
|
270
270
|
|
271
271
|
|
272
272
|
<li class="r2 ">
|
273
|
-
<span class='object_link'><a href="Lazier/
|
274
|
-
<small>Lazier::
|
273
|
+
<span class='object_link'><a href="Lazier/Settings.html#i18n-instance_method" title="Lazier::Settings#i18n (method)">#i18n</a></span>
|
274
|
+
<small>Lazier::Settings</small>
|
275
275
|
</li>
|
276
276
|
|
277
277
|
|
@@ -318,26 +318,26 @@
|
|
318
318
|
|
319
319
|
|
320
320
|
<li class="r2 ">
|
321
|
-
<span class='object_link'><a href="Lazier/
|
322
|
-
<small>Lazier::
|
321
|
+
<span class='object_link'><a href="Lazier/Settings.html#initialize-instance_method" title="Lazier::Settings#initialize (method)">#initialize</a></span>
|
322
|
+
<small>Lazier::Settings</small>
|
323
323
|
</li>
|
324
324
|
|
325
325
|
|
326
326
|
<li class="r1 ">
|
327
|
-
<span class='object_link'><a href="Lazier/
|
328
|
-
<small>Lazier::
|
327
|
+
<span class='object_link'><a href="Lazier/Localizer.html#initialize-instance_method" title="Lazier::Localizer#initialize (method)">#initialize</a></span>
|
328
|
+
<small>Lazier::Localizer</small>
|
329
329
|
</li>
|
330
330
|
|
331
331
|
|
332
332
|
<li class="r2 ">
|
333
|
-
<span class='object_link'><a href="Lazier/
|
334
|
-
<small>Lazier::
|
333
|
+
<span class='object_link'><a href="Lazier/Exceptions/MissingTranslation.html#initialize-instance_method" title="Lazier::Exceptions::MissingTranslation#initialize (method)">#initialize</a></span>
|
334
|
+
<small>Lazier::Exceptions::MissingTranslation</small>
|
335
335
|
</li>
|
336
336
|
|
337
337
|
|
338
338
|
<li class="r1 ">
|
339
|
-
<span class='object_link'><a href="Lazier/
|
340
|
-
<small>Lazier::
|
339
|
+
<span class='object_link'><a href="Lazier/Configuration.html#initialize-instance_method" title="Lazier::Configuration#initialize (method)">#initialize</a></span>
|
340
|
+
<small>Lazier::Configuration</small>
|
341
341
|
</li>
|
342
342
|
|
343
343
|
|
@@ -492,14 +492,14 @@
|
|
492
492
|
|
493
493
|
|
494
494
|
<li class="r1 ">
|
495
|
-
<span class='object_link'><a href="Lazier/
|
496
|
-
<small>Lazier::
|
495
|
+
<span class='object_link'><a href="Lazier/DateTime/ClassMethods.html#parameterize_zone-instance_method" title="Lazier::DateTime::ClassMethods#parameterize_zone (method)">#parameterize_zone</a></span>
|
496
|
+
<small>Lazier::DateTime::ClassMethods</small>
|
497
497
|
</li>
|
498
498
|
|
499
499
|
|
500
500
|
<li class="r2 ">
|
501
|
-
<span class='object_link'><a href="Lazier/
|
502
|
-
<small>Lazier::
|
501
|
+
<span class='object_link'><a href="Lazier/TimeZone/ClassMethods.html#parameterize_zone-instance_method" title="Lazier::TimeZone::ClassMethods#parameterize_zone (method)">#parameterize_zone</a></span>
|
502
|
+
<small>Lazier::TimeZone::ClassMethods</small>
|
503
503
|
</li>
|
504
504
|
|
505
505
|
|
@@ -510,14 +510,14 @@
|
|
510
510
|
|
511
511
|
|
512
512
|
<li class="r2 ">
|
513
|
-
<span class='object_link'><a href="Lazier/
|
514
|
-
<small>Lazier::
|
513
|
+
<span class='object_link'><a href="Lazier/TimeZone/ClassMethods.html#rationalize_offset-instance_method" title="Lazier::TimeZone::ClassMethods#rationalize_offset (method)">#rationalize_offset</a></span>
|
514
|
+
<small>Lazier::TimeZone::ClassMethods</small>
|
515
515
|
</li>
|
516
516
|
|
517
517
|
|
518
518
|
<li class="r1 ">
|
519
|
-
<span class='object_link'><a href="Lazier/
|
520
|
-
<small>Lazier::
|
519
|
+
<span class='object_link'><a href="Lazier/DateTime/ClassMethods.html#rationalize_offset-instance_method" title="Lazier::DateTime::ClassMethods#rationalize_offset (method)">#rationalize_offset</a></span>
|
520
|
+
<small>Lazier::DateTime::ClassMethods</small>
|
521
521
|
</li>
|
522
522
|
|
523
523
|
|
@@ -678,14 +678,14 @@
|
|
678
678
|
|
679
679
|
|
680
680
|
<li class="r2 ">
|
681
|
-
<span class='object_link'><a href="Lazier/
|
682
|
-
<small>Lazier::
|
681
|
+
<span class='object_link'><a href="Lazier/Boolean.html#value-instance_method" title="Lazier::Boolean#value (method)">#value</a></span>
|
682
|
+
<small>Lazier::Boolean</small>
|
683
683
|
</li>
|
684
684
|
|
685
685
|
|
686
686
|
<li class="r1 ">
|
687
|
-
<span class='object_link'><a href="Lazier/
|
688
|
-
<small>Lazier::
|
687
|
+
<span class='object_link'><a href="Lazier/String.html#value-instance_method" title="Lazier::String#value (method)">#value</a></span>
|
688
|
+
<small>Lazier::String</small>
|
689
689
|
</li>
|
690
690
|
|
691
691
|
|
@@ -103,7 +103,7 @@
|
|
103
103
|
</div>
|
104
104
|
|
105
105
|
<div id="footer">
|
106
|
-
Generated on
|
106
|
+
Generated on Sat May 10 10:54:35 2014 by
|
107
107
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
108
108
|
0.8.7.4 (ruby-2.1.0).
|
109
109
|
</div>
|
data/lib/lazier.rb
CHANGED
data/lib/lazier/datetime.rb
CHANGED
@@ -273,296 +273,4 @@ module Lazier
|
|
273
273
|
::Lazier.settings.date_names[type][index]
|
274
274
|
end
|
275
275
|
end
|
276
|
-
|
277
|
-
# Extensions for timezone objects.
|
278
|
-
module TimeZone
|
279
|
-
extend ::ActiveSupport::Concern
|
280
|
-
|
281
|
-
# General methods.
|
282
|
-
module ClassMethods
|
283
|
-
# Returns an offset in rational value.
|
284
|
-
#
|
285
|
-
# @param offset [Fixnum] The offset to convert.
|
286
|
-
# @return [Rational] The converted offset.
|
287
|
-
def rationalize_offset(offset)
|
288
|
-
::TZInfo::OffsetRationals.rational_for_offset(offset.is_a?(::Fixnum) ? offset : offset.offset)
|
289
|
-
end
|
290
|
-
|
291
|
-
# Returns a +HH:MM formatted representation of the offset.
|
292
|
-
#
|
293
|
-
# @param offset [Rational|Fixnum] The offset to represent, in seconds or as a rational.
|
294
|
-
# @param colon [Boolean] If to put the colon in the output string.
|
295
|
-
# @return [String] The formatted offset.
|
296
|
-
def format_offset(offset, colon = true)
|
297
|
-
seconds_to_utc_offset(offset.is_a?(::Rational) ? (offset * 86_400).to_i : offset, colon)
|
298
|
-
end
|
299
|
-
|
300
|
-
# Find a zone by its name.
|
301
|
-
#
|
302
|
-
# @param name [String] The zone name.
|
303
|
-
# @param dst_label [String] Label for the DST indication. Defaults to `(DST)`.
|
304
|
-
# @return [TimeZone] A timezone or `nil` if no zone was found.
|
305
|
-
def find(name, dst_label = nil)
|
306
|
-
catch(:zone) do
|
307
|
-
::ActiveSupport::TimeZone.all.each do |zone|
|
308
|
-
zone.aliases.each do |zone_alias|
|
309
|
-
throw(:zone, zone) if [zone.to_str(zone_alias), zone.to_str_with_dst(dst_label, nil, zone_alias)].include?(name)
|
310
|
-
end
|
311
|
-
end
|
312
|
-
|
313
|
-
nil
|
314
|
-
end
|
315
|
-
end
|
316
|
-
|
317
|
-
# Returns a list of names of all timezones.
|
318
|
-
#
|
319
|
-
# @param with_dst [Boolean] If include DST version of the zones.
|
320
|
-
# @param dst_label [String] Label for the DST indication. Defaults to `(DST)`.
|
321
|
-
# @return [Array] A list of names of timezones.
|
322
|
-
def list_all(with_dst = true, dst_label = nil)
|
323
|
-
dst_label ||= "(DST)"
|
324
|
-
|
325
|
-
@zones_names ||= { "STANDARD" => ::ActiveSupport::TimeZone.all.map(&:to_s) }
|
326
|
-
@zones_names["DST[#{dst_label}]-STANDARD"] ||= ::ActiveSupport::TimeZone.all
|
327
|
-
.map { |zone| fetch_aliases(zone, dst_label) }.flatten.compact.uniq
|
328
|
-
.sort { |a, b| ::ActiveSupport::TimeZone.compare(a, b) } # Sort by name
|
329
|
-
|
330
|
-
@zones_names["#{with_dst ? "DST[#{dst_label}]-" : ""}STANDARD"]
|
331
|
-
end
|
332
|
-
|
333
|
-
# Returns a string representation of a timezone.
|
334
|
-
#
|
335
|
-
# ```ruby
|
336
|
-
# DateTime.parameterize_zone(ActiveSupport::TimeZone["Pacific Time (US & Canada)"])
|
337
|
-
# # => "-0800@pacific-time-us-canada"
|
338
|
-
# ```
|
339
|
-
# @param tz [TimeZone] The zone to represent.
|
340
|
-
# @param with_offset [Boolean] If to include offset into the representation.
|
341
|
-
# @return [String] A string representation which can be used for searches.
|
342
|
-
def parameterize_zone(tz, with_offset = true)
|
343
|
-
tz = tz.to_s unless tz.is_a?(::String)
|
344
|
-
mo = /^(\([a-z]+([+-])(\d{2})(:?)(\d{2})\)\s(.+))$/i.match(tz)
|
345
|
-
|
346
|
-
if mo
|
347
|
-
with_offset ? "#{mo[2]}#{mo[3]}#{mo[5]}@#{mo[6].to_s.parameterize}" : mo[6].to_s.parameterize
|
348
|
-
elsif !with_offset then
|
349
|
-
tz.gsub(/^([+-]?(\d{2})(:?)(\d{2})@)/, "")
|
350
|
-
else
|
351
|
-
tz.parameterize
|
352
|
-
end
|
353
|
-
end
|
354
|
-
|
355
|
-
# Finds a parameterized timezone.
|
356
|
-
# @see DateTime#parameterize_zone
|
357
|
-
#
|
358
|
-
# @param tz [String] The zone to unparameterize.
|
359
|
-
# @param as_string [Boolean] If return just the zone name.
|
360
|
-
# @param dst_label [String] Label for the DST indication. Defaults to `(DST)`.
|
361
|
-
# @return [String|TimeZone] The found timezone or `nil` if the zone is not valid.
|
362
|
-
def unparameterize_zone(tz, as_string = false, dst_label = nil)
|
363
|
-
tz = parameterize_zone(tz, false)
|
364
|
-
rv = find_parameterized_zone(dst_label, /(#{Regexp.quote(tz)})$/)
|
365
|
-
|
366
|
-
if rv
|
367
|
-
as_string ? rv : find(rv, dst_label)
|
368
|
-
else
|
369
|
-
nil
|
370
|
-
end
|
371
|
-
end
|
372
|
-
|
373
|
-
# Compares two timezones. They are sorted by the location name.
|
374
|
-
#
|
375
|
-
# @param left [String|TimeZone] The first zone name to compare.
|
376
|
-
# @param right [String|TimeZone] The second zone name to compare.
|
377
|
-
# @return [Fixnum] The result of comparison, like Ruby's operator `<=>`.
|
378
|
-
def compare(left, right)
|
379
|
-
left = left.to_str if left.is_a?(::ActiveSupport::TimeZone)
|
380
|
-
right = right.to_str if right.is_a?(::ActiveSupport::TimeZone)
|
381
|
-
left.ensure_string.split(" ", 2)[1] <=> right.ensure_string.split(" ", 2)[1]
|
382
|
-
end
|
383
|
-
|
384
|
-
private
|
385
|
-
|
386
|
-
# Returns a list of aliases for a given time zone.
|
387
|
-
#
|
388
|
-
# @param zone [ActiveSupport::TimeZone] The zone.
|
389
|
-
# @param dst_label [String] Label for the DST indication. Defaults to `(DST)`.
|
390
|
-
def fetch_aliases(zone, dst_label = "(DST)")
|
391
|
-
matcher = /(#{Regexp.quote(dst_label)})$/
|
392
|
-
|
393
|
-
zone.aliases.map { |zone_alias|
|
394
|
-
[zone.to_str(zone_alias), (zone.uses_dst? && zone_alias !~ matcher) ? zone.to_str_with_dst(dst_label, nil, zone_alias) : nil]
|
395
|
-
}
|
396
|
-
end
|
397
|
-
|
398
|
-
# Finds a parameterized timezone.
|
399
|
-
#
|
400
|
-
# @param dst_label [String] Label for the DST indication. Defaults to `(DST)`.
|
401
|
-
# @param matcher [Regexp] The expression to match.
|
402
|
-
# @return [TimeZone] The found timezone or `nil` if the zone is not valid.
|
403
|
-
def find_parameterized_zone(dst_label, matcher)
|
404
|
-
catch(:zone) do
|
405
|
-
list_all(true, dst_label).each do |zone|
|
406
|
-
throw(:zone, zone) if parameterize_zone(zone, false) =~ matcher
|
407
|
-
end
|
408
|
-
|
409
|
-
nil
|
410
|
-
end
|
411
|
-
end
|
412
|
-
end
|
413
|
-
|
414
|
-
# Returns a list of valid aliases (city names) for this timezone (basing on offset).
|
415
|
-
# @return [Array] A list of aliases for this timezone
|
416
|
-
def aliases
|
417
|
-
reference = self.class::MAPPING.fetch(name, name).gsub("_", " ")
|
418
|
-
@aliases ||= ([reference] + self.class::MAPPING.map { |name, zone| format_alias(name, zone, reference) }).uniq.compact.sort
|
419
|
-
end
|
420
|
-
|
421
|
-
# Returns the current offset for this timezone, taking care of Daylight Saving Time (DST).
|
422
|
-
#
|
423
|
-
# @param rational [Boolean] If to return the offset as a Rational.
|
424
|
-
# @param date [DateTime] The date to consider. Defaults to now.
|
425
|
-
# @return [Fixnum|Rational] The offset of this timezone.
|
426
|
-
def current_offset(rational = false, date = nil)
|
427
|
-
date ||= ::DateTime.now
|
428
|
-
rv = (period_for_utc(date.utc).dst? ? dst_offset : offset)
|
429
|
-
rational ? self.class.rationalize_offset(rv) : rv
|
430
|
-
end
|
431
|
-
|
432
|
-
# Returns the current alias for this timezone.
|
433
|
-
#
|
434
|
-
# @return [String] The current alias or the first alias of the current timezone.
|
435
|
-
def current_alias
|
436
|
-
identifier = tzinfo.identifier
|
437
|
-
|
438
|
-
catch(:alias) do
|
439
|
-
aliases.each do |a|
|
440
|
-
throw(:alias, a) if a == identifier
|
441
|
-
end
|
442
|
-
|
443
|
-
aliases.first
|
444
|
-
end
|
445
|
-
end
|
446
|
-
|
447
|
-
# Returns the standard offset for this timezone.
|
448
|
-
#
|
449
|
-
# @param rational [Boolean] If to return the offset as a Rational.
|
450
|
-
# @return [Fixnum|Rational] The offset of this timezone.
|
451
|
-
def offset(rational = false)
|
452
|
-
rational ? self.class.rationalize_offset(utc_offset) : utc_offset
|
453
|
-
end
|
454
|
-
|
455
|
-
# Gets a period for this timezone when the Daylight Saving Time (DST) is active (it takes care of different hemispheres).
|
456
|
-
#
|
457
|
-
# @param year [Fixnum] The year to which refer to. Defaults to the current year.
|
458
|
-
# @return [TimezonePeriod] A period when the Daylight Saving Time (DST) is active or `nil` if the timezone doesn't use DST for that year.
|
459
|
-
def dst_period(year = nil)
|
460
|
-
year ||= ::Date.today.year
|
461
|
-
|
462
|
-
northern_summer = ::DateTime.civil(year, 7, 15).utc # This is a representation of a summer period in the Northern Hemisphere.
|
463
|
-
southern_summer = ::DateTime.civil(year, 1, 15).utc # This is a representation of a summer period in the Southern Hemisphere.
|
464
|
-
|
465
|
-
period = period_for_utc(northern_summer)
|
466
|
-
period = period_for_utc(southern_summer) unless period.dst?
|
467
|
-
period.dst? ? period : nil
|
468
|
-
end
|
469
|
-
|
470
|
-
# Checks if the timezone uses Daylight Saving Time (DST) for that date or year.
|
471
|
-
#
|
472
|
-
# @param reference [Object] The date or year to check. Defaults to the current year.
|
473
|
-
# @return [Boolean] `true` if the zone uses DST for that date or year, `false` otherwise.
|
474
|
-
def uses_dst?(reference = nil)
|
475
|
-
if reference.respond_to?(:year) && reference.respond_to?(:utc) # This is a date like object
|
476
|
-
dst_period(reference.year).present? && period_for_utc(reference.utc).dst?
|
477
|
-
else
|
478
|
-
dst_period(reference).present?
|
479
|
-
end
|
480
|
-
end
|
481
|
-
|
482
|
-
# Return the correction applied to the standard offset the timezone when the Daylight Saving Time (DST) is active.
|
483
|
-
#
|
484
|
-
# @param rational [Boolean] If to return the offset as a Rational.
|
485
|
-
# @param year [Fixnum] The year to which refer to. Defaults to the current year.
|
486
|
-
# @return [Fixnum|Rational] The correction for dst.
|
487
|
-
def dst_correction(rational = false, year = nil)
|
488
|
-
dst_offset(rational, year, :std_offset)
|
489
|
-
end
|
490
|
-
|
491
|
-
# Returns the standard offset for this timezone timezone when the Daylight Saving Time (DST) is active.
|
492
|
-
#
|
493
|
-
# @param rational [Boolean] If to return the offset as a Rational.
|
494
|
-
# @param year [Fixnum] The year to which refer to. Defaults to the current year.
|
495
|
-
# @param method [Symbol] The method to use for getting the offset. Default is total offset from UTC.
|
496
|
-
# @return [Fixnum|Rational] The DST offset for this timezone or `0`, if the timezone doesn't use DST for that year.
|
497
|
-
def dst_offset(rational = false, year = nil, method = :utc_total_offset)
|
498
|
-
period = dst_period(year)
|
499
|
-
rv = period ? period.send(method) : 0
|
500
|
-
rational ? self.class.rationalize_offset(rv) : rv
|
501
|
-
end
|
502
|
-
|
503
|
-
# Returns the name for this zone with Daylight Saving Time (DST) active.
|
504
|
-
#
|
505
|
-
# @param dst_label [String] Label for the DST indication. Defaults to `(DST)`.
|
506
|
-
# @param year [Fixnum] The year to which refer to. Defaults to the current year.
|
507
|
-
# @param name [String] The name to use for this zone. Defaults to the zone name.
|
508
|
-
# @return [String] The name for the zone with DST or `nil`, if the timezone doesn't use DST for that year.
|
509
|
-
def dst_name(dst_label = nil, year = nil, name = nil)
|
510
|
-
uses_dst?(year) ? "#{name || self.name} #{dst_label || "(DST)"}" : nil
|
511
|
-
end
|
512
|
-
|
513
|
-
# Returns the name for this zone with Daylight Saving Time (DST) active.
|
514
|
-
#
|
515
|
-
# @param name [String] The name to use for this zone. Defaults to the zone name.
|
516
|
-
# @param colon [Boolean] If to put the colon in the output string.
|
517
|
-
# @return [String] The name for this zone.
|
518
|
-
def to_str(name = nil, colon = true)
|
519
|
-
"(GMT#{formatted_offset(colon)}) #{name || current_alias}"
|
520
|
-
end
|
521
|
-
|
522
|
-
# Returns a string representation for this zone with Daylight Saving Time (DST) active.
|
523
|
-
#
|
524
|
-
# @param dst_label [String] Label for the DST indication. Defaults to `(DST)`.
|
525
|
-
# @param year [Fixnum] The year to which refer to. Defaults to the current year.
|
526
|
-
# @param name [String] The name to use for this zone. Defaults to the zone name.
|
527
|
-
# @return [String] The string representation for the zone with DST or `nil`, if the timezone doesn't use DST for that year.
|
528
|
-
def to_str_with_dst(dst_label = nil, year = nil, name = nil)
|
529
|
-
uses_dst?(year) ? "(GMT#{self.class.seconds_to_utc_offset(dst_period(year).utc_total_offset)}) #{name || current_alias} #{dst_label || "(DST)"}" : nil
|
530
|
-
end
|
531
|
-
|
532
|
-
# Returns a parameterized string representation for this zone.
|
533
|
-
#
|
534
|
-
# @param with_offset [Boolean] If to include offset into the representation.
|
535
|
-
# @param name [String] The name to use for this zone. Defaults to the zone name.
|
536
|
-
# @return [String] The parameterized string representation for this zone.
|
537
|
-
def to_str_parameterized(with_offset = true, name = nil)
|
538
|
-
::ActiveSupport::TimeZone.parameterize_zone(name || to_str, with_offset)
|
539
|
-
end
|
540
|
-
|
541
|
-
# Returns a parameterized string representation for this zone with Daylight Saving Time (DST) active.
|
542
|
-
#
|
543
|
-
# @param dst_label [String] Label for the DST indication. Defaults to `(DST)`.
|
544
|
-
# @param year [Fixnum] The year to which refer to. Defaults to the current year.
|
545
|
-
# @param name [String] The name to use for this zone. Defaults to the zone name.
|
546
|
-
# @return [String] The parameterized string representation for this zone with DST or `nil`, if the timezone doesn't use DST for that year.
|
547
|
-
def to_str_with_dst_parameterized(dst_label = nil, year = nil, name = nil)
|
548
|
-
rv = to_str_with_dst(dst_label, year, name)
|
549
|
-
rv ? ::ActiveSupport::TimeZone.parameterize_zone(rv) : nil
|
550
|
-
end
|
551
|
-
|
552
|
-
private
|
553
|
-
|
554
|
-
# Formats a time zone alias.
|
555
|
-
#
|
556
|
-
# @param name [String] The zone name.
|
557
|
-
# @param zone [String] The zone.
|
558
|
-
# @param reference [String] The main name for the zone.
|
559
|
-
# @return [String|nil] The formatted alias.
|
560
|
-
def format_alias(name, zone, reference)
|
561
|
-
if zone.gsub("_", " ") == reference
|
562
|
-
["International Date Line West", "UTC"].include?(name) || name.include?("(US & Canada)") ? name : reference.gsub(/\/.*/, "/#{name}")
|
563
|
-
else
|
564
|
-
nil
|
565
|
-
end
|
566
|
-
end
|
567
|
-
end
|
568
276
|
end
|