time_with_zone 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -1
- data/README.md +2 -2
- data/docs/TimeWithZone.html +162 -134
- data/docs/_index.html +1 -1
- data/docs/file.LICENSE.html +1 -1
- data/docs/file.README.html +9 -4
- data/docs/index.html +9 -4
- data/docs/method_list.html +3 -3
- data/docs/top-level-namespace.html +1 -1
- data/lib/time_with_zone.rb +29 -10
- data/lib/time_with_zone/version.rb +1 -1
- data/time_with_zone.gemspec +2 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c7e50a190b197838effa435df09432a17e377b34
|
4
|
+
data.tar.gz: 0761e3c5c2314d738328d3605dfc16896a1b01e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d5cef7cfc7e529e25a3bcffa0bcf0c3a579e698bd54991fc4bf6a1853c17bb8b0c32b69686a8e85f00accd98a3ca493da8c64415c84ee88bf0b977e390c1cf0
|
7
|
+
data.tar.gz: 38c96fca1e1d4b3a8577f9291689e2a677158404069ececd03276db2ea8b0c755a81c6a81cc85375ba09a05017a149b99a8e3ab9900039369e285064d2e49bdf
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# TimeWithZone
|
2
2
|
|
3
|
-
Handle
|
3
|
+
Handle time with zone without ActiveSupport or `ENV['TZ']` for thread-safety.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -20,7 +20,7 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
-
See [docs](https://sonots.github.io/time_with_zone/
|
23
|
+
See [docs](https://sonots.github.io/time_with_zone/TimeWithZone.html)
|
24
24
|
|
25
25
|
## Development
|
26
26
|
|
data/docs/TimeWithZone.html
CHANGED
@@ -101,7 +101,35 @@
|
|
101
101
|
</dl>
|
102
102
|
<div class="clear"></div>
|
103
103
|
|
104
|
+
<h2>Overview</h2><div class="docstring">
|
105
|
+
<div class="discussion">
|
106
|
+
|
107
|
+
<p>Handle time with zone withtout ActiveSupport or <a href="'TZ'\">ENV</a></p>
|
108
|
+
|
109
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>time_with_zone</span><span class='tstring_end'>'</span></span>
|
110
|
+
|
111
|
+
<span class='const'>TimeWithZone</span><span class='period'>.</span><span class='id identifier rubyid_strptime_with_zone'>strptime_with_zone</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>2016-10-10</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>%Y-%m-%d</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Asia/Taipei</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
112
|
+
<span class='comment'># => '2016-10-10 00:00:00 +0800'
|
113
|
+
</span>
|
114
|
+
<span class='const'>TimeWithZone</span><span class='period'>.</span><span class='id identifier rubyid_parse_with_zone'>parse_with_zone</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>2016-10-10</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Asia/Taipei</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
115
|
+
<span class='comment'># => '2016-10-10 00:00:00 +0800'
|
116
|
+
</span>
|
117
|
+
<span class='id identifier rubyid_time'>time</span> <span class='op'>=</span> <span class='const'>Time</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>2016-10-10 00:00:00 +00:00</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
118
|
+
<span class='const'>TimeWithZone</span><span class='period'>.</span><span class='id identifier rubyid_set_zone!'>set_zone!</span><span class='lparen'>(</span><span class='id identifier rubyid_time'>time</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Asia/Taipei</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
119
|
+
<span class='comment'># => '2016-10-10 00:00:00 +0800'
|
120
|
+
</span>
|
121
|
+
<span class='id identifier rubyid_time'>time</span> <span class='op'>=</span> <span class='const'>Time</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>2016-10-10 00:00:00 +00:00</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
122
|
+
<span class='const'>TimeWithZone</span><span class='period'>.</span><span class='id identifier rubyid_localtime_with_zone'>localtime_with_zone</span><span class='lparen'>(</span><span class='id identifier rubyid_time'>time</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Asia/Taipei</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
123
|
+
<span class='comment'># => '2016-10-10 08:00:00 +0800'
|
124
|
+
</span></code></pre>
|
125
|
+
|
104
126
|
|
127
|
+
</div>
|
128
|
+
</div>
|
129
|
+
<div class="tags">
|
130
|
+
|
131
|
+
|
132
|
+
</div>
|
105
133
|
<h2>Constant Summary</h2>
|
106
134
|
|
107
135
|
<dl class="constants">
|
@@ -234,7 +262,7 @@
|
|
234
262
|
<li class="public ">
|
235
263
|
<span class="summary_signature">
|
236
264
|
|
237
|
-
<a href="#
|
265
|
+
<a href="#parse_with_zone-class_method" title="parse_with_zone (class method)">+ (Object) <strong>parse_with_zone</strong>(date, timezone) </a>
|
238
266
|
|
239
267
|
|
240
268
|
|
@@ -249,8 +277,7 @@
|
|
249
277
|
|
250
278
|
|
251
279
|
<span class="summary_desc"><div class='inline'>
|
252
|
-
<p>
|
253
|
-
(non-destructive).</p>
|
280
|
+
<p>Time.parse with timezone.</p>
|
254
281
|
</div></span>
|
255
282
|
|
256
283
|
</li>
|
@@ -259,7 +286,7 @@
|
|
259
286
|
<li class="public ">
|
260
287
|
<span class="summary_signature">
|
261
288
|
|
262
|
-
<a href="#
|
289
|
+
<a href="#set_zone-class_method" title="set_zone (class method)">+ (Time) <strong>set_zone</strong>(time, timezone) </a>
|
263
290
|
|
264
291
|
|
265
292
|
|
@@ -274,7 +301,7 @@
|
|
274
301
|
|
275
302
|
|
276
303
|
<span class="summary_desc"><div class='inline'>
|
277
|
-
<p>This method simply
|
304
|
+
<p>This method simply sets the zone field of Time object (non-destructive).</p>
|
278
305
|
</div></span>
|
279
306
|
|
280
307
|
</li>
|
@@ -283,7 +310,7 @@
|
|
283
310
|
<li class="public ">
|
284
311
|
<span class="summary_signature">
|
285
312
|
|
286
|
-
<a href="#
|
313
|
+
<a href="#set_zone%21-class_method" title="set_zone! (class method)">+ (Object) <strong>set_zone!</strong>(time, timezone) </a>
|
287
314
|
|
288
315
|
|
289
316
|
|
@@ -298,7 +325,7 @@
|
|
298
325
|
|
299
326
|
|
300
327
|
<span class="summary_desc"><div class='inline'>
|
301
|
-
<p>Time
|
328
|
+
<p>This method simply sets the zone field of Time object (destructive).</p>
|
302
329
|
</div></span>
|
303
330
|
|
304
331
|
</li>
|
@@ -457,12 +484,12 @@
|
|
457
484
|
<pre class="lines">
|
458
485
|
|
459
486
|
|
460
|
-
|
461
|
-
|
462
|
-
|
487
|
+
61
|
488
|
+
62
|
489
|
+
63</pre>
|
463
490
|
</td>
|
464
491
|
<td>
|
465
|
-
<pre class="code"><span class="info file"># File 'lib/time_with_zone.rb', line
|
492
|
+
<pre class="code"><span class="info file"># File 'lib/time_with_zone.rb', line 61</span>
|
466
493
|
|
467
494
|
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_localtime_with_zone'>localtime_with_zone</span><span class='lparen'>(</span><span class='id identifier rubyid_time'>time</span><span class='comma'>,</span> <span class='id identifier rubyid_timezone'>timezone</span><span class='rparen'>)</span>
|
468
495
|
<span class='id identifier rubyid_localtime_with_zone!'>localtime_with_zone!</span><span class='lparen'>(</span><span class='id identifier rubyid_time'>time</span><span class='period'>.</span><span class='id identifier rubyid_dup'>dup</span><span class='comma'>,</span> <span class='id identifier rubyid_timezone'>timezone</span><span class='rparen'>)</span>
|
@@ -541,13 +568,13 @@
|
|
541
568
|
<pre class="lines">
|
542
569
|
|
543
570
|
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
571
|
+
70
|
572
|
+
71
|
573
|
+
72
|
574
|
+
73</pre>
|
548
575
|
</td>
|
549
576
|
<td>
|
550
|
-
<pre class="code"><span class="info file"># File 'lib/time_with_zone.rb', line
|
577
|
+
<pre class="code"><span class="info file"># File 'lib/time_with_zone.rb', line 70</span>
|
551
578
|
|
552
579
|
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_localtime_with_zone!'>localtime_with_zone!</span><span class='lparen'>(</span><span class='id identifier rubyid_time'>time</span><span class='comma'>,</span> <span class='id identifier rubyid_timezone'>timezone</span><span class='rparen'>)</span>
|
553
580
|
<span class='id identifier rubyid__zone_offset'>_zone_offset</span> <span class='op'>=</span> <span class='id identifier rubyid_zone_offset'>zone_offset</span><span class='lparen'>(</span><span class='id identifier rubyid_timezone'>timezone</span><span class='comma'>,</span> <span class='id identifier rubyid_time'>time</span><span class='rparen'>)</span>
|
@@ -559,9 +586,9 @@
|
|
559
586
|
</div>
|
560
587
|
|
561
588
|
<div class="method_details ">
|
562
|
-
<h3 class="signature " id="
|
589
|
+
<h3 class="signature " id="parse_with_zone-class_method">
|
563
590
|
|
564
|
-
+ (<tt>
|
591
|
+
+ (<tt>Object</tt>) <strong>parse_with_zone</strong>(date, timezone)
|
565
592
|
|
566
593
|
|
567
594
|
|
@@ -570,13 +597,29 @@
|
|
570
597
|
</h3><div class="docstring">
|
571
598
|
<div class="discussion">
|
572
599
|
|
573
|
-
<p>
|
574
|
-
(non-destructive)</p>
|
600
|
+
<p>Time.parse with timezone</p>
|
575
601
|
|
576
|
-
<pre class="code ruby"><code class="ruby"><span class='
|
602
|
+
<pre class="code ruby"><code class="ruby"><span class='const'>ENV</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>TZ</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>+09:00</span><span class='tstring_end'>'</span></span> <span class='comment'># Assume your local timezone is +09:00
|
603
|
+
</span>
|
604
|
+
<span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>time</span><span class='tstring_end'>'</span></span>
|
605
|
+
|
606
|
+
<span class='const'>Time</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>2016-10-20</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
607
|
+
<span class='comment'>#=> 2016-10-20 00:00:00 +0900
|
608
|
+
</span><span class='const'>Time</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>2016-10-20 00:00:00 +08:00</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
609
|
+
<span class='comment'>#=> 2016-10-20 00:00:00 +0800
|
610
|
+
</span><span class='const'>Time</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>2016-10-20 00:00:00 CDT</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
611
|
+
<span class='comment'>#=> 2016-10-20 00:00:00 -0500
|
612
|
+
</span><span class='const'>Time</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>2016-10-20 00:00:00 Asia/Taipei</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
613
|
+
<span class='comment'>#=> 2016-10-20 00:00:00 +0900 (does not work)
|
614
|
+
</span>
|
615
|
+
<span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>time_with_zone</span><span class='tstring_end'>'</span></span>
|
577
616
|
|
578
|
-
<span class='const'>TimeWithZone</span><span class='period'>.</span><span class='id identifier
|
579
|
-
<span class='comment'>#=>
|
617
|
+
<span class='const'>TimeWithZone</span><span class='period'>.</span><span class='id identifier rubyid_parse_with_zone'>parse_with_zone</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>2016-10-20</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>+08:00</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
618
|
+
<span class='comment'>#=> 2016-10-20 00:00:00 +0800
|
619
|
+
</span><span class='const'>TimeWithZone</span><span class='period'>.</span><span class='id identifier rubyid_parse_with_zone'>parse_with_zone</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>2016-10-20</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>CDT</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
620
|
+
<span class='comment'>#=> 2016-10-20 00:00:00 -0500
|
621
|
+
</span><span class='const'>TimeWithZone</span><span class='period'>.</span><span class='id identifier rubyid_parse_with_zone'>parse_with_zone</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>2016-10-20</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Asia/Taipei</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
622
|
+
<span class='comment'>#=> 2016-10-20 00:00:00 +0800
|
580
623
|
</span></code></pre>
|
581
624
|
|
582
625
|
|
@@ -588,13 +631,18 @@
|
|
588
631
|
|
589
632
|
<li>
|
590
633
|
|
591
|
-
<span class='name'>
|
634
|
+
<span class='name'>date</span>
|
592
635
|
|
593
636
|
|
594
|
-
<span class='type'>(<tt>
|
637
|
+
<span class='type'>(<tt>String</tt>)</span>
|
595
638
|
|
596
639
|
|
597
640
|
|
641
|
+
—
|
642
|
+
<div class='inline'>
|
643
|
+
<p>string to be parsed</p>
|
644
|
+
</div>
|
645
|
+
|
598
646
|
</li>
|
599
647
|
|
600
648
|
<li>
|
@@ -606,39 +654,33 @@
|
|
606
654
|
|
607
655
|
|
608
656
|
|
609
|
-
|
610
|
-
|
611
|
-
</
|
612
|
-
|
613
|
-
<p class="tag_title">Returns:</p>
|
614
|
-
<ul class="return">
|
615
|
-
|
616
|
-
<li>
|
617
|
-
|
618
|
-
|
619
|
-
<span class='type'>(<tt>Time</tt>)</span>
|
620
|
-
|
621
|
-
|
657
|
+
—
|
658
|
+
<div class='inline'>
|
659
|
+
<p><span class='object_link'><a href="#NUMERIC_PATTERN-constant" title="TimeWithZone::NUMERIC_PATTERN (constant)">NUMERIC_PATTERN</a></span> or <span class='object_link'><a href="#NAME_PATTERN-constant" title="TimeWithZone::NAME_PATTERN (constant)">NAME_PATTERN</a></span> or <span class='object_link'><a href="#ZoneOffset-constant" title="TimeWithZone::ZoneOffset (constant)">ZoneOffset</a></span></p>
|
660
|
+
</div>
|
622
661
|
|
623
662
|
</li>
|
624
663
|
|
625
664
|
</ul>
|
626
665
|
|
666
|
+
|
627
667
|
</div><table class="source_code">
|
628
668
|
<tr>
|
629
669
|
<td>
|
630
670
|
<pre class="lines">
|
631
671
|
|
632
672
|
|
633
|
-
|
634
|
-
|
635
|
-
|
673
|
+
101
|
674
|
+
102
|
675
|
+
103
|
676
|
+
104</pre>
|
636
677
|
</td>
|
637
678
|
<td>
|
638
|
-
<pre class="code"><span class="info file"># File 'lib/time_with_zone.rb', line
|
679
|
+
<pre class="code"><span class="info file"># File 'lib/time_with_zone.rb', line 101</span>
|
639
680
|
|
640
|
-
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier
|
641
|
-
<span class='id identifier
|
681
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_parse_with_zone'>parse_with_zone</span><span class='lparen'>(</span><span class='id identifier rubyid_date'>date</span><span class='comma'>,</span> <span class='id identifier rubyid_timezone'>timezone</span><span class='rparen'>)</span>
|
682
|
+
<span class='id identifier rubyid_time'>time</span> <span class='op'>=</span> <span class='const'>Time</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='id identifier rubyid_date'>date</span><span class='rparen'>)</span>
|
683
|
+
<span class='id identifier rubyid_set_zone!'>set_zone!</span><span class='lparen'>(</span><span class='id identifier rubyid_time'>time</span><span class='comma'>,</span> <span class='id identifier rubyid_timezone'>timezone</span><span class='rparen'>)</span>
|
642
684
|
<span class='kw'>end</span></pre>
|
643
685
|
</td>
|
644
686
|
</tr>
|
@@ -646,9 +688,9 @@
|
|
646
688
|
</div>
|
647
689
|
|
648
690
|
<div class="method_details ">
|
649
|
-
<h3 class="signature " id="
|
691
|
+
<h3 class="signature " id="set_zone-class_method">
|
650
692
|
|
651
|
-
+ (<tt>
|
693
|
+
+ (<tt>Time</tt>) <strong>set_zone</strong>(time, timezone)
|
652
694
|
|
653
695
|
|
654
696
|
|
@@ -657,7 +699,15 @@
|
|
657
699
|
</h3><div class="docstring">
|
658
700
|
<div class="discussion">
|
659
701
|
|
660
|
-
<p>This method simply
|
702
|
+
<p>This method simply sets the zone field of Time object (non-destructive)</p>
|
703
|
+
|
704
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>time_with_zone</span><span class='tstring_end'>'</span></span>
|
705
|
+
|
706
|
+
<span class='id identifier rubyid_time'>time</span> <span class='op'>=</span> <span class='const'>Time</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>2016-02-02 00:00:00 +00:00</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
707
|
+
<span class='const'>TimeWithZone</span><span class='period'>.</span><span class='id identifier rubyid_set_zone'>set_zone</span><span class='lparen'>(</span><span class='id identifier rubyid_time'>time</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>+08:00</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
708
|
+
<span class='comment'>#=> "2016-02-02 00:00:00 +0800"
|
709
|
+
</span><span class='comment'># Note that it is not "2016-02-02 08:00:00 +0800" like Time#localtime(timezone)
|
710
|
+
</span></code></pre>
|
661
711
|
|
662
712
|
|
663
713
|
</div>
|
@@ -690,13 +740,19 @@
|
|
690
740
|
|
691
741
|
</ul>
|
692
742
|
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
743
|
+
<p class="tag_title">Returns:</p>
|
744
|
+
<ul class="return">
|
745
|
+
|
746
|
+
<li>
|
747
|
+
|
748
|
+
|
749
|
+
<span class='type'>(<tt>Time</tt>)</span>
|
750
|
+
|
751
|
+
|
752
|
+
|
753
|
+
</li>
|
754
|
+
|
755
|
+
</ul>
|
700
756
|
|
701
757
|
</div><table class="source_code">
|
702
758
|
<tr>
|
@@ -704,19 +760,15 @@
|
|
704
760
|
<pre class="lines">
|
705
761
|
|
706
762
|
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
143
|
711
|
-
144</pre>
|
763
|
+
150
|
764
|
+
151
|
765
|
+
152</pre>
|
712
766
|
</td>
|
713
767
|
<td>
|
714
|
-
<pre class="code"><span class="info file"># File 'lib/time_with_zone.rb', line
|
768
|
+
<pre class="code"><span class="info file"># File 'lib/time_with_zone.rb', line 150</span>
|
715
769
|
|
716
|
-
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier
|
717
|
-
<span class='id identifier
|
718
|
-
<span class='id identifier rubyid__zone_offset'>_zone_offset</span> <span class='op'>=</span> <span class='id identifier rubyid_zone_offset'>zone_offset</span><span class='lparen'>(</span><span class='id identifier rubyid_timezone'>timezone</span><span class='comma'>,</span> <span class='id identifier rubyid_time'>time</span><span class='rparen'>)</span>
|
719
|
-
<span class='id identifier rubyid_time'>time</span><span class='period'>.</span><span class='id identifier rubyid_localtime'>localtime</span><span class='lparen'>(</span><span class='id identifier rubyid__zone_offset'>_zone_offset</span><span class='rparen'>)</span> <span class='op'>+</span> <span class='id identifier rubyid__utc_offset'>_utc_offset</span> <span class='op'>-</span> <span class='id identifier rubyid__zone_offset'>_zone_offset</span>
|
770
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_set_zone'>set_zone</span><span class='lparen'>(</span><span class='id identifier rubyid_time'>time</span><span class='comma'>,</span> <span class='id identifier rubyid_timezone'>timezone</span><span class='rparen'>)</span>
|
771
|
+
<span class='id identifier rubyid_set_zone!'>set_zone!</span><span class='lparen'>(</span><span class='id identifier rubyid_time'>time</span><span class='period'>.</span><span class='id identifier rubyid_dup'>dup</span><span class='comma'>,</span> <span class='id identifier rubyid_timezone'>timezone</span><span class='rparen'>)</span>
|
720
772
|
<span class='kw'>end</span></pre>
|
721
773
|
</td>
|
722
774
|
</tr>
|
@@ -724,9 +776,9 @@
|
|
724
776
|
</div>
|
725
777
|
|
726
778
|
<div class="method_details ">
|
727
|
-
<h3 class="signature " id="
|
779
|
+
<h3 class="signature " id="set_zone!-class_method">
|
728
780
|
|
729
|
-
+ (<tt>Object</tt>) <strong>
|
781
|
+
+ (<tt>Object</tt>) <strong>set_zone!</strong>(time, timezone)
|
730
782
|
|
731
783
|
|
732
784
|
|
@@ -735,30 +787,7 @@
|
|
735
787
|
</h3><div class="docstring">
|
736
788
|
<div class="discussion">
|
737
789
|
|
738
|
-
<p>Time
|
739
|
-
|
740
|
-
<pre class="code ruby"><code class="ruby"><span class='const'>ENV</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>TZ</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>+09:00</span><span class='tstring_end'>'</span></span> <span class='comment'># Assume your local timezone is +09:00
|
741
|
-
</span>
|
742
|
-
<span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>time</span><span class='tstring_end'>'</span></span>
|
743
|
-
|
744
|
-
<span class='const'>Time</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>2016-10-20</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
745
|
-
<span class='comment'>#=> 2016-10-20 00:00:00 +0900
|
746
|
-
</span><span class='const'>Time</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>2016-10-20 00:00:00 +08:00</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
747
|
-
<span class='comment'>#=> 2016-10-20 00:00:00 +0800
|
748
|
-
</span><span class='const'>Time</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>2016-10-20 00:00:00 CDT</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
749
|
-
<span class='comment'>#=> 2016-10-20 00:00:00 -0500
|
750
|
-
</span><span class='const'>Time</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>2016-10-20 00:00:00 Asia/Taipei</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
751
|
-
<span class='comment'>#=> 2016-10-20 00:00:00 +0900 (does not work)
|
752
|
-
</span>
|
753
|
-
<span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>time_with_zone</span><span class='tstring_end'>'</span></span>
|
754
|
-
|
755
|
-
<span class='const'>TimeWithZone</span><span class='period'>.</span><span class='id identifier rubyid_parse_with_zone'>parse_with_zone</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>2016-10-20</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>+08:00</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
756
|
-
<span class='comment'>#=> 2016-10-20 00:00:00 +0800
|
757
|
-
</span><span class='const'>TimeWithZone</span><span class='period'>.</span><span class='id identifier rubyid_parse_with_zone'>parse_with_zone</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>2016-10-20</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>CDT</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
758
|
-
<span class='comment'>#=> 2016-10-20 00:00:00 -0500
|
759
|
-
</span><span class='const'>TimeWithZone</span><span class='period'>.</span><span class='id identifier rubyid_parse_with_zone'>parse_with_zone</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>2016-10-20</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Asia/Taipei</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
760
|
-
<span class='comment'>#=> 2016-10-20 00:00:00 +0800
|
761
|
-
</span></code></pre>
|
790
|
+
<p>This method simply sets the zone field of Time object (destructive)</p>
|
762
791
|
|
763
792
|
|
764
793
|
</div>
|
@@ -769,18 +798,13 @@
|
|
769
798
|
|
770
799
|
<li>
|
771
800
|
|
772
|
-
<span class='name'>
|
801
|
+
<span class='name'>time</span>
|
773
802
|
|
774
803
|
|
775
|
-
<span class='type'>(<tt>
|
804
|
+
<span class='type'>(<tt>Time</tt>)</span>
|
776
805
|
|
777
806
|
|
778
807
|
|
779
|
-
—
|
780
|
-
<div class='inline'>
|
781
|
-
<p>string to be parsed</p>
|
782
|
-
</div>
|
783
|
-
|
784
808
|
</li>
|
785
809
|
|
786
810
|
<li>
|
@@ -792,33 +816,37 @@
|
|
792
816
|
|
793
817
|
|
794
818
|
|
795
|
-
—
|
796
|
-
<div class='inline'>
|
797
|
-
<p><span class='object_link'><a href="#NUMERIC_PATTERN-constant" title="TimeWithZone::NUMERIC_PATTERN (constant)">NUMERIC_PATTERN</a></span> or <span class='object_link'><a href="#NAME_PATTERN-constant" title="TimeWithZone::NAME_PATTERN (constant)">NAME_PATTERN</a></span> or <span class='object_link'><a href="#ZoneOffset-constant" title="TimeWithZone::ZoneOffset (constant)">ZoneOffset</a></span></p>
|
798
|
-
</div>
|
799
|
-
|
800
819
|
</li>
|
801
820
|
|
802
821
|
</ul>
|
803
822
|
|
804
823
|
|
824
|
+
<p class="tag_title">See Also:</p>
|
825
|
+
<ul class="see">
|
826
|
+
|
827
|
+
<li><span class='object_link'><a href="#set_zone-class_method" title="TimeWithZone.set_zone (method)">set_zone</a></span></li>
|
828
|
+
|
829
|
+
</ul>
|
830
|
+
|
805
831
|
</div><table class="source_code">
|
806
832
|
<tr>
|
807
833
|
<td>
|
808
834
|
<pre class="lines">
|
809
835
|
|
810
836
|
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
837
|
+
159
|
838
|
+
160
|
839
|
+
161
|
840
|
+
162
|
841
|
+
163</pre>
|
815
842
|
</td>
|
816
843
|
<td>
|
817
|
-
<pre class="code"><span class="info file"># File 'lib/time_with_zone.rb', line
|
844
|
+
<pre class="code"><span class="info file"># File 'lib/time_with_zone.rb', line 159</span>
|
818
845
|
|
819
|
-
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier
|
820
|
-
<span class='id identifier
|
821
|
-
<span class='id identifier
|
846
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_set_zone!'>set_zone!</span><span class='lparen'>(</span><span class='id identifier rubyid_time'>time</span><span class='comma'>,</span> <span class='id identifier rubyid_timezone'>timezone</span><span class='rparen'>)</span>
|
847
|
+
<span class='id identifier rubyid__utc_offset'>_utc_offset</span> <span class='op'>=</span> <span class='id identifier rubyid_time'>time</span><span class='period'>.</span><span class='id identifier rubyid_utc_offset'>utc_offset</span>
|
848
|
+
<span class='id identifier rubyid__zone_offset'>_zone_offset</span> <span class='op'>=</span> <span class='id identifier rubyid_zone_offset'>zone_offset</span><span class='lparen'>(</span><span class='id identifier rubyid_timezone'>timezone</span><span class='comma'>,</span> <span class='id identifier rubyid_time'>time</span><span class='rparen'>)</span>
|
849
|
+
<span class='id identifier rubyid_time'>time</span><span class='period'>.</span><span class='id identifier rubyid_localtime'>localtime</span><span class='lparen'>(</span><span class='id identifier rubyid__zone_offset'>_zone_offset</span><span class='rparen'>)</span> <span class='op'>+</span> <span class='id identifier rubyid__utc_offset'>_utc_offset</span> <span class='op'>-</span> <span class='id identifier rubyid__zone_offset'>_zone_offset</span>
|
822
850
|
<span class='kw'>end</span></pre>
|
823
851
|
</td>
|
824
852
|
</tr>
|
@@ -921,17 +949,17 @@
|
|
921
949
|
<pre class="lines">
|
922
950
|
|
923
951
|
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
|
952
|
+
133
|
953
|
+
134
|
954
|
+
135
|
955
|
+
136</pre>
|
928
956
|
</td>
|
929
957
|
<td>
|
930
|
-
<pre class="code"><span class="info file"># File 'lib/time_with_zone.rb', line
|
958
|
+
<pre class="code"><span class="info file"># File 'lib/time_with_zone.rb', line 133</span>
|
931
959
|
|
932
960
|
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_strptime_with_zone'>strptime_with_zone</span><span class='lparen'>(</span><span class='id identifier rubyid_date'>date</span><span class='comma'>,</span> <span class='id identifier rubyid_format'>format</span><span class='comma'>,</span> <span class='id identifier rubyid_timezone'>timezone</span><span class='rparen'>)</span>
|
933
961
|
<span class='id identifier rubyid_time'>time</span> <span class='op'>=</span> <span class='const'>Time</span><span class='period'>.</span><span class='id identifier rubyid_strptime'>strptime</span><span class='lparen'>(</span><span class='id identifier rubyid_date'>date</span><span class='comma'>,</span> <span class='id identifier rubyid_format'>format</span><span class='rparen'>)</span>
|
934
|
-
<span class='id identifier
|
962
|
+
<span class='id identifier rubyid_set_zone!'>set_zone!</span><span class='lparen'>(</span><span class='id identifier rubyid_time'>time</span><span class='comma'>,</span> <span class='id identifier rubyid_timezone'>timezone</span><span class='rparen'>)</span>
|
935
963
|
<span class='kw'>end</span></pre>
|
936
964
|
</td>
|
937
965
|
</tr>
|
@@ -1036,25 +1064,25 @@
|
|
1036
1064
|
<pre class="lines">
|
1037
1065
|
|
1038
1066
|
|
1039
|
-
|
1040
|
-
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
1044
|
-
|
1045
|
-
|
1046
|
-
|
1047
|
-
|
1048
|
-
|
1049
|
-
|
1050
|
-
|
1051
|
-
|
1052
|
-
|
1053
|
-
|
1054
|
-
|
1067
|
+
185
|
1068
|
+
186
|
1069
|
+
187
|
1070
|
+
188
|
1071
|
+
189
|
1072
|
+
190
|
1073
|
+
191
|
1074
|
+
192
|
1075
|
+
193
|
1076
|
+
194
|
1077
|
+
195
|
1078
|
+
196
|
1079
|
+
197
|
1080
|
+
198
|
1081
|
+
199
|
1082
|
+
200</pre>
|
1055
1083
|
</td>
|
1056
1084
|
<td>
|
1057
|
-
<pre class="code"><span class="info file"># File 'lib/time_with_zone.rb', line
|
1085
|
+
<pre class="code"><span class="info file"># File 'lib/time_with_zone.rb', line 185</span>
|
1058
1086
|
|
1059
1087
|
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_zone_offset'>zone_offset</span><span class='lparen'>(</span><span class='id identifier rubyid_timezone'>timezone</span><span class='comma'>,</span> <span class='id identifier rubyid_time'>time</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span>
|
1060
1088
|
<span class='kw'>if</span> <span class='const'>NUMERIC_PATTERN</span> <span class='op'>===</span> <span class='id identifier rubyid_timezone'>timezone</span>
|
@@ -1082,7 +1110,7 @@
|
|
1082
1110
|
</div>
|
1083
1111
|
|
1084
1112
|
<div id="footer">
|
1085
|
-
Generated on
|
1113
|
+
Generated on Mon Oct 31 02:34:08 2016 by
|
1086
1114
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
1087
1115
|
0.8.7.6 (ruby-2.3.0).
|
1088
1116
|
</div>
|
data/docs/_index.html
CHANGED
@@ -104,7 +104,7 @@
|
|
104
104
|
</div>
|
105
105
|
|
106
106
|
<div id="footer">
|
107
|
-
Generated on
|
107
|
+
Generated on Mon Oct 31 02:34:08 2016 by
|
108
108
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
109
109
|
0.8.7.6 (ruby-2.3.0).
|
110
110
|
</div>
|
data/docs/file.LICENSE.html
CHANGED
@@ -64,7 +64,7 @@
|
|
64
64
|
<div id="content"><div id='filecontents'>The MIT License (MIT)<br/><br/>Copyright (c) 2016 Naotoshi Seo<br/><br/>Permission is hereby granted, free of charge, to any person obtaining a copy<br/>of this software and associated documentation files (the "Software"), to deal<br/>in the Software without restriction, including without limitation the rights<br/>to use, copy, modify, merge, publish, distribute, sublicense, and/or sell<br/>copies of the Software, and to permit persons to whom the Software is<br/>furnished to do so, subject to the following conditions:<br/><br/>The above copyright notice and this permission notice shall be included in<br/>all copies or substantial portions of the Software.<br/><br/>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br/>IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br/>FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE<br/>AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br/>LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,<br/>OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN<br/>THE SOFTWARE.</div></div>
|
65
65
|
|
66
66
|
<div id="footer">
|
67
|
-
Generated on
|
67
|
+
Generated on Mon Oct 31 02:34:08 2016 by
|
68
68
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
69
69
|
0.8.7.6 (ruby-2.3.0).
|
70
70
|
</div>
|
data/docs/file.README.html
CHANGED
@@ -64,8 +64,8 @@
|
|
64
64
|
<div id="content"><div id='filecontents'>
|
65
65
|
<h1 id="label-TimeWithZone">TimeWithZone</h1>
|
66
66
|
|
67
|
-
<p>Handle
|
68
|
-
|
67
|
+
<p>Handle time with zone without ActiveSupport or <code>ENV['TZ']</code> for
|
68
|
+
thread-safety.</p>
|
69
69
|
|
70
70
|
<h2 id="label-Installation">Installation</h2>
|
71
71
|
|
@@ -84,7 +84,8 @@ for thread-safety.</p>
|
|
84
84
|
|
85
85
|
<h2 id="label-Usage">Usage</h2>
|
86
86
|
|
87
|
-
<p>See <a
|
87
|
+
<p>See <a
|
88
|
+
href="https://sonots.github.io/time_with_zone/TimeWithZone.html">docs</a></p>
|
88
89
|
|
89
90
|
<h2 id="label-Development">Development</h2>
|
90
91
|
|
@@ -103,6 +104,10 @@ for thread-safety.</p>
|
|
103
104
|
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_bundle'>bundle</span> <span class='id identifier rubyid_exec'>exec</span> <span class='id identifier rubyid_rake'>rake</span> <span class='id identifier rubyid_release'>release</span>
|
104
105
|
</code></pre>
|
105
106
|
|
107
|
+
<h2 id="label-CHANGELOG">CHANGELOG</h2>
|
108
|
+
|
109
|
+
<p><a href="./CHANGELOG.md">CHANGELOG.md</a></p>
|
110
|
+
|
106
111
|
<h2 id="label-Contributing">Contributing</h2>
|
107
112
|
|
108
113
|
<p>Bug reports and pull requests are welcome on GitHub at <a
|
@@ -119,7 +124,7 @@ href="http://opensource.org/licenses/MIT">MIT License</a>.</p>
|
|
119
124
|
</div></div>
|
120
125
|
|
121
126
|
<div id="footer">
|
122
|
-
Generated on
|
127
|
+
Generated on Mon Oct 31 02:34:08 2016 by
|
123
128
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
124
129
|
0.8.7.6 (ruby-2.3.0).
|
125
130
|
</div>
|
data/docs/index.html
CHANGED
@@ -64,8 +64,8 @@
|
|
64
64
|
<div id="content"><div id='filecontents'>
|
65
65
|
<h1 id="label-TimeWithZone">TimeWithZone</h1>
|
66
66
|
|
67
|
-
<p>Handle
|
68
|
-
|
67
|
+
<p>Handle time with zone without ActiveSupport or <code>ENV['TZ']</code> for
|
68
|
+
thread-safety.</p>
|
69
69
|
|
70
70
|
<h2 id="label-Installation">Installation</h2>
|
71
71
|
|
@@ -84,7 +84,8 @@ for thread-safety.</p>
|
|
84
84
|
|
85
85
|
<h2 id="label-Usage">Usage</h2>
|
86
86
|
|
87
|
-
<p>See <a
|
87
|
+
<p>See <a
|
88
|
+
href="https://sonots.github.io/time_with_zone/TimeWithZone.html">docs</a></p>
|
88
89
|
|
89
90
|
<h2 id="label-Development">Development</h2>
|
90
91
|
|
@@ -103,6 +104,10 @@ for thread-safety.</p>
|
|
103
104
|
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_bundle'>bundle</span> <span class='id identifier rubyid_exec'>exec</span> <span class='id identifier rubyid_rake'>rake</span> <span class='id identifier rubyid_release'>release</span>
|
104
105
|
</code></pre>
|
105
106
|
|
107
|
+
<h2 id="label-CHANGELOG">CHANGELOG</h2>
|
108
|
+
|
109
|
+
<p><a href="./CHANGELOG.md">CHANGELOG.md</a></p>
|
110
|
+
|
106
111
|
<h2 id="label-Contributing">Contributing</h2>
|
107
112
|
|
108
113
|
<p>Bug reports and pull requests are welcome on GitHub at <a
|
@@ -119,7 +124,7 @@ href="http://opensource.org/licenses/MIT">MIT License</a>.</p>
|
|
119
124
|
</div></div>
|
120
125
|
|
121
126
|
<div id="footer">
|
122
|
-
Generated on
|
127
|
+
Generated on Mon Oct 31 02:34:08 2016 by
|
123
128
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
124
129
|
0.8.7.6 (ruby-2.3.0).
|
125
130
|
</div>
|
data/docs/method_list.html
CHANGED
@@ -64,19 +64,19 @@
|
|
64
64
|
|
65
65
|
|
66
66
|
<li class="r1 ">
|
67
|
-
<span class='object_link'><a href="TimeWithZone.html#
|
67
|
+
<span class='object_link'><a href="TimeWithZone.html#parse_with_zone-class_method" title="TimeWithZone.parse_with_zone (method)">parse_with_zone</a></span>
|
68
68
|
<small>TimeWithZone</small>
|
69
69
|
</li>
|
70
70
|
|
71
71
|
|
72
72
|
<li class="r2 ">
|
73
|
-
<span class='object_link'><a href="TimeWithZone.html#
|
73
|
+
<span class='object_link'><a href="TimeWithZone.html#set_zone-class_method" title="TimeWithZone.set_zone (method)">set_zone</a></span>
|
74
74
|
<small>TimeWithZone</small>
|
75
75
|
</li>
|
76
76
|
|
77
77
|
|
78
78
|
<li class="r1 ">
|
79
|
-
<span class='object_link'><a href="TimeWithZone.html#
|
79
|
+
<span class='object_link'><a href="TimeWithZone.html#set_zone%21-class_method" title="TimeWithZone.set_zone! (method)">set_zone!</a></span>
|
80
80
|
<small>TimeWithZone</small>
|
81
81
|
</li>
|
82
82
|
|
@@ -103,7 +103,7 @@
|
|
103
103
|
</div>
|
104
104
|
|
105
105
|
<div id="footer">
|
106
|
-
Generated on
|
106
|
+
Generated on Mon Oct 31 02:34:08 2016 by
|
107
107
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
108
108
|
0.8.7.6 (ruby-2.3.0).
|
109
109
|
</div>
|
data/lib/time_with_zone.rb
CHANGED
@@ -2,6 +2,23 @@ require_relative 'time_with_zone/version'
|
|
2
2
|
require 'time'
|
3
3
|
require 'tzinfo'
|
4
4
|
|
5
|
+
# Handle time with zone withtout ActiveSupport or ENV\['TZ'\]
|
6
|
+
#
|
7
|
+
# require 'time_with_zone'
|
8
|
+
#
|
9
|
+
# TimeWithZone.strptime_with_zone('2016-10-10', '%Y-%m-%d', 'Asia/Taipei')
|
10
|
+
# # => '2016-10-10 00:00:00 +0800'
|
11
|
+
#
|
12
|
+
# TimeWithZone.parse_with_zone('2016-10-10', 'Asia/Taipei')
|
13
|
+
# # => '2016-10-10 00:00:00 +0800'
|
14
|
+
#
|
15
|
+
# time = Time.parse('2016-10-10 00:00:00 +00:00')
|
16
|
+
# TimeWithZone.set_zone!(time, 'Asia/Taipei')
|
17
|
+
# # => '2016-10-10 00:00:00 +0800'
|
18
|
+
#
|
19
|
+
# time = Time.parse('2016-10-10 00:00:00 +00:00')
|
20
|
+
# TimeWithZone.localtime_with_zone(time, 'Asia/Taipei')
|
21
|
+
# # => '2016-10-10 08:00:00 +0800'
|
5
22
|
class TimeWithZone
|
6
23
|
# [+-]HH:MM, [+-]HHMM, [+-]HH
|
7
24
|
NUMERIC_PATTERN = %r{\A[+-]\d\d(:?\d\d)?\z}
|
@@ -83,7 +100,7 @@ class TimeWithZone
|
|
83
100
|
# @param [String] timezone {NUMERIC_PATTERN} or {NAME_PATTERN} or {ZoneOffset}
|
84
101
|
def self.parse_with_zone(date, timezone)
|
85
102
|
time = Time.parse(date)
|
86
|
-
|
103
|
+
set_zone!(time, timezone)
|
87
104
|
end
|
88
105
|
|
89
106
|
# Time.strptime with timezone
|
@@ -115,29 +132,31 @@ class TimeWithZone
|
|
115
132
|
# @param [String] timezone {NUMERIC_PATTERN} or {NAME_PATTERN} or {ZoneOffset}
|
116
133
|
def self.strptime_with_zone(date, format, timezone)
|
117
134
|
time = Time.strptime(date, format)
|
118
|
-
|
135
|
+
set_zone!(time, timezone)
|
119
136
|
end
|
120
137
|
|
121
|
-
# This method simply
|
138
|
+
# This method simply sets the zone field of Time object (non-destructive)
|
122
139
|
#
|
123
140
|
# require 'time_with_zone'
|
124
141
|
#
|
125
|
-
#
|
126
|
-
#
|
142
|
+
# time = Time.parse("2016-02-02 00:00:00 +00:00")
|
143
|
+
# TimeWithZone.set_zone(time, "+08:00")
|
144
|
+
# #=> "2016-02-02 00:00:00 +0800"
|
145
|
+
# # Note that it is not "2016-02-02 08:00:00 +0800" like Time#localtime(timezone)
|
127
146
|
#
|
128
147
|
# @param [Time] time
|
129
148
|
# @param [String] timezone
|
130
149
|
# @return [Time]
|
131
|
-
def self.
|
132
|
-
|
150
|
+
def self.set_zone(time, timezone)
|
151
|
+
set_zone!(time.dup, timezone)
|
133
152
|
end
|
134
153
|
|
135
|
-
# This method simply
|
154
|
+
# This method simply sets the zone field of Time object (destructive)
|
136
155
|
#
|
137
156
|
# @param [Time] time
|
138
157
|
# @param [String] timezone
|
139
|
-
# @see
|
140
|
-
def self.
|
158
|
+
# @see set_zone
|
159
|
+
def self.set_zone!(time, timezone)
|
141
160
|
_utc_offset = time.utc_offset
|
142
161
|
_zone_offset = zone_offset(timezone, time)
|
143
162
|
time.localtime(_zone_offset) + _utc_offset - _zone_offset
|
data/time_with_zone.gemspec
CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["sonots"]
|
10
10
|
spec.email = ["sonots@gmail.com"]
|
11
11
|
|
12
|
-
spec.summary = %q{Handle
|
13
|
-
spec.description = %q{Handle
|
12
|
+
spec.summary = %q{Handle time with zone withtout ActiveSupport or ENV['TZ']}
|
13
|
+
spec.description = %q{Handle time with zone withtout ActiveSupport or ENV['TZ']}
|
14
14
|
spec.homepage = "https://github.com/sonots/time_with_zone"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: time_with_zone
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sonots
|
@@ -52,7 +52,7 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '10.0'
|
55
|
-
description: Handle
|
55
|
+
description: Handle time with zone withtout ActiveSupport or ENV['TZ']
|
56
56
|
email:
|
57
57
|
- sonots@gmail.com
|
58
58
|
executables: []
|
@@ -113,6 +113,6 @@ rubyforge_project:
|
|
113
113
|
rubygems_version: 2.5.1
|
114
114
|
signing_key:
|
115
115
|
specification_version: 4
|
116
|
-
summary: Handle
|
116
|
+
summary: Handle time with zone withtout ActiveSupport or ENV['TZ']
|
117
117
|
test_files: []
|
118
118
|
has_rdoc:
|