lazier 2.8.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +3 -3
- data/doc/Lazier.html +69 -99
- data/doc/Lazier/Boolean.html +6 -6
- data/doc/Lazier/DateTime.html +35 -39
- data/doc/Lazier/DateTime/ClassMethods.html +59 -85
- data/doc/Lazier/Exceptions.html +6 -6
- data/doc/Lazier/Exceptions/Debug.html +133 -0
- data/doc/Lazier/Exceptions/MissingTranslation.html +8 -8
- data/doc/Lazier/Hash.html +5 -270
- data/doc/Lazier/I18n.html +68 -26
- data/doc/Lazier/Localizer.html +17 -21
- data/doc/Lazier/Math.html +5 -5
- data/doc/Lazier/Math/ClassMethods.html +5 -5
- data/doc/Lazier/Object.html +681 -218
- data/doc/Lazier/Pathname.html +7 -11
- data/doc/Lazier/Settings.html +166 -262
- data/doc/Lazier/String.html +21 -25
- data/doc/Lazier/TimeZone.html +119 -130
- data/doc/Lazier/TimeZone/ClassMethods.html +75 -83
- data/doc/Lazier/Version.html +8 -8
- data/doc/_index.html +7 -7
- data/doc/class_list.html +2 -2
- data/doc/file.README.html +5 -5
- data/doc/file_list.html +1 -1
- data/doc/frames.html +1 -1
- data/doc/index.html +5 -5
- data/doc/js/full_list.js +6 -1
- data/doc/method_list.html +134 -324
- data/doc/top-level-namespace.html +5 -5
- data/lazier.gemspec +4 -3
- data/lib/lazier.rb +9 -23
- data/lib/lazier/boolean.rb +1 -1
- data/lib/lazier/datetime.rb +47 -79
- data/lib/lazier/exceptions.rb +4 -4
- data/lib/lazier/hash.rb +0 -24
- data/lib/lazier/i18n.rb +13 -6
- data/lib/lazier/localizer.rb +3 -5
- data/lib/lazier/object.rb +107 -78
- data/lib/lazier/pathname.rb +1 -3
- data/lib/lazier/settings.rb +22 -30
- data/lib/lazier/string.rb +3 -5
- data/lib/lazier/version.rb +3 -3
- data/spec/lazier/datetime_spec.rb +8 -8
- data/spec/lazier/hash_spec.rb +9 -10
- data/spec/lazier/object_spec.rb +85 -11
- data/spec/lazier/settings_spec.rb +10 -17
- data/spec/lazier_spec.rb +1 -1
- metadata +26 -9
@@ -6,13 +6,13 @@
|
|
6
6
|
<title>
|
7
7
|
Top Level Namespace
|
8
8
|
|
9
|
-
— Documentation by YARD 0.8.
|
9
|
+
— Documentation by YARD 0.8.6.1
|
10
10
|
|
11
11
|
</title>
|
12
12
|
|
13
|
-
<link rel="stylesheet" href="css/style.css" type="text/css"
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />
|
14
14
|
|
15
|
-
<link rel="stylesheet" href="css/common.css" type="text/css"
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
|
16
16
|
|
17
17
|
<script type="text/javascript" charset="utf-8">
|
18
18
|
hasFrames = window.top.frames.main ? true : false;
|
@@ -103,9 +103,9 @@
|
|
103
103
|
</div>
|
104
104
|
|
105
105
|
<div id="footer">
|
106
|
-
Generated on
|
106
|
+
Generated on Fri May 17 12:03:20 2013 by
|
107
107
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
108
|
-
0.8.
|
108
|
+
0.8.6.1 (ruby-1.9.3).
|
109
109
|
</div>
|
110
110
|
|
111
111
|
</body>
|
data/lazier.gemspec
CHANGED
@@ -24,8 +24,9 @@ Gem::Specification.new do |gem|
|
|
24
24
|
|
25
25
|
gem.required_ruby_version = ">= 1.9.3"
|
26
26
|
|
27
|
-
gem.add_dependency("json", "~> 1.
|
27
|
+
gem.add_dependency("json", "~> 1.8.0")
|
28
28
|
gem.add_dependency("actionpack", ">= 3.2.13") # We don't use ~> to enable use with 4.0
|
29
|
-
gem.add_dependency("tzinfo", "~> 0.3.
|
30
|
-
gem.add_dependency("r18n-desktop", "~> 1.1.
|
29
|
+
gem.add_dependency("tzinfo", "~> 0.3.37")
|
30
|
+
gem.add_dependency("r18n-desktop", "~> 1.1.5")
|
31
|
+
gem.add_dependency("hashie", "~> 2.0.5")
|
31
32
|
end
|
data/lib/lazier.rb
CHANGED
@@ -9,6 +9,7 @@ require "tzinfo"
|
|
9
9
|
require "active_support/all"
|
10
10
|
require "action_view"
|
11
11
|
require "r18n-desktop"
|
12
|
+
require "hashie"
|
12
13
|
|
13
14
|
require "lazier/version" if !defined?(Lazier::Version)
|
14
15
|
require "lazier/exceptions"
|
@@ -45,18 +46,14 @@ module Lazier
|
|
45
46
|
# @option pathname Extensions for path objects.
|
46
47
|
# @return [Settings] The settings for the extensions.
|
47
48
|
def self.load!(*what)
|
48
|
-
what
|
49
|
-
what.collect! { |w| ::Lazier.send("load_#{w}") }
|
50
|
-
|
49
|
+
(what.present? ? what : ["object", "boolean", "string", "hash", "datetime", "math", "pathname"]).each { |w| ::Lazier.send("load_#{w}") }
|
51
50
|
yield if block_given?
|
52
51
|
::Lazier::Settings.instance
|
53
52
|
end
|
54
53
|
|
55
54
|
# Loads Object extensions.
|
56
55
|
def self.load_object
|
57
|
-
::Object.class_eval
|
58
|
-
include ::Lazier::Object
|
59
|
-
end
|
56
|
+
::Object.class_eval { include ::Lazier::Object }
|
60
57
|
end
|
61
58
|
|
62
59
|
# Loads Boolean extensions.
|
@@ -74,14 +71,13 @@ module Lazier
|
|
74
71
|
|
75
72
|
# Loads String extensions.
|
76
73
|
def self.load_string
|
77
|
-
::String.class_eval
|
78
|
-
include ::Lazier::String
|
79
|
-
end
|
74
|
+
::String.class_eval { include ::Lazier::String }
|
80
75
|
end
|
81
76
|
|
82
77
|
# Loads Hash extensions.
|
83
78
|
def self.load_hash
|
84
79
|
::Hash.class_eval do
|
80
|
+
include Hashie::Extensions::MethodAccess
|
85
81
|
include ::Lazier::Hash
|
86
82
|
end
|
87
83
|
end
|
@@ -91,32 +87,22 @@ module Lazier
|
|
91
87
|
Lazier.load_object
|
92
88
|
|
93
89
|
[::Time, ::Date, ::DateTime].each do |c|
|
94
|
-
c.class_eval
|
95
|
-
include ::Lazier::DateTime
|
96
|
-
end
|
90
|
+
c.class_eval { include ::Lazier::DateTime }
|
97
91
|
end
|
98
92
|
|
99
|
-
::ActiveSupport::TimeZone.class_eval
|
100
|
-
include ::Lazier::TimeZone
|
101
|
-
end
|
93
|
+
::ActiveSupport::TimeZone.class_eval { include ::Lazier::TimeZone }
|
102
94
|
end
|
103
95
|
|
104
96
|
# Loads Math extensions.
|
105
97
|
def self.load_math
|
106
98
|
Lazier.load_object
|
107
|
-
|
108
|
-
::Math.class_eval do
|
109
|
-
include ::Lazier::Math
|
110
|
-
end
|
99
|
+
::Math.class_eval { include ::Lazier::Math }
|
111
100
|
end
|
112
101
|
|
113
102
|
# Loads Pathname extensions.
|
114
103
|
def self.load_pathname
|
115
104
|
require "pathname"
|
116
|
-
|
117
|
-
::Pathname.class_eval do
|
118
|
-
include ::Lazier::Pathname
|
119
|
-
end
|
105
|
+
::Pathname.class_eval { include ::Lazier::Pathname }
|
120
106
|
end
|
121
107
|
|
122
108
|
# Finds a class to instantiate.
|
data/lib/lazier/boolean.rb
CHANGED
data/lib/lazier/datetime.rb
CHANGED
@@ -17,11 +17,9 @@ module Lazier
|
|
17
17
|
# @param short [Boolean] If return the abbreviated representations.
|
18
18
|
# @return [Array] Return string representations of days.
|
19
19
|
def days(short = true)
|
20
|
-
|
21
|
-
|
22
|
-
{value: i.to_s, label: days[i - 1]}
|
20
|
+
::Lazier.settings.date_names[short ? :short_days : :long_days].collect.with_index {|label, index|
|
21
|
+
{value: (index + 1).to_s, label: label}
|
23
22
|
}
|
24
|
-
|
25
23
|
end
|
26
24
|
|
27
25
|
# Returns strings representations of months.
|
@@ -30,9 +28,8 @@ module Lazier
|
|
30
28
|
# @param short [Boolean] If return the abbreviated representations.
|
31
29
|
# @return [Array] Return string representations of months.
|
32
30
|
def months(short = true)
|
33
|
-
|
34
|
-
|
35
|
-
{value: i.to_s.rjust(2, "0"), label: months.at(i - 1)}
|
31
|
+
::Lazier.settings.date_names[short ? :short_months : :long_months].collect.with_index {|label, index|
|
32
|
+
{value: (index + 1).to_s.rjust(2, "0"), label: label}
|
36
33
|
}
|
37
34
|
end
|
38
35
|
|
@@ -128,7 +125,7 @@ module Lazier
|
|
128
125
|
data = easter_start(year)
|
129
126
|
data = easter_part_1(data)
|
130
127
|
data = easter_part_2(year, data)
|
131
|
-
data = easter_part_3(year,
|
128
|
+
data = easter_part_3(year, data)
|
132
129
|
day, month = easter_end(data)
|
133
130
|
|
134
131
|
::Date.civil(year, month, day)
|
@@ -140,7 +137,7 @@ module Lazier
|
|
140
137
|
# @param key [Symbol] The name of the format to search.
|
141
138
|
# @return [String] The format or the name itself (if the format has not been found).
|
142
139
|
def custom_format(key)
|
143
|
-
::Lazier.settings.date_formats.fetch(key
|
140
|
+
::Lazier.settings.date_formats.fetch(key, key)
|
144
141
|
end
|
145
142
|
|
146
143
|
# Checks if the date is valid against to a specific format.
|
@@ -150,17 +147,7 @@ module Lazier
|
|
150
147
|
# @param format [String] The format to check the value against.
|
151
148
|
# @return [Boolean] `true` if the value is valid against the format, `false` otherwise.
|
152
149
|
def is_valid?(value, format = "%F %T")
|
153
|
-
|
154
|
-
|
155
|
-
format = self.custom_format(format)
|
156
|
-
|
157
|
-
begin
|
158
|
-
::DateTime.strptime(value.ensure_string, format)
|
159
|
-
rescue => _
|
160
|
-
rv = false
|
161
|
-
end
|
162
|
-
|
163
|
-
rv
|
150
|
+
!(::DateTime.strptime(value, self.custom_format(format)) rescue nil).nil?
|
164
151
|
end
|
165
152
|
|
166
153
|
private
|
@@ -177,6 +164,7 @@ module Lazier
|
|
177
164
|
# @return [Array] Partial variables for #easter_part_2.
|
178
165
|
def easter_part_1(data)
|
179
166
|
_, b, c = data
|
167
|
+
|
180
168
|
[
|
181
169
|
b - (b / 4.0).floor - ((b - ((b + 8) / 25.0).floor + 1) / 3.0).floor,
|
182
170
|
b % 4,
|
@@ -219,8 +207,7 @@ module Lazier
|
|
219
207
|
#
|
220
208
|
# @return [UTC::Time] The UTC::Time representation of the current datetime.
|
221
209
|
def utc_time
|
222
|
-
|
223
|
-
::Time.utc(ua.year, ua.month, ua.day, ua.hour, ua.min, ua.sec)
|
210
|
+
utc.to_time
|
224
211
|
end
|
225
212
|
|
226
213
|
# Returns the number of months passed between the beginning of the base year and the current date.
|
@@ -233,15 +220,14 @@ module Lazier
|
|
233
220
|
# @param base [DateTime] The base year to start computation from. Default to current year.
|
234
221
|
# @return [Fixnum] Returns the number of months passed between the beginning of the base year and the current date.
|
235
222
|
def in_months(base = nil)
|
236
|
-
base
|
237
|
-
((self.year) - base) * 12 + self.month
|
223
|
+
(year - (base || ::Date.today.year)) * 12 + month
|
238
224
|
end
|
239
225
|
|
240
226
|
# Returns the current month number with leading 0.
|
241
227
|
#
|
242
228
|
# @return [String] The current month number with leading 0.
|
243
229
|
def padded_month
|
244
|
-
|
230
|
+
month.indexize
|
245
231
|
end
|
246
232
|
|
247
233
|
# Formats a datetime, looking up also custom formats.
|
@@ -250,7 +236,7 @@ module Lazier
|
|
250
236
|
# @param format [String] A format or a custom format name to use for formatting.
|
251
237
|
# @return [String] The formatted date.
|
252
238
|
def lstrftime(format = nil)
|
253
|
-
|
239
|
+
strftime(::DateTime.custom_format(format.to_s).gsub(/(?<!%)(%[ab])/i) {|mo| localize_time_component(mo) })
|
254
240
|
end
|
255
241
|
|
256
242
|
# Formats a datetime in the current timezone.
|
@@ -258,7 +244,7 @@ module Lazier
|
|
258
244
|
# @param format [String] The format to use for formatting.
|
259
245
|
# @return [String] The formatted date.
|
260
246
|
def local_strftime(format = nil)
|
261
|
-
(
|
247
|
+
(respond_to?(:in_time_zone) ? in_time_zone : self).strftime(::DateTime.custom_format(format))
|
262
248
|
end
|
263
249
|
|
264
250
|
# Formats a datetime in the current timezone, looking up also custom formats.
|
@@ -267,7 +253,7 @@ module Lazier
|
|
267
253
|
# @param format [String] A format or a custom format name.
|
268
254
|
# @return [String] The formatted date.
|
269
255
|
def local_lstrftime(format = nil)
|
270
|
-
(
|
256
|
+
(respond_to?(:in_time_zone) ? in_time_zone : self).lstrftime(format)
|
271
257
|
end
|
272
258
|
|
273
259
|
private
|
@@ -277,8 +263,8 @@ module Lazier
|
|
277
263
|
# @return [String] The localized component.
|
278
264
|
def localize_time_component(component)
|
279
265
|
type = {"%a" => :short_days, "%A" => :long_days, "%b" => :short_months, "%B" => :long_months}.fetch(component, "")
|
280
|
-
index = component =~ /%a/i ?
|
281
|
-
::Lazier.settings.date_names
|
266
|
+
index = component =~ /%a/i ? wday : month - 1
|
267
|
+
::Lazier.settings.date_names[type][index]
|
282
268
|
end
|
283
269
|
end
|
284
270
|
|
@@ -293,8 +279,7 @@ module Lazier
|
|
293
279
|
# @param offset [Fixnum] The offset to convert.
|
294
280
|
# @return [Rational] The converted offset.
|
295
281
|
def rationalize_offset(offset)
|
296
|
-
|
297
|
-
::TZInfo::OffsetRationals.rational_for_offset(offset.to_integer)
|
282
|
+
::TZInfo::OffsetRationals.rational_for_offset(offset.is_a?(::Fixnum) ? offset : offset.offset)
|
298
283
|
end
|
299
284
|
|
300
285
|
# Returns a +HH:MM formatted representation of the offset.
|
@@ -303,8 +288,7 @@ module Lazier
|
|
303
288
|
# @param colon [Boolean] If to put the colon in the output string.
|
304
289
|
# @return [String] The formatted offset.
|
305
290
|
def format_offset(offset, colon = true)
|
306
|
-
offset
|
307
|
-
offset.is_a?(::Fixnum) ? self.seconds_to_utc_offset(offset, colon) : nil
|
291
|
+
self.seconds_to_utc_offset(offset.is_a?(::Rational) ? (offset * 86400).to_i : offset, colon)
|
308
292
|
end
|
309
293
|
|
310
294
|
# Find a zone by its name.
|
@@ -367,20 +351,18 @@ module Lazier
|
|
367
351
|
# @param dst_label [String] Label for the DST indication. Defaults to `(DST)`.
|
368
352
|
# @return [String|TimeZone] The found timezone or `nil` if the zone is not valid.
|
369
353
|
def unparameterize_zone(tz, as_string = false, dst_label = nil)
|
370
|
-
tz =
|
354
|
+
tz = parameterize_zone(tz, false)
|
355
|
+
matcher = /(#{Regexp.quote(tz)})$/
|
356
|
+
|
371
357
|
rv = catch(:zone) do
|
372
|
-
|
373
|
-
throw(:zone, zone) if
|
358
|
+
list_all(true, dst_label).each do |zone|
|
359
|
+
throw(:zone, zone) if parameterize_zone(zone, false) =~ matcher
|
374
360
|
end
|
375
361
|
|
376
362
|
nil
|
377
363
|
end
|
378
364
|
|
379
|
-
|
380
|
-
(as_string ? rv : self.find(rv, dst_label))
|
381
|
-
else
|
382
|
-
nil
|
383
|
-
end
|
365
|
+
rv ? (as_string ? rv : self.find(rv, dst_label)) : nil
|
384
366
|
end
|
385
367
|
|
386
368
|
# Compares two timezones. They are sorted by the location name.
|
@@ -400,8 +382,10 @@ module Lazier
|
|
400
382
|
# @param zone [ActiveSupport::TimeZone] The zone.
|
401
383
|
# @param dst_label [String] Label for the DST indication. Defaults to `(DST)`.
|
402
384
|
def fetch_aliases(zone, dst_label = "(DST)")
|
385
|
+
matcher = /(#{Regexp.quote(dst_label)})$/
|
386
|
+
|
403
387
|
zone.aliases.collect { |zone_alias|
|
404
|
-
[zone.to_str(zone_alias), (zone.uses_dst? && zone_alias !~
|
388
|
+
[zone.to_str(zone_alias), (zone.uses_dst? && zone_alias !~ matcher) ? zone.to_str_with_dst(dst_label, nil, zone_alias) : nil]
|
405
389
|
}
|
406
390
|
end
|
407
391
|
end
|
@@ -409,7 +393,7 @@ module Lazier
|
|
409
393
|
# Returns a list of valid aliases (city names) for this timezone (basing on offset).
|
410
394
|
# @return [Array] A list of aliases for this timezone
|
411
395
|
def aliases
|
412
|
-
reference = self.class::MAPPING.fetch(
|
396
|
+
reference = self.class::MAPPING.fetch(name, name).gsub("_", " ")
|
413
397
|
@aliases ||= ([reference] + self.class::MAPPING.collect { |name, zone| format_alias(name, zone, reference) }).uniq.compact.sort
|
414
398
|
end
|
415
399
|
|
@@ -420,20 +404,22 @@ module Lazier
|
|
420
404
|
# @return [Fixnum|Rational] The offset of this timezone.
|
421
405
|
def current_offset(rational = false, date = nil)
|
422
406
|
date ||= ::DateTime.now
|
423
|
-
rv = (
|
407
|
+
rv = (period_for_utc(date.utc).dst? ? dst_offset : offset)
|
424
408
|
rational ? self.class.rationalize_offset(rv) : rv
|
425
409
|
end
|
426
410
|
|
427
|
-
#
|
411
|
+
# Returns the current alias for this timezone.
|
412
|
+
#
|
413
|
+
# @return [String] The current alias or the first alias of the current timezone.
|
428
414
|
def current_alias
|
429
|
-
identifier =
|
415
|
+
identifier = tzinfo.identifier
|
430
416
|
|
431
417
|
catch(:alias) do
|
432
|
-
|
418
|
+
aliases.each do |a|
|
433
419
|
throw(:alias, a) if a == identifier
|
434
420
|
end
|
435
421
|
|
436
|
-
|
422
|
+
aliases.first
|
437
423
|
end
|
438
424
|
end
|
439
425
|
|
@@ -442,8 +428,7 @@ module Lazier
|
|
442
428
|
# @param rational [Boolean] If to return the offset as a Rational.
|
443
429
|
# @return [Fixnum|Rational] The offset of this timezone.
|
444
430
|
def offset(rational = false)
|
445
|
-
|
446
|
-
rational ? self.class.rationalize_offset(rv) : rv
|
431
|
+
rational ? self.class.rationalize_offset(utc_offset) : utc_offset
|
447
432
|
end
|
448
433
|
|
449
434
|
# Gets a period for this timezone when the Daylight Saving Time (DST) is active (it takes care of different hemispheres).
|
@@ -454,7 +439,7 @@ module Lazier
|
|
454
439
|
year ||= ::Date.today.year
|
455
440
|
|
456
441
|
northern_summer = ::DateTime.civil(year, 7, 15).utc # This is a representation of a summer period in the Northern Hemisphere.
|
457
|
-
southern_summer = ::DateTime.civil(year, 1, 15).utc # This is a representation of a summer period in the
|
442
|
+
southern_summer = ::DateTime.civil(year, 1, 15).utc # This is a representation of a summer period in the Southern Hemisphere.
|
458
443
|
|
459
444
|
period = self.period_for_utc(northern_summer)
|
460
445
|
period = self.period_for_utc(southern_summer) if !period.dst?
|
@@ -467,9 +452,9 @@ module Lazier
|
|
467
452
|
# @return [Boolean] `true` if the zone uses DST for that date or year, `false` otherwise.
|
468
453
|
def uses_dst?(reference = nil)
|
469
454
|
if reference.respond_to?(:year) && reference.respond_to?(:utc) then # This is a date like object
|
470
|
-
|
455
|
+
dst_period(reference.year).present? && period_for_utc(reference.utc).dst?
|
471
456
|
else
|
472
|
-
|
457
|
+
dst_period(reference).present?
|
473
458
|
end
|
474
459
|
end
|
475
460
|
|
@@ -479,7 +464,7 @@ module Lazier
|
|
479
464
|
# @param year [Fixnum] The year to which refer to. Defaults to the current year.
|
480
465
|
# @return [Fixnum|Rational] The correction for dst.
|
481
466
|
def dst_correction(rational = false, year = nil)
|
482
|
-
|
467
|
+
dst_offset(rational, year, :std_offset)
|
483
468
|
end
|
484
469
|
|
485
470
|
# Returns the standard offset for this timezone timezone when the Daylight Saving Time (DST) is active.
|
@@ -489,7 +474,7 @@ module Lazier
|
|
489
474
|
# @param method [Symbol] The method to use for getting the offset. Default is total offset from UTC.
|
490
475
|
# @return [Fixnum|Rational] The DST offset for this timezone or `0`, if the timezone doesn't use DST for that year.
|
491
476
|
def dst_offset(rational = false, year = nil, method = :utc_total_offset)
|
492
|
-
period =
|
477
|
+
period = dst_period(year)
|
493
478
|
rv = period ? period.send(method) : 0
|
494
479
|
rational ? self.class.rationalize_offset(rv) : rv
|
495
480
|
end
|
@@ -501,10 +486,7 @@ module Lazier
|
|
501
486
|
# @param name [String] The name to use for this zone. Defaults to the zone name.
|
502
487
|
# @return [String] The name for the zone with DST or `nil`, if the timezone doesn't use DST for that year.
|
503
488
|
def dst_name(dst_label = nil, year = nil, name = nil)
|
504
|
-
dst_label
|
505
|
-
name ||= self.name
|
506
|
-
|
507
|
-
self.uses_dst?(year) ? "#{name} #{dst_label}" : nil
|
489
|
+
uses_dst?(year) ? "#{name || self.name} #{dst_label || "(DST)"}" : nil
|
508
490
|
end
|
509
491
|
|
510
492
|
# Returns the name for this zone with Daylight Saving Time (DST) active.
|
@@ -513,8 +495,7 @@ module Lazier
|
|
513
495
|
# @param colon [Boolean] If to put the colon in the output string.
|
514
496
|
# @return [String] The name for this zone.
|
515
497
|
def to_str(name = nil, colon = true)
|
516
|
-
name
|
517
|
-
"(GMT#{self.formatted_offset(colon)}) #{name}"
|
498
|
+
"(GMT#{self.formatted_offset(colon)}) #{name || current_alias}"
|
518
499
|
end
|
519
500
|
|
520
501
|
# Returns a string representation for this zone with Daylight Saving Time (DST) active.
|
@@ -524,16 +505,7 @@ module Lazier
|
|
524
505
|
# @param name [String] The name to use for this zone. Defaults to the zone name.
|
525
506
|
# @return [String] The string representation for the zone with DST or `nil`, if the timezone doesn't use DST for that year.
|
526
507
|
def to_str_with_dst(dst_label = nil, year = nil, name = nil)
|
527
|
-
dst_label
|
528
|
-
name ||= self.current_alias
|
529
|
-
|
530
|
-
if self.uses_dst?(year) then
|
531
|
-
period = self.dst_period(year)
|
532
|
-
offset = self.class.seconds_to_utc_offset(period.utc_total_offset)
|
533
|
-
"(GMT#{offset}) #{name} #{dst_label}"
|
534
|
-
else
|
535
|
-
nil
|
536
|
-
end
|
508
|
+
self.uses_dst?(year) ? "(GMT#{self.class.seconds_to_utc_offset(dst_period(year).utc_total_offset)}) #{name || current_alias} #{dst_label || "(DST)"}" : nil
|
537
509
|
end
|
538
510
|
|
539
511
|
# Returns a parameterized string representation for this zone.
|
@@ -542,7 +514,7 @@ module Lazier
|
|
542
514
|
# @param name [String] The name to use for this zone. Defaults to the zone name.
|
543
515
|
# @return [String] The parameterized string representation for this zone.
|
544
516
|
def to_str_parameterized(with_offset = true, name = nil)
|
545
|
-
::ActiveSupport::TimeZone.parameterize_zone(name ||
|
517
|
+
::ActiveSupport::TimeZone.parameterize_zone(name || to_str, with_offset)
|
546
518
|
end
|
547
519
|
|
548
520
|
# Returns a parameterized string representation for this zone with Daylight Saving Time (DST) active.
|
@@ -552,7 +524,7 @@ module Lazier
|
|
552
524
|
# @param name [String] The name to use for this zone. Defaults to the zone name.
|
553
525
|
# @return [String] The parameterized string representation for this zone with DST or `nil`, if the timezone doesn't use DST for that year.
|
554
526
|
def to_str_with_dst_parameterized(dst_label = nil, year = nil, name = nil)
|
555
|
-
rv =
|
527
|
+
rv = to_str_with_dst(dst_label, year, name)
|
556
528
|
rv ? ::ActiveSupport::TimeZone.parameterize_zone(rv) : nil
|
557
529
|
end
|
558
530
|
|
@@ -564,11 +536,7 @@ module Lazier
|
|
564
536
|
# @param reference [String] The main name for the zone.
|
565
537
|
# @return [String|nil] The formatted alias.
|
566
538
|
def format_alias(name, zone, reference)
|
567
|
-
|
568
|
-
(["International Date Line West", "UTC"].include?(name) || name.include?("(US & Canada)")) ? name : reference.gsub(/\/.*/, "/#{name}")
|
569
|
-
else
|
570
|
-
nil
|
571
|
-
end
|
539
|
+
zone.gsub("_", " ") == reference ? (["International Date Line West", "UTC"].include?(name) || name.include?("(US & Canada)")) ? name : reference.gsub(/\/.*/, "/#{name}") : nil
|
572
540
|
end
|
573
541
|
end
|
574
542
|
end
|