time_with_zone 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c7e50a190b197838effa435df09432a17e377b34
4
- data.tar.gz: 0761e3c5c2314d738328d3605dfc16896a1b01e2
3
+ metadata.gz: fd91409d0be8be98807e79978b9f780b66378169
4
+ data.tar.gz: 5eff3854aff0288ed5c53468284015e1ade975c4
5
5
  SHA512:
6
- metadata.gz: 8d5cef7cfc7e529e25a3bcffa0bcf0c3a579e698bd54991fc4bf6a1853c17bb8b0c32b69686a8e85f00accd98a3ca493da8c64415c84ee88bf0b977e390c1cf0
7
- data.tar.gz: 38c96fca1e1d4b3a8577f9291689e2a677158404069ececd03276db2ea8b0c755a81c6a81cc85375ba09a05017a149b99a8e3ab9900039369e285064d2e49bdf
6
+ metadata.gz: 66304bd2be5721f7698854f4682de8b94aa54277562dd3f1a94494ca79deccf8e9888291ad7b5b708ca9ffe8c8592e6b5c720709b2bb2b592d91d1b8cb3e1ab7
7
+ data.tar.gz: 72a63b6d9fa9986f66d37787f6916b573a02d8d211ab2f6de41519d3a2441746cc1f6aeebe3fb6e9da4803ae1b8e71caa4ef5165492235e5e244780564bf969b
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # 0.2.1 (2016-10-31)
2
+
3
+ Enhancements:
4
+
5
+ * Add TimeWithZone.set_zone_offset
6
+
1
7
  # 0.2.0 (2016-10-31)
2
8
 
3
9
  Incompatibility changes:
@@ -192,7 +192,7 @@
192
192
  <dt id="VERSION-constant" class="">VERSION =
193
193
 
194
194
  </dt>
195
- <dd><pre class="code"><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>0.1.0</span><span class='tstring_end'>&quot;</span></span></pre></dd>
195
+ <dd><pre class="code"><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>0.2.0</span><span class='tstring_end'>&quot;</span></span></pre></dd>
196
196
 
197
197
  </dl>
198
198
 
@@ -409,9 +409,9 @@
409
409
  <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'>&quot;</span><span class='tstring_content'>2016-10-20 00:00:00 +00:00</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
410
410
  <span class='id identifier rubyid_time'>time</span><span class='period'>.</span><span class='id identifier rubyid_dup'>dup</span><span class='period'>.</span><span class='id identifier rubyid_localtime'>localtime</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>+08:00</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
411
411
  <span class='comment'>#=&gt; 2010-10-20 08:00:00 +0800
412
- </span><span class='id identifier rubyid_time'>time</span><span class='period'>.</span><span class='id identifier rubyid_dump'>dump</span><span class='period'>.</span><span class='id identifier rubyid_localtime'>localtime</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>CDT</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
412
+ </span><span class='id identifier rubyid_time'>time</span><span class='period'>.</span><span class='id identifier rubyid_dup'>dup</span><span class='period'>.</span><span class='id identifier rubyid_localtime'>localtime</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>CDT</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
413
413
  <span class='comment'>#=&gt; error
414
- </span><span class='id identifier rubyid_time'>time</span><span class='period'>.</span><span class='id identifier rubyid_dump'>dump</span><span class='period'>.</span><span class='id identifier rubyid_localtime'>localtime</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Asia/Taipei</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
414
+ </span><span class='id identifier rubyid_time'>time</span><span class='period'>.</span><span class='id identifier rubyid_dup'>dup</span><span class='period'>.</span><span class='id identifier rubyid_localtime'>localtime</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Asia/Taipei</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
415
415
  <span class='comment'>#=&gt; error
416
416
  </span>
417
417
  <span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>time_with_zone</span><span class='tstring_end'>&#39;</span></span>
@@ -425,6 +425,15 @@
425
425
  <span class='comment'>#=&gt; 2010-10-20 08:00:00 +0800
426
426
  </span></code></pre>
427
427
 
428
+ <p>This method is actually a short-hand of</p>
429
+
430
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>time_with_zone</span><span class='tstring_end'>&#39;</span></span>
431
+ <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'>&quot;</span><span class='tstring_content'>2016-10-20 00:00:00 +00:00</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
432
+
433
+ <span class='id identifier rubyid_time'>time</span><span class='period'>.</span><span class='id identifier rubyid_dup'>dup</span><span class='period'>.</span><span class='id identifier rubyid_localtime'>localtime</span><span class='lparen'>(</span><span class='const'>TimeWithZone</span><span class='period'>.</span><span class='id identifier rubyid_zone_offset'>zone_offset</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Asia/Taipei</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span><span class='rparen'>)</span>
434
+ <span class='comment'>#=&gt; 2010-10-20 08:00:00 +0800
435
+ </span></code></pre>
436
+
428
437
 
429
438
  </div>
430
439
  </div>
@@ -484,12 +493,12 @@
484
493
  <pre class="lines">
485
494
 
486
495
 
487
- 61
488
- 62
489
- 63</pre>
496
+ 69
497
+ 70
498
+ 71</pre>
490
499
  </td>
491
500
  <td>
492
- <pre class="code"><span class="info file"># File 'lib/time_with_zone.rb', line 61</span>
501
+ <pre class="code"><span class="info file"># File 'lib/time_with_zone.rb', line 69</span>
493
502
 
494
503
  <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>
495
504
  <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>
@@ -568,13 +577,13 @@
568
577
  <pre class="lines">
569
578
 
570
579
 
571
- 70
572
- 71
573
- 72
574
- 73</pre>
580
+ 78
581
+ 79
582
+ 80
583
+ 81</pre>
575
584
  </td>
576
585
  <td>
577
- <pre class="code"><span class="info file"># File 'lib/time_with_zone.rb', line 70</span>
586
+ <pre class="code"><span class="info file"># File 'lib/time_with_zone.rb', line 78</span>
578
587
 
579
588
  <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>
580
589
  <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>
@@ -670,13 +679,13 @@
670
679
  <pre class="lines">
671
680
 
672
681
 
673
- 101
674
- 102
675
- 103
676
- 104</pre>
682
+ 109
683
+ 110
684
+ 111
685
+ 112</pre>
677
686
  </td>
678
687
  <td>
679
- <pre class="code"><span class="info file"># File 'lib/time_with_zone.rb', line 101</span>
688
+ <pre class="code"><span class="info file"># File 'lib/time_with_zone.rb', line 109</span>
680
689
 
681
690
  <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
691
  <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>
@@ -760,12 +769,12 @@
760
769
  <pre class="lines">
761
770
 
762
771
 
763
- 150
764
- 151
765
- 152</pre>
772
+ 158
773
+ 159
774
+ 160</pre>
766
775
  </td>
767
776
  <td>
768
- <pre class="code"><span class="info file"># File 'lib/time_with_zone.rb', line 150</span>
777
+ <pre class="code"><span class="info file"># File 'lib/time_with_zone.rb', line 158</span>
769
778
 
770
779
  <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
780
  <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>
@@ -834,14 +843,14 @@
834
843
  <pre class="lines">
835
844
 
836
845
 
837
- 159
838
- 160
839
- 161
840
- 162
841
- 163</pre>
846
+ 167
847
+ 168
848
+ 169
849
+ 170
850
+ 171</pre>
842
851
  </td>
843
852
  <td>
844
- <pre class="code"><span class="info file"># File 'lib/time_with_zone.rb', line 159</span>
853
+ <pre class="code"><span class="info file"># File 'lib/time_with_zone.rb', line 167</span>
845
854
 
846
855
  <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
856
  <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>
@@ -949,13 +958,13 @@
949
958
  <pre class="lines">
950
959
 
951
960
 
952
- 133
953
- 134
954
- 135
955
- 136</pre>
961
+ 141
962
+ 142
963
+ 143
964
+ 144</pre>
956
965
  </td>
957
966
  <td>
958
- <pre class="code"><span class="info file"># File 'lib/time_with_zone.rb', line 133</span>
967
+ <pre class="code"><span class="info file"># File 'lib/time_with_zone.rb', line 141</span>
959
968
 
960
969
  <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>
961
970
  <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>
@@ -1064,14 +1073,6 @@
1064
1073
  <pre class="lines">
1065
1074
 
1066
1075
 
1067
- 185
1068
- 186
1069
- 187
1070
- 188
1071
- 189
1072
- 190
1073
- 191
1074
- 192
1075
1076
  193
1076
1077
  194
1077
1078
  195
@@ -1079,10 +1080,18 @@
1079
1080
  197
1080
1081
  198
1081
1082
  199
1082
- 200</pre>
1083
+ 200
1084
+ 201
1085
+ 202
1086
+ 203
1087
+ 204
1088
+ 205
1089
+ 206
1090
+ 207
1091
+ 208</pre>
1083
1092
  </td>
1084
1093
  <td>
1085
- <pre class="code"><span class="info file"># File 'lib/time_with_zone.rb', line 185</span>
1094
+ <pre class="code"><span class="info file"># File 'lib/time_with_zone.rb', line 193</span>
1086
1095
 
1087
1096
  <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>
1088
1097
  <span class='kw'>if</span> <span class='const'>NUMERIC_PATTERN</span> <span class='op'>===</span> <span class='id identifier rubyid_timezone'>timezone</span>
@@ -1110,7 +1119,7 @@
1110
1119
  </div>
1111
1120
 
1112
1121
  <div id="footer">
1113
- Generated on Mon Oct 31 02:34:08 2016 by
1122
+ Generated on Mon Oct 31 12:59:31 2016 by
1114
1123
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
1115
1124
  0.8.7.6 (ruby-2.3.0).
1116
1125
  </div>
data/docs/_index.html CHANGED
@@ -104,7 +104,7 @@
104
104
  </div>
105
105
 
106
106
  <div id="footer">
107
- Generated on Mon Oct 31 02:34:08 2016 by
107
+ Generated on Mon Oct 31 12:59:30 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>
@@ -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 &quot;Software&quot;), 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 &quot;AS IS&quot;, 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 Mon Oct 31 02:34:08 2016 by
67
+ Generated on Mon Oct 31 12:59:31 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>
@@ -124,7 +124,7 @@ href="http://opensource.org/licenses/MIT">MIT License</a>.</p>
124
124
  </div></div>
125
125
 
126
126
  <div id="footer">
127
- Generated on Mon Oct 31 02:34:08 2016 by
127
+ Generated on Mon Oct 31 12:59:31 2016 by
128
128
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
129
129
  0.8.7.6 (ruby-2.3.0).
130
130
  </div>
data/docs/index.html CHANGED
@@ -124,7 +124,7 @@ href="http://opensource.org/licenses/MIT">MIT License</a>.</p>
124
124
  </div></div>
125
125
 
126
126
  <div id="footer">
127
- Generated on Mon Oct 31 02:34:08 2016 by
127
+ Generated on Mon Oct 31 12:59:31 2016 by
128
128
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
129
129
  0.8.7.6 (ruby-2.3.0).
130
130
  </div>
@@ -103,7 +103,7 @@
103
103
  </div>
104
104
 
105
105
  <div id="footer">
106
- Generated on Mon Oct 31 02:34:08 2016 by
106
+ Generated on Mon Oct 31 12:59:31 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>
@@ -40,9 +40,9 @@ class TimeWithZone
40
40
  # time = Time.parse("2016-10-20 00:00:00 +00:00")
41
41
  # time.dup.localtime("+08:00")
42
42
  # #=> 2010-10-20 08:00:00 +0800
43
- # time.dump.localtime("CDT")
43
+ # time.dup.localtime("CDT")
44
44
  # #=> error
45
- # time.dump.localtime("Asia/Taipei")
45
+ # time.dup.localtime("Asia/Taipei")
46
46
  # #=> error
47
47
  #
48
48
  # require 'time_with_zone'
@@ -55,6 +55,14 @@ class TimeWithZone
55
55
  # TimeWithZone.localtime_with_zone(time, "Asia/Taipei")
56
56
  # #=> 2010-10-20 08:00:00 +0800
57
57
  #
58
+ # This method is actually a short-hand of
59
+ #
60
+ # require 'time_with_zone'
61
+ # time = Time.parse("2016-10-20 00:00:00 +00:00")
62
+ #
63
+ # time.dup.localtime(TimeWithZone.zone_offset("Asia/Taipei"))
64
+ # #=> 2010-10-20 08:00:00 +0800
65
+ #
58
66
  # @param [Time] time object
59
67
  # @param [String] timezone {NUMERIC_PATTERN} or {NAME_PATTERN} or {ZoneOffset}
60
68
  # @param [Time]
@@ -157,9 +165,33 @@ class TimeWithZone
157
165
  # @param [String] timezone
158
166
  # @see set_zone
159
167
  def self.set_zone!(time, timezone)
160
- _utc_offset = time.utc_offset
161
- _zone_offset = zone_offset(timezone, time)
162
- time.localtime(_zone_offset) + _utc_offset - _zone_offset
168
+ set_zone_offset!(time, zone_offset(timezone, time))
169
+ end
170
+
171
+ # This method simply sets the zone offset field of Time object (non-destructive)
172
+ #
173
+ # require 'time_with_zone'
174
+ # time = Time.parse("2016-02-02 00:00:00 +00:00")
175
+ #
176
+ # TimeWithZone.set_zone_offset(time, 28800)
177
+ # #=> "2016-02-02 00:00:00 +0800"
178
+ # # Note that it is not "2016-02-02 08:00:00 +0800" like Time#localtime(zone_offset)
179
+ #
180
+ # @param [Time] time
181
+ # @param [Integer] zone_offset
182
+ # @return [Time]
183
+ def self.set_zone_offset(time, zone_offset)
184
+ set_zone_offset!(time.dup, zone_offset)
185
+ end
186
+
187
+ # This method simply sets the zone offset field of Time object (destructive)
188
+ #
189
+ # @param [Time] time
190
+ # @param [Integer] zone_offset
191
+ # @see set_zone_offset
192
+ def self.set_zone_offset!(time, zone_offset)
193
+ utc_offset = time.utc_offset
194
+ time.localtime(zone_offset) + utc_offset - zone_offset
163
195
  end
164
196
 
165
197
  # Returns zone offset for given timezone string
@@ -1,3 +1,3 @@
1
1
  class TimeWithZone
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: time_with_zone
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - sonots
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-10-30 00:00:00.000000000 Z
11
+ date: 2016-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tzinfo