lazier 2.4.0 → 2.5.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/doc/Lazier.html +22 -34
- data/doc/Lazier/Boolean.html +1 -1
- data/doc/Lazier/DateTime.html +28 -34
- data/doc/Lazier/DateTime/ClassMethods.html +17 -13
- data/doc/Lazier/Exceptions.html +1 -1
- data/doc/Lazier/Exceptions/Dump.html +1 -1
- data/doc/Lazier/Hash.html +1 -1
- data/doc/Lazier/I18n.html +20 -10
- data/doc/Lazier/Math.html +1 -1
- data/doc/Lazier/Math/ClassMethods.html +1 -1
- data/doc/Lazier/Object.html +1 -1
- data/doc/Lazier/Pathname.html +1 -1
- data/doc/Lazier/Settings.html +1 -1
- data/doc/Lazier/String.html +1 -1
- data/doc/Lazier/TimeZone.html +96 -110
- data/doc/Lazier/TimeZone/ClassMethods.html +65 -69
- data/doc/Lazier/Version.html +3 -3
- data/doc/_index.html +1 -1
- data/doc/file.README.html +1 -1
- data/doc/index.html +1 -1
- data/doc/top-level-namespace.html +1 -1
- data/lib/lazier.rb +4 -10
- data/lib/lazier/datetime.rb +68 -37
- data/lib/lazier/i18n.rb +1 -0
- data/lib/lazier/version.rb +1 -1
- metadata +2 -2
data/doc/Lazier/Version.html
CHANGED
@@ -134,7 +134,7 @@
|
|
134
134
|
|
135
135
|
</div>
|
136
136
|
</dt>
|
137
|
-
<dd><pre class="code"><span class='int'>
|
137
|
+
<dd><pre class="code"><span class='int'>5</span></pre></dd>
|
138
138
|
|
139
139
|
<dt id="PATCH-constant" class="">PATCH =
|
140
140
|
<div class="docstring">
|
@@ -149,7 +149,7 @@
|
|
149
149
|
|
150
150
|
</div>
|
151
151
|
</dt>
|
152
|
-
<dd><pre class="code"><span class='int'>
|
152
|
+
<dd><pre class="code"><span class='int'>0</span></pre></dd>
|
153
153
|
|
154
154
|
<dt id="STRING-constant" class="">STRING =
|
155
155
|
<div class="docstring">
|
@@ -180,7 +180,7 @@
|
|
180
180
|
</div>
|
181
181
|
|
182
182
|
<div id="footer">
|
183
|
-
Generated on
|
183
|
+
Generated on Thu Jan 31 20:15:55 2013 by
|
184
184
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
185
185
|
0.8.3 (ruby-1.9.3).
|
186
186
|
</div>
|
data/doc/_index.html
CHANGED
@@ -312,7 +312,7 @@
|
|
312
312
|
</div>
|
313
313
|
|
314
314
|
<div id="footer">
|
315
|
-
Generated on
|
315
|
+
Generated on Thu Jan 31 20:15:55 2013 by
|
316
316
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
317
317
|
0.8.3 (ruby-1.9.3).
|
318
318
|
</div>
|
data/doc/file.README.html
CHANGED
@@ -102,7 +102,7 @@ See documentation for more informations.</p>
|
|
102
102
|
</div></div>
|
103
103
|
|
104
104
|
<div id="footer">
|
105
|
-
Generated on
|
105
|
+
Generated on Thu Jan 31 20:15:55 2013 by
|
106
106
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
107
107
|
0.8.3 (ruby-1.9.3).
|
108
108
|
</div>
|
data/doc/index.html
CHANGED
@@ -102,7 +102,7 @@ See documentation for more informations.</p>
|
|
102
102
|
</div></div>
|
103
103
|
|
104
104
|
<div id="footer">
|
105
|
-
Generated on
|
105
|
+
Generated on Thu Jan 31 20:15:55 2013 by
|
106
106
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
107
107
|
0.8.3 (ruby-1.9.3).
|
108
108
|
</div>
|
@@ -103,7 +103,7 @@
|
|
103
103
|
</div>
|
104
104
|
|
105
105
|
<div id="footer">
|
106
|
-
Generated on
|
106
|
+
Generated on Thu Jan 31 20:15:55 2013 by
|
107
107
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
108
108
|
0.8.3 (ruby-1.9.3).
|
109
109
|
</div>
|
data/lib/lazier.rb
CHANGED
@@ -89,16 +89,10 @@ module Lazier
|
|
89
89
|
def self.load_datetime
|
90
90
|
Lazier.load_object
|
91
91
|
|
92
|
-
::Time.
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
::Date.class_eval do
|
97
|
-
include ::Lazier::DateTime
|
98
|
-
end
|
99
|
-
|
100
|
-
::DateTime.class_eval do
|
101
|
-
include ::Lazier::DateTime
|
92
|
+
[::Time, ::Date, ::DateTime].each do |c|
|
93
|
+
c.class_eval do
|
94
|
+
include ::Lazier::DateTime
|
95
|
+
end
|
102
96
|
end
|
103
97
|
|
104
98
|
::ActiveSupport::TimeZone.class_eval do
|
data/lib/lazier/datetime.rb
CHANGED
@@ -125,9 +125,11 @@ module Lazier
|
|
125
125
|
year = ::Date.today.year if !year.is_integer?
|
126
126
|
|
127
127
|
# Compute using Anonymouse Gregorian Algorithm: http://en.wikipedia.org/wiki/Computus#Anonymous_Gregorian_algorithm
|
128
|
-
|
129
|
-
|
130
|
-
|
128
|
+
data = easter_start(year)
|
129
|
+
data = easter_part_1(data)
|
130
|
+
data = easter_part_2(year, data)
|
131
|
+
data = easter_part_3(year, data)
|
132
|
+
day, month = easter_end(data)
|
131
133
|
|
132
134
|
::Date.civil(year, month, day)
|
133
135
|
end
|
@@ -165,17 +167,16 @@ module Lazier
|
|
165
167
|
# Part one of Easter calculation.
|
166
168
|
#
|
167
169
|
# @param year [Fixnum] The year to compute the date for.
|
168
|
-
# @return [Array] Partial variables for
|
169
|
-
def
|
170
|
+
# @return [Array] Partial variables for #easter_part_1.
|
171
|
+
def easter_start(year)
|
170
172
|
[year % 19, (year / 100.0).floor, year % 100]
|
171
173
|
end
|
172
174
|
|
173
175
|
# Part two of Easter calculation.
|
174
|
-
#
|
175
|
-
# @
|
176
|
-
|
177
|
-
|
178
|
-
def easter_dependent(b, c)
|
176
|
+
# @param data [Fixnum] Partial variables from #easter_start.
|
177
|
+
# @return [Array] Partial variables for #easter_part_2.
|
178
|
+
def easter_part_1(data)
|
179
|
+
a, b, c = data
|
179
180
|
[
|
180
181
|
b - (b / 4.0).floor - ((b - ((b + 8) / 25.0).floor + 1) / 3.0).floor,
|
181
182
|
b % 4,
|
@@ -186,25 +187,30 @@ module Lazier
|
|
186
187
|
|
187
188
|
# Part three of Easter calculation.
|
188
189
|
#
|
189
|
-
# @param
|
190
|
-
# @
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
# @return [Array] Partial variables for calculus.
|
195
|
-
def easter_finalize(a, x, e, i, k)
|
190
|
+
# @param data [Fixnum] Partial variables from #easter_part_1.
|
191
|
+
# @return [Array] Partial variables for #easter_part_3.
|
192
|
+
def easter_part_2(year, data)
|
193
|
+
a = year % 19
|
194
|
+
x, e, i, k = data
|
196
195
|
h = ((19 * a) + x + 15) % 30
|
197
|
-
|
196
|
+
[h, (32 + (2 * e) + (2 * i) - h - k) % 7]
|
197
|
+
end
|
198
198
|
|
199
|
+
# Part four of Easter calculation
|
200
|
+
# @param data [Arrays] Partial variables from #easter_part_2.
|
201
|
+
# @return [Array] Partial variables for #easter_end.
|
202
|
+
def easter_part_3(year, data)
|
203
|
+
a = year % 19
|
204
|
+
h, l = data
|
199
205
|
[h, l, ((a + (11 * h) + (22 * l)) / 451.0).floor]
|
200
206
|
end
|
201
207
|
|
202
208
|
# Final part of Easter calculation.
|
203
209
|
#
|
204
|
-
# @param
|
205
|
-
# @return [Array] Day and month of Easter
|
206
|
-
def
|
207
|
-
h, l, m =
|
210
|
+
# @param data [Fixnum] Variable from #easter_part_3.
|
211
|
+
# @return [Array] Day and month of Easter day.
|
212
|
+
def easter_end(data)
|
213
|
+
h, l, m = data
|
208
214
|
[((h + l - (7 * m) + 114) % 31) + 1, ((h + l - (7 * m) + 114) / 31.0).floor]
|
209
215
|
end
|
210
216
|
end
|
@@ -244,10 +250,7 @@ module Lazier
|
|
244
250
|
# @param format [String] A format or a custom format name to use for formatting.
|
245
251
|
# @return [String] The formatted date.
|
246
252
|
def lstrftime(format = nil)
|
247
|
-
|
248
|
-
names = ::Lazier.settings.date_names
|
249
|
-
substitutions = {"%a" => names[:short_days][self.wday], "%A" => names[:long_days][self.wday], "%b" => names[:short_months][self.month - 1], "%B" => names[:long_months][self.month - 1]}
|
250
|
-
self.strftime(::DateTime.custom_format(format).ensure_string.gsub(/(?<!%)(%[ab])/i) {|mo| substitutions[mo] })
|
253
|
+
self.strftime(::DateTime.custom_format(format).ensure_string.gsub(/(?<!%)(%[ab])/i) {|mo| localize_time_component(mo) })
|
251
254
|
end
|
252
255
|
|
253
256
|
# Formats a datetime in the current timezone.
|
@@ -266,6 +269,17 @@ module Lazier
|
|
266
269
|
def local_lstrftime(format = nil)
|
267
270
|
(self.respond_to?(:in_time_zone) ? self.in_time_zone : self).lstrftime(format)
|
268
271
|
end
|
272
|
+
|
273
|
+
private
|
274
|
+
# Returns a component of the date in the current locale.
|
275
|
+
#
|
276
|
+
# @param component [String] The component to localize.
|
277
|
+
# @return [String] The localized component.
|
278
|
+
def localize_time_component(component)
|
279
|
+
type = {"%a" => :short_days, "%A" => :long_days, "%b" => :short_months, "%B" => :long_months}.fetch(component, "")
|
280
|
+
index = component =~ /%a/i ? self.wday : self.month - 1
|
281
|
+
::Lazier.settings.date_names.fetch(type, [])[index]
|
282
|
+
end
|
269
283
|
end
|
270
284
|
|
271
285
|
# Extensions for timezone objects.
|
@@ -319,9 +333,7 @@ module Lazier
|
|
319
333
|
dst_label ||= "(DST)"
|
320
334
|
|
321
335
|
@zones_names ||= { "STANDARD" => ::ActiveSupport::TimeZone.all.collect(&:to_s) }
|
322
|
-
@zones_names["DST[#{dst_label}]-STANDARD"] ||= ::ActiveSupport::TimeZone.all.collect { |zone|
|
323
|
-
zone.aliases.collect { |zone_alias| [zone.to_str(zone_alias), (zone.uses_dst? && zone_alias !~ /(#{Regexp.quote(dst_label)})$/) ? zone.to_str_with_dst(dst_label, nil, zone_alias) : nil] }
|
324
|
-
}.flatten.compact.uniq.sort { |a,b| ::ActiveSupport::TimeZone.compare(a, b) } # Sort by name
|
336
|
+
@zones_names["DST[#{dst_label}]-STANDARD"] ||= ::ActiveSupport::TimeZone.all.collect { |zone| fetch_aliases(zone, dst_label) }.flatten.compact.uniq.sort { |a,b| ::ActiveSupport::TimeZone.compare(a, b) } # Sort by name
|
325
337
|
|
326
338
|
@zones_names["#{with_dst ? "DST[#{dst_label}]-" : ""}STANDARD"]
|
327
339
|
end
|
@@ -381,20 +393,24 @@ module Lazier
|
|
381
393
|
right = right.to_str if right.is_a?(::ActiveSupport::TimeZone)
|
382
394
|
left.ensure_string.split(" ", 2)[1] <=> right.ensure_string.split(" ", 2)[1]
|
383
395
|
end
|
396
|
+
|
397
|
+
private
|
398
|
+
# Returns a list of aliases for a given time zone.
|
399
|
+
#
|
400
|
+
# @param zone [ActiveSupport::TimeZone] The zone.
|
401
|
+
# @param dst_label [String] Label for the DST indication. Defaults to `(DST)`.
|
402
|
+
def fetch_aliases(zone, dst_label = "(DST)")
|
403
|
+
zone.aliases.collect { |zone_alias|
|
404
|
+
[zone.to_str(zone_alias), (zone.uses_dst? && zone_alias !~ /(#{Regexp.quote(dst_label)})$/) ? zone.to_str_with_dst(dst_label, nil, zone_alias) : nil]
|
405
|
+
}
|
406
|
+
end
|
384
407
|
end
|
385
408
|
|
386
409
|
# Returns a list of valid aliases (city names) for this timezone (basing on offset).
|
387
410
|
# @return [Array] A list of aliases for this timezone
|
388
411
|
def aliases
|
389
412
|
reference = self.class::MAPPING.fetch(self.name, self.name).gsub("_", " ")
|
390
|
-
|
391
|
-
@aliases ||= ([reference] + self.class::MAPPING.collect { |name, zone|
|
392
|
-
if zone.gsub("_", " ") == reference then
|
393
|
-
(["International Date Line West", "UTC"].include?(name) || name.include?("(US & Canada)")) ? name : reference.gsub(/\/.*/, "/#{name}")
|
394
|
-
else
|
395
|
-
nil
|
396
|
-
end
|
397
|
-
}).uniq.compact.sort
|
413
|
+
@aliases ||= ([reference] + self.class::MAPPING.collect { |name, zone| format_alias(name, zone, reference) }).uniq.compact.sort
|
398
414
|
end
|
399
415
|
|
400
416
|
# Returns the current offset for this timezone, taking care of Daylight Saving Time (DST).
|
@@ -543,5 +559,20 @@ module Lazier
|
|
543
559
|
rv = self.to_str_with_dst(dst_label, year, name)
|
544
560
|
rv ? ::ActiveSupport::TimeZone.parameterize_zone(rv) : nil
|
545
561
|
end
|
562
|
+
|
563
|
+
private
|
564
|
+
# Formats a time zone alias.
|
565
|
+
#
|
566
|
+
# @param name [String] The zone name.
|
567
|
+
# @param zone [String] The zone.
|
568
|
+
# @param reference [String] The main name for the zone.
|
569
|
+
# @return [String|nil] The formatted alias.
|
570
|
+
def format_alias(name, zone, reference)
|
571
|
+
if zone.gsub("_", " ") == reference then
|
572
|
+
(["International Date Line West", "UTC"].include?(name) || name.include?("(US & Canada)")) ? name : reference.gsub(/\/.*/, "/#{name}")
|
573
|
+
else
|
574
|
+
nil
|
575
|
+
end
|
576
|
+
end
|
546
577
|
end
|
547
578
|
end
|
data/lib/lazier/i18n.rb
CHANGED
data/lib/lazier/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lazier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.5.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-02-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|