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.
@@ -0,0 +1,164 @@
1
+ # encoding: utf-8
2
+ #
3
+ # This file is part of the lazier gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
4
+ # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
5
+ #
6
+
7
+ require "spec_helper"
8
+
9
+ describe Lazier::TimeZone do
10
+ let(:subject_zone) { ::ActiveSupport::TimeZone["Mountain Time (US & Canada)"] }
11
+ let(:subject_zone) { ::ActiveSupport::TimeZone["Mountain Time (US & Canada)"] }
12
+ let(:zone_without_dst) { ::ActiveSupport::TimeZone["International Date Line West"] }
13
+
14
+ before(:all) do
15
+ ::Lazier.load!
16
+ ::Lazier::Settings.instance(true)
17
+ ::Lazier::Settings.instance.i18n = :en
18
+ end
19
+
20
+ describe ".rationalize_offset" do
21
+ it "should return the correct rational value" do
22
+ expect(::ActiveSupport::TimeZone.rationalize_offset(::ActiveSupport::TimeZone[4])).to eq(Rational(1, 6))
23
+ expect(::ActiveSupport::TimeZone.rationalize_offset(-25200)).to eq(Rational(-7, 24))
24
+ end
25
+ end
26
+
27
+ describe ".format_offset" do
28
+ it "should correctly format an offset" do
29
+ expect(::ActiveSupport::TimeZone.format_offset(-25200)).to eq("-07:00")
30
+ expect(::ActiveSupport::TimeZone.format_offset(Rational(-4, 24), false)).to eq("-0400")
31
+ end
32
+ end
33
+
34
+ describe ".parameterize_zone" do
35
+ it "should return the parameterized version of the zone" do
36
+ expect(::ActiveSupport::TimeZone.parameterize_zone(subject_zone.to_str)).to eq(subject_zone.to_str_parameterized)
37
+ expect(::ActiveSupport::TimeZone.parameterize_zone(subject_zone.to_str)).to eq(subject_zone.to_str_parameterized)
38
+ expect(::ActiveSupport::TimeZone.parameterize_zone(subject_zone.to_str, false)).to eq(subject_zone.to_str_parameterized(false))
39
+ expect(::ActiveSupport::TimeZone.parameterize_zone("INVALID")).to eq("invalid")
40
+ end
41
+ end
42
+
43
+ describe ".unparameterize_zone" do
44
+ it "should return the parameterized version of the zone" do
45
+ expect(::ActiveSupport::TimeZone.unparameterize_zone(subject_zone.to_str_parameterized)).to eq(subject_zone)
46
+ expect(::ActiveSupport::TimeZone.unparameterize_zone(subject_zone.to_str_parameterized, true)).to eq(subject_zone.to_str)
47
+ expect(::ActiveSupport::TimeZone.unparameterize_zone(subject_zone.to_str_with_dst_parameterized)).to eq(subject_zone)
48
+ expect(::ActiveSupport::TimeZone.unparameterize_zone(subject_zone.to_str_with_dst_parameterized, true)).to eq(subject_zone.to_str_with_dst)
49
+ expect(::ActiveSupport::TimeZone.unparameterize_zone("INVALID")).to eq(nil)
50
+ end
51
+ end
52
+
53
+ describe ".find" do
54
+ it "should find timezones" do
55
+ expect(::ActiveSupport::TimeZone.find("(GMT-07:00) Mountain Time (US & Canada)")).to eq(subject_zone)
56
+ expect(::ActiveSupport::TimeZone.find("(GMT-06:00) Mountain Time (US & Canada) (DST)")).to eq(subject_zone)
57
+ expect(::ActiveSupport::TimeZone.find("(GMT-06:00) Mountain Time (US & Canada) Daylight Saving Time", "Daylight Saving Time")).to eq(subject_zone)
58
+ expect(::ActiveSupport::TimeZone.find("INVALID", "INVALID")).to be_nil
59
+ end
60
+ end
61
+
62
+ describe ".list_all" do
63
+ it "should list all timezones" do
64
+ expect(::ActiveSupport::TimeZone.list_all(false)).to eq(::ActiveSupport::TimeZone.all.map(&:to_s))
65
+ expect(::ActiveSupport::TimeZone.list_all(true)).to include("(GMT-06:00) #{subject_zone.aliases.first} (DST)")
66
+ expect(::ActiveSupport::TimeZone.list_all(true, "Daylight Saving Time")).to include("(GMT-06:00) #{subject_zone.aliases.first} Daylight Saving Time")
67
+ end
68
+ end
69
+
70
+ describe "#offset" do
71
+ it "should correctly return zone offset" do
72
+ expect(subject_zone.offset).to eq(subject_zone.utc_offset)
73
+ end
74
+ end
75
+
76
+ describe "#current_offset" do
77
+ it "should correctly return current zone offset" do
78
+ expect(subject_zone.current_offset(false, ::DateTime.civil(2012, 1, 15))).to eq(subject_zone.offset)
79
+ expect(subject_zone.current_offset(true, ::DateTime.civil(2012, 7, 15))).to eq(subject_zone.dst_offset(true))
80
+ end
81
+ end
82
+
83
+ describe "#current_alias" do
84
+ it "should correctly return current zone alias or the first one" do
85
+ zone = ActiveSupport::TimeZone["America/Halifax"]
86
+ expect(zone.current_alias).to eq("America/Halifax")
87
+ allow(zone.tzinfo).to receive(:identifier).and_return("INVALID")
88
+ expect(zone.current_alias).to eq("America/Atlantic Time (Canada)")
89
+ end
90
+ end
91
+
92
+ describe "#dst_period" do
93
+ it "should correctly return zone offset" do
94
+ expect(subject_zone.dst_period).to be_a(::TZInfo::TimezonePeriod)
95
+ expect(subject_zone.dst_period(1000)).to be_nil
96
+ expect(zone_without_dst.dst_period).to be_nil
97
+ end
98
+ end
99
+
100
+ describe "#uses_dst?" do
101
+ it "should correctly detect offset usage" do
102
+ expect(subject_zone.uses_dst?).to be_true
103
+ expect(subject_zone.uses_dst?(::DateTime.civil(2012, 7, 15))).to be_true
104
+ expect(subject_zone.uses_dst?(::DateTime.civil(2012, 1, 15))).to be_false
105
+ expect(subject_zone.uses_dst?(1000)).to be_false
106
+ expect(zone_without_dst.uses_dst?).to be_false
107
+ end
108
+ end
109
+
110
+ describe "#dst_name" do
111
+ it "should correctly get zone name with Daylight Saving Time" do
112
+ expect(subject_zone.dst_name).to eq("Mountain Time (US & Canada) (DST)")
113
+ expect(subject_zone.dst_name("Daylight Saving Time")).to eq("Mountain Time (US & Canada) Daylight Saving Time")
114
+ expect(subject_zone.dst_name(nil, 1000)).to be_nil
115
+ expect(zone_without_dst.to_str_with_dst).to be_nil
116
+ end
117
+ end
118
+
119
+ describe "#dst_correction" do
120
+ it "should correctly detect offset usage" do
121
+ expect(subject_zone.dst_correction).to eq(3600)
122
+ expect(subject_zone.dst_correction(true)).to eq(Rational(1, 24))
123
+ expect(subject_zone.dst_correction(false, 1000)).to eq(0)
124
+ expect(zone_without_dst.dst_correction).to eq(0)
125
+ end
126
+ end
127
+
128
+ describe "#dst_offset" do
129
+ it "should correctly return zone offset" do
130
+ expect(subject_zone.dst_offset).to eq(subject_zone.dst_correction + subject_zone.utc_offset)
131
+ expect(subject_zone.dst_offset(true)).to eq(::ActiveSupport::TimeZone.rationalize_offset(subject_zone.dst_correction + subject_zone.utc_offset))
132
+ expect(zone_without_dst.dst_offset(false, 1000)).to eq(0)
133
+ expect(zone_without_dst.dst_offset).to eq(0)
134
+ end
135
+ end
136
+
137
+ describe "#to_str_with_dst" do
138
+ it "should correctly format zone with Daylight Saving Time" do
139
+ expect(subject_zone.to_str_with_dst).to eq("(GMT-06:00) #{subject_zone.aliases.first} (DST)")
140
+ expect(subject_zone.to_str_with_dst("Daylight Saving Time")).to eq("(GMT-06:00) #{subject_zone.aliases.first} Daylight Saving Time")
141
+ expect(subject_zone.to_str_with_dst("Daylight Saving Time", nil, "NAME")).to eq("(GMT-06:00) NAME Daylight Saving Time")
142
+ expect(subject_zone.to_str_with_dst(nil, 1000)).to be_nil
143
+ expect(zone_without_dst.to_str_with_dst).to be_nil
144
+ end
145
+ end
146
+
147
+ describe "#to_str_parameterized" do
148
+ it "should correctly format (parameterized) zone" do
149
+ expect(subject_zone.to_str_parameterized).to eq(::ActiveSupport::TimeZone.parameterize_zone(subject_zone.to_str))
150
+ expect(subject_zone.to_str_parameterized(false)).to eq(::ActiveSupport::TimeZone.parameterize_zone(subject_zone.to_str, false))
151
+ expect(subject_zone.to_str_parameterized(false, "NAME SPACE")).to eq(::ActiveSupport::TimeZone.parameterize_zone("NAME SPACE", false))
152
+ end
153
+ end
154
+
155
+ describe "#to_str_with_dst_parameterized" do
156
+ it "should correctly format (parameterized) zone with Daylight Saving Time" do
157
+ expect(subject_zone.to_str_with_dst_parameterized).to eq("-0600@america-denver-dst")
158
+ expect(subject_zone.to_str_with_dst_parameterized("Daylight Saving Time")).to eq("-0600@america-denver-daylight-saving-time")
159
+ expect(subject_zone.to_str_with_dst_parameterized(nil, 1000)).to be_nil
160
+ expect(subject_zone.to_str_with_dst_parameterized("Daylight Saving Time", nil, "NAME SPACE")).to eq("-0600@name-space-daylight-saving-time")
161
+ expect(zone_without_dst.to_str_with_dst_parameterized).to be_nil
162
+ end
163
+ end
164
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lazier
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.5.2
4
+ version: 3.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shogun
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-28 00:00:00.000000000 Z
11
+ date: 2014-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -145,6 +145,7 @@ files:
145
145
  - lib/lazier/pathname.rb
146
146
  - lib/lazier/settings.rb
147
147
  - lib/lazier/string.rb
148
+ - lib/lazier/timezone.rb
148
149
  - lib/lazier/version.rb
149
150
  - locales/en.yml
150
151
  - locales/it.yml
@@ -160,6 +161,7 @@ files:
160
161
  - spec/lazier/pathname_spec.rb
161
162
  - spec/lazier/settings_spec.rb
162
163
  - spec/lazier/string_spec.rb
164
+ - spec/lazier/timezone_spec.rb
163
165
  - spec/lazier_spec.rb
164
166
  - spec/spec_helper.rb
165
167
  homepage: http://sw.cow.tc/lazier
@@ -199,6 +201,7 @@ test_files:
199
201
  - spec/lazier/pathname_spec.rb
200
202
  - spec/lazier/settings_spec.rb
201
203
  - spec/lazier/string_spec.rb
204
+ - spec/lazier/timezone_spec.rb
202
205
  - spec/lazier_spec.rb
203
206
  - spec/spec_helper.rb
204
207
  has_rdoc: