lazier 1.0.7 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/doc/frames.html CHANGED
@@ -4,7 +4,7 @@
4
4
  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
5
  <head>
6
6
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
7
- <title>Documentation by YARD 0.8.2.1</title>
7
+ <title>Documentation by YARD 0.8.3</title>
8
8
  </head>
9
9
  <script type="text/javascript" charset="utf-8">
10
10
  window.onload = function() {
data/doc/index.html CHANGED
@@ -2,11 +2,11 @@
2
2
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
3
  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
4
  <head>
5
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
+ <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII" />
6
6
  <title>
7
7
  File: README
8
8
 
9
- &mdash; Documentation by YARD 0.8.2.1
9
+ &mdash; Documentation by YARD 0.8.3
10
10
 
11
11
  </title>
12
12
 
@@ -69,12 +69,14 @@
69
69
 
70
70
  <p>Several Ruby object enhancements.</p>
71
71
 
72
- <p><a href="http://github.com/ShogunPanda/lazier">http://github.com/ShogunPanda/lazier</a></p>
72
+ <p><a href="http://sw.cow.tc/lazier">http://sw.cow.tc/lazier</a></p>
73
+
74
+ <p><a href="http://rdoc.info/gems/lazier">http://rdoc.info/gems/lazier</a></p>
73
75
 
74
76
  <h2>Usage</h2>
75
77
 
76
- <pre class="code ruby"><code><span class='rubyid_require identifier id'>require</span> <span class='string val'>&quot;lazier&quot;</span>
77
- <span class='rubyid_Lazier constant id'>Lazier</span><span class='dot token'>.</span><span class='rubyid_load! fid id'>load!</span>
78
+ <pre class="code ruby"><code><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>lazier</span><span class='tstring_end'>&quot;</span></span>
79
+ <span class='const'>Lazier</span><span class='period'>.</span><span class='id identifier rubyid_load!'>load!</span>
78
80
  </code></pre>
79
81
 
80
82
  <p>That&#39;s all!
@@ -94,14 +96,15 @@ See documentation for more informations.</p>
94
96
 
95
97
  <h2>Copyright</h2>
96
98
 
97
- <p>Copyright (C) 2013 and above Shogun <shogun_panda@me.com>.
98
- Licensed under the MIT license, which can be found at <a href="http://www.opensource.org/licenses/mit-license.php">http://www.opensource.org/licenses/mit-license.php</a>.</p>
99
+ <p>Copyright (C) 2013 and above Shogun (<a href="mailto:shogun_panda@me.com">shogun_panda@me.com</a>).</p>
100
+
101
+ <p>Licensed under the MIT license, which can be found at <a href="http://www.opensource.org/licenses/mit-license.php">http://www.opensource.org/licenses/mit-license.php</a>.</p>
99
102
  </div></div>
100
103
 
101
104
  <div id="footer">
102
- Generated on Wed Jan 16 10:02:55 2013 by
105
+ Generated on Mon Jan 28 20:23:45 2013 by
103
106
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
104
- 0.8.2.1 (ruby-1.8.7).
107
+ 0.8.3 (ruby-1.9.3).
105
108
  </div>
106
109
 
107
110
  </body>
data/doc/method_list.html CHANGED
@@ -215,17 +215,17 @@
215
215
 
216
216
 
217
217
  <li class="r2 ">
218
- <span class='object_link'><a href="Lazier/Settings.html#format_number-instance_method" title="Lazier::Settings#format_number (method)">#format_number</a></span>
218
+ <span class='object_link'><a href="Lazier/Object.html#format_number-instance_method" title="Lazier::Object#format_number (method)">#format_number</a></span>
219
219
 
220
- <small>Lazier::Settings</small>
220
+ <small>Lazier::Object</small>
221
221
 
222
222
  </li>
223
223
 
224
224
 
225
225
  <li class="r1 ">
226
- <span class='object_link'><a href="Lazier/Object.html#format_number-instance_method" title="Lazier::Object#format_number (method)">#format_number</a></span>
226
+ <span class='object_link'><a href="Lazier/Settings.html#format_number-instance_method" title="Lazier::Settings#format_number (method)">#format_number</a></span>
227
227
 
228
- <small>Lazier::Object</small>
228
+ <small>Lazier::Settings</small>
229
229
 
230
230
  </li>
231
231
 
@@ -295,39 +295,87 @@
295
295
 
296
296
 
297
297
  <li class="r2 ">
298
- <span class='object_link'><a href="Lazier.html#is_ruby_18%3F-class_method" title="Lazier.is_ruby_18? (method)">is_ruby_18?</a></span>
298
+ <span class='object_link'><a href="Lazier/DateTime/ClassMethods.html#is_valid%3F-instance_method" title="Lazier::DateTime::ClassMethods#is_valid? (method)">#is_valid?</a></span>
299
299
 
300
- <small>Lazier</small>
300
+ <small>Lazier::DateTime::ClassMethods</small>
301
301
 
302
302
  </li>
303
303
 
304
304
 
305
305
  <li class="r1 ">
306
- <span class='object_link'><a href="Lazier/DateTime/ClassMethods.html#is_valid%3F-instance_method" title="Lazier::DateTime::ClassMethods#is_valid? (method)">#is_valid?</a></span>
306
+ <span class='object_link'><a href="Lazier/TimeZone/ClassMethods.html#list_all-instance_method" title="Lazier::TimeZone::ClassMethods#list_all (method)">#list_all</a></span>
307
+
308
+ <small>Lazier::TimeZone::ClassMethods</small>
309
+
310
+ </li>
311
+
312
+
313
+ <li class="r2 ">
314
+ <span class='object_link'><a href="Lazier/DateTime/ClassMethods.html#list_timezones-instance_method" title="Lazier::DateTime::ClassMethods#list_timezones (method)">#list_timezones</a></span>
307
315
 
308
316
  <small>Lazier::DateTime::ClassMethods</small>
309
317
 
310
318
  </li>
311
319
 
312
320
 
321
+ <li class="r1 ">
322
+ <span class='object_link'><a href="Lazier.html#load%21-class_method" title="Lazier.load! (method)">load!</a></span>
323
+
324
+ <small>Lazier</small>
325
+
326
+ </li>
327
+
328
+
313
329
  <li class="r2 ">
314
- <span class='object_link'><a href="Lazier/TimeZone/ClassMethods.html#list_all-instance_method" title="Lazier::TimeZone::ClassMethods#list_all (method)">#list_all</a></span>
330
+ <span class='object_link'><a href="Lazier.html#load_boolean-class_method" title="Lazier.load_boolean (method)">load_boolean</a></span>
315
331
 
316
- <small>Lazier::TimeZone::ClassMethods</small>
332
+ <small>Lazier</small>
317
333
 
318
334
  </li>
319
335
 
320
336
 
321
337
  <li class="r1 ">
322
- <span class='object_link'><a href="Lazier/DateTime/ClassMethods.html#list_timezones-instance_method" title="Lazier::DateTime::ClassMethods#list_timezones (method)">#list_timezones</a></span>
338
+ <span class='object_link'><a href="Lazier.html#load_datetime-class_method" title="Lazier.load_datetime (method)">load_datetime</a></span>
323
339
 
324
- <small>Lazier::DateTime::ClassMethods</small>
340
+ <small>Lazier</small>
325
341
 
326
342
  </li>
327
343
 
328
344
 
329
345
  <li class="r2 ">
330
- <span class='object_link'><a href="Lazier.html#load%21-class_method" title="Lazier.load! (method)">load!</a></span>
346
+ <span class='object_link'><a href="Lazier.html#load_hash-class_method" title="Lazier.load_hash (method)">load_hash</a></span>
347
+
348
+ <small>Lazier</small>
349
+
350
+ </li>
351
+
352
+
353
+ <li class="r1 ">
354
+ <span class='object_link'><a href="Lazier.html#load_math-class_method" title="Lazier.load_math (method)">load_math</a></span>
355
+
356
+ <small>Lazier</small>
357
+
358
+ </li>
359
+
360
+
361
+ <li class="r2 ">
362
+ <span class='object_link'><a href="Lazier.html#load_object-class_method" title="Lazier.load_object (method)">load_object</a></span>
363
+
364
+ <small>Lazier</small>
365
+
366
+ </li>
367
+
368
+
369
+ <li class="r1 ">
370
+ <span class='object_link'><a href="Lazier.html#load_pathname-class_method" title="Lazier.load_pathname (method)">load_pathname</a></span>
371
+
372
+ <small>Lazier</small>
373
+
374
+ </li>
375
+
376
+
377
+ <li class="r2 ">
378
+ <span class='object_link'><a href="Lazier.html#load_string-class_method" title="Lazier.load_string (method)">load_string</a></span>
331
379
 
332
380
  <small>Lazier</small>
333
381
 
@@ -415,17 +463,17 @@
415
463
 
416
464
 
417
465
  <li class="r1 ">
418
- <span class='object_link'><a href="Lazier/TimeZone/ClassMethods.html#parameterize_zone-instance_method" title="Lazier::TimeZone::ClassMethods#parameterize_zone (method)">#parameterize_zone</a></span>
466
+ <span class='object_link'><a href="Lazier/DateTime/ClassMethods.html#parameterize_zone-instance_method" title="Lazier::DateTime::ClassMethods#parameterize_zone (method)">#parameterize_zone</a></span>
419
467
 
420
- <small>Lazier::TimeZone::ClassMethods</small>
468
+ <small>Lazier::DateTime::ClassMethods</small>
421
469
 
422
470
  </li>
423
471
 
424
472
 
425
473
  <li class="r2 ">
426
- <span class='object_link'><a href="Lazier/DateTime/ClassMethods.html#parameterize_zone-instance_method" title="Lazier::DateTime::ClassMethods#parameterize_zone (method)">#parameterize_zone</a></span>
474
+ <span class='object_link'><a href="Lazier/TimeZone/ClassMethods.html#parameterize_zone-instance_method" title="Lazier::TimeZone::ClassMethods#parameterize_zone (method)">#parameterize_zone</a></span>
427
475
 
428
- <small>Lazier::DateTime::ClassMethods</small>
476
+ <small>Lazier::TimeZone::ClassMethods</small>
429
477
 
430
478
  </li>
431
479
 
@@ -591,17 +639,17 @@
591
639
 
592
640
 
593
641
  <li class="r1 ">
594
- <span class='object_link'><a href="Lazier/DateTime/ClassMethods.html#unparameterize_zone-instance_method" title="Lazier::DateTime::ClassMethods#unparameterize_zone (method)">#unparameterize_zone</a></span>
642
+ <span class='object_link'><a href="Lazier/TimeZone/ClassMethods.html#unparameterize_zone-instance_method" title="Lazier::TimeZone::ClassMethods#unparameterize_zone (method)">#unparameterize_zone</a></span>
595
643
 
596
- <small>Lazier::DateTime::ClassMethods</small>
644
+ <small>Lazier::TimeZone::ClassMethods</small>
597
645
 
598
646
  </li>
599
647
 
600
648
 
601
649
  <li class="r2 ">
602
- <span class='object_link'><a href="Lazier/TimeZone/ClassMethods.html#unparameterize_zone-instance_method" title="Lazier::TimeZone::ClassMethods#unparameterize_zone (method)">#unparameterize_zone</a></span>
650
+ <span class='object_link'><a href="Lazier/DateTime/ClassMethods.html#unparameterize_zone-instance_method" title="Lazier::DateTime::ClassMethods#unparameterize_zone (method)">#unparameterize_zone</a></span>
603
651
 
604
- <small>Lazier::TimeZone::ClassMethods</small>
652
+ <small>Lazier::DateTime::ClassMethods</small>
605
653
 
606
654
  </li>
607
655
 
@@ -631,17 +679,17 @@
631
679
 
632
680
 
633
681
  <li class="r2 ">
634
- <span class='object_link'><a href="Lazier/String.html#value-instance_method" title="Lazier::String#value (method)">#value</a></span>
682
+ <span class='object_link'><a href="Lazier/Boolean.html#value-instance_method" title="Lazier::Boolean#value (method)">#value</a></span>
635
683
 
636
- <small>Lazier::String</small>
684
+ <small>Lazier::Boolean</small>
637
685
 
638
686
  </li>
639
687
 
640
688
 
641
689
  <li class="r1 ">
642
- <span class='object_link'><a href="Lazier/Boolean.html#value-instance_method" title="Lazier::Boolean#value (method)">#value</a></span>
690
+ <span class='object_link'><a href="Lazier/String.html#value-instance_method" title="Lazier::String#value (method)">#value</a></span>
643
691
 
644
- <small>Lazier::Boolean</small>
692
+ <small>Lazier::String</small>
645
693
 
646
694
  </li>
647
695
 
@@ -6,7 +6,7 @@
6
6
  <title>
7
7
  Top Level Namespace
8
8
 
9
- &mdash; Documentation by YARD 0.8.2.1
9
+ &mdash; Documentation by YARD 0.8.3
10
10
 
11
11
  </title>
12
12
 
@@ -103,9 +103,9 @@
103
103
  </div>
104
104
 
105
105
  <div id="footer">
106
- Generated on Wed Jan 16 10:02:55 2013 by
106
+ Generated on Mon Jan 28 20:23:45 2013 by
107
107
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
108
- 0.8.2.1 (ruby-1.8.7).
108
+ 0.8.3 (ruby-1.9.3).
109
109
  </div>
110
110
 
111
111
  </body>
data/lazier.gemspec CHANGED
@@ -22,15 +22,15 @@ Gem::Specification.new do |gem|
22
22
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
23
23
  gem.require_paths = ["lib"]
24
24
 
25
- gem.add_dependency("json", "~> 1.7.0")
26
- gem.add_dependency("actionpack", "~> 3.0")
27
- gem.add_dependency("tzinfo", "~> 0.3.0")
25
+ gem.add_dependency("json", "~> 1.7.6")
26
+ gem.add_dependency("actionpack", ">= 3.2.11") # We don't use ~> to enable use with 4.0
27
+ gem.add_dependency("tzinfo", "~> 0.3.35")
28
28
 
29
- gem.add_development_dependency("rspec", "~> 2.11.0")
30
- gem.add_development_dependency("rake", "~> 0.9.0")
31
- gem.add_development_dependency("simplecov", "~> 0.7.0")
29
+ gem.add_development_dependency("rspec", "~> 2.12.0")
30
+ gem.add_development_dependency("rake", "~> 10.0.3")
31
+ gem.add_development_dependency("simplecov", "~> 0.7.1")
32
32
  gem.add_development_dependency("pry", ">= 0")
33
- gem.add_development_dependency("yard", "~> 0.8.0")
33
+ gem.add_development_dependency("yard", "~> 0.8.3")
34
34
  gem.add_development_dependency("redcarpet", "~> 2.2.2")
35
- gem.add_development_dependency("github-markup", "~> 0.7.0")
35
+ gem.add_development_dependency("github-markup", "~> 0.7.5")
36
36
  end
data/lib/lazier.rb CHANGED
@@ -4,8 +4,6 @@
4
4
  # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
5
5
  #
6
6
 
7
- $KCODE='UTF8' if RUBY_VERSION < '1.9'
8
-
9
7
  require "json"
10
8
  require "tzinfo"
11
9
  require "active_support/all"
@@ -24,13 +22,6 @@ require "lazier/pathname"
24
22
 
25
23
  # Several Ruby object enhancements.
26
24
  module Lazier
27
- # Checks if we are running under Ruby 1.8
28
- #
29
- # @return [Boolean] `true` for Ruby 1.8, `false` otherwise.
30
- def self.is_ruby_18?
31
- RUBY_VERSION =~ /^1\.8/
32
- end
33
-
34
25
  # Returns the settings for the extensions
35
26
  #
36
27
  # @return [Settings] The settings for the extensions.
@@ -51,77 +42,82 @@ module Lazier
51
42
  # @return [Settings] The settings for the extensions.
52
43
  def self.load!(*what)
53
44
  what = ["object", "boolean", "string", "hash", "datetime", "math", "pathname"] if what.count == 0
54
- what.collect! { |w| w.to_s }
45
+ what.collect! { |w| Lazier.send("load_#{w}") }
55
46
 
56
- # Dependency resolving
57
- what << "object" if what.include?("datetime")
58
- what << "object" if what.include?("math")
59
- what.compact.uniq!
47
+ yield if block_given?
48
+ ::Lazier::Settings.instance
49
+ end
60
50
 
61
- if what.include?("object") then
62
- ::Object.class_eval do
63
- include ::Lazier::Object
64
- end
51
+ # Loads Object extensions.
52
+ def self.load_object
53
+ ::Object.class_eval do
54
+ include ::Lazier::Object
65
55
  end
56
+ end
66
57
 
67
- if what.include?("boolean") then
68
- ::TrueClass.class_eval do
69
- include ::Lazier::Object
70
- include ::Lazier::Boolean
71
- end
58
+ # Loads Boolean extensions.
59
+ def self.load_boolean
60
+ ::TrueClass.class_eval do
61
+ include ::Lazier::Object
62
+ include ::Lazier::Boolean
63
+ end
72
64
 
73
- ::FalseClass.class_eval do
74
- include ::Lazier::Object
75
- include ::Lazier::Boolean
76
- end
65
+ ::FalseClass.class_eval do
66
+ include ::Lazier::Object
67
+ include ::Lazier::Boolean
77
68
  end
69
+ end
78
70
 
79
- if what.include?("string") then
80
- ::String.class_eval do
81
- include ::Lazier::String
82
- end
71
+ # Loads String extensions.
72
+ def self.load_string
73
+ ::String.class_eval do
74
+ include ::Lazier::String
83
75
  end
76
+ end
84
77
 
85
- if what.include?("hash") then
86
- ::Hash.class_eval do
87
- include ::Lazier::Hash
88
- end
78
+ # Loads Hash extensions.
79
+ def self.load_hash
80
+ ::Hash.class_eval do
81
+ include ::Lazier::Hash
89
82
  end
83
+ end
90
84
 
91
- if what.include?("datetime") then
92
- ::Time.class_eval do
93
- include ::Lazier::DateTime
94
- end
85
+ # Loads DateTime extensions.
86
+ def self.load_datetime
87
+ Lazier.load_object
95
88
 
96
- ::Date.class_eval do
97
- include ::Lazier::DateTime
98
- end
89
+ ::Time.class_eval do
90
+ include ::Lazier::DateTime
91
+ end
99
92
 
100
- ::DateTime.class_eval do
101
- include ::Lazier::DateTime
102
- end
93
+ ::Date.class_eval do
94
+ include ::Lazier::DateTime
95
+ end
103
96
 
104
- ::ActiveSupport::TimeZone.class_eval do
105
- include ::Lazier::TimeZone
106
- end
97
+ ::DateTime.class_eval do
98
+ include ::Lazier::DateTime
107
99
  end
108
100
 
109
- if what.include?("math") then
110
- ::Math.class_eval do
111
- include ::Lazier::Math
112
- end
101
+ ::ActiveSupport::TimeZone.class_eval do
102
+ include ::Lazier::TimeZone
113
103
  end
104
+ end
114
105
 
115
- if what.include?("pathname") then
116
- require "pathname"
106
+ # Loads Math extensions.
107
+ def self.load_math
108
+ Lazier.load_object
117
109
 
118
- ::Pathname.class_eval do
119
- include ::Lazier::Pathname
120
- end
110
+ ::Math.class_eval do
111
+ include ::Lazier::Math
121
112
  end
113
+ end
122
114
 
123
- yield if block_given?
115
+ # Loads Pathname extensions.
116
+ def self.load_pathname
117
+ require "pathname"
124
118
 
125
- ::Lazier::Settings.instance
119
+ ::Pathname.class_eval do
120
+ include ::Lazier::Pathname
121
+ end
126
122
  end
127
123
  end
@@ -19,7 +19,7 @@ module Lazier
19
19
  def days(short = true)
20
20
  days = ::Lazier.settings.date_names[short ? :short_days : :long_days]
21
21
  (1..7).to_a.collect { |i|
22
- {:value => i.to_s, :label=> days[i - 1]}
22
+ {value: i.to_s, label: days[i - 1]}
23
23
  }
24
24
 
25
25
  end
@@ -32,7 +32,7 @@ module Lazier
32
32
  def months(short = true)
33
33
  months = ::Lazier.settings.date_names[short ? :short_months : :long_months]
34
34
  (1..12).collect { |i|
35
- {:value => i.to_s.rjust(2, "0"), :label=> months.at(i - 1)}
35
+ {value: i.to_s.rjust(2, "0"), label: months.at(i - 1)}
36
36
  }
37
37
  end
38
38
 
@@ -56,7 +56,7 @@ module Lazier
56
56
  # @return [Array] A range of years. Every entry is
57
57
  def years(offset = 10, also_future = true, reference = nil, as_objects = false)
58
58
  y = reference || ::Date.today.year
59
- (y - offset..(also_future ? y + offset : y)).collect { |year| as_objects ? {:value => year, :label => year} : year }
59
+ (y - offset..(also_future ? y + offset : y)).collect { |year| as_objects ? {value: year, label: year} : year }
60
60
  end
61
61
 
62
62
  # Returns all the availabe timezones.
@@ -125,21 +125,10 @@ 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
- a = year % 19
129
- b = (year / 100.0).floor
130
- c = year % 100
131
- d = (b / 4.0).floor
132
- e = b % 4
133
- f = ((b + 8) / 25.0).floor
134
- g = ((b - f + 1) / 3.0).floor
135
- h = ((19 * a) + b - d - g + 15) % 30
136
- i = (c / 4.0).floor
137
- k = c % 4
138
- l = (32 + (2 * e) + (2 * i) - h - k) % 7
139
- m = ((a + (11 * h) + (22 * l)) / 451.0).floor
140
-
141
- day = ((h + l - (7 * m) + 114) % 31) + 1
142
- month = ((h + l - (7 * m) + 114) / 31.0).floor
128
+ a, b, c = easter_independent(year)
129
+ x, e, i, k = easter_dependent(b, c)
130
+ day, month = easter_summarize(easter_finalize(a, x, e, i, k))
131
+
143
132
  ::Date.civil(year, month, day)
144
133
  end
145
134
 
@@ -171,6 +160,53 @@ module Lazier
171
160
 
172
161
  rv
173
162
  end
163
+
164
+ private
165
+ # Part one of Easter calculation.
166
+ #
167
+ # @param year [Fixnum] The year to compute the date for.
168
+ # @return [Array] Partial variables for calculus.
169
+ def easter_independent(year)
170
+ [year % 19, (year / 100.0).floor, year % 100]
171
+ end
172
+
173
+ # Part two of Easter calculation.
174
+ #
175
+ # @param b [Fixnum] Variable from #easter_independent.
176
+ # @param c [Fixnum] Variable from #easter_independent.
177
+ # @return [Array] Partial variables for calculus.
178
+ def easter_dependent(b, c)
179
+ [
180
+ b - (b / 4.0).floor - ((b - ((b + 8) / 25.0).floor + 1) / 3.0).floor,
181
+ b % 4,
182
+ (c / 4.0).floor,
183
+ c % 4
184
+ ]
185
+ end
186
+
187
+ # Part three of Easter calculation.
188
+ #
189
+ # @param a [Fixnum] Variable from #easter_independent.
190
+ # @param x [Fixnum] Variable from #easter_independent.
191
+ # @param e [Fixnum] Variable from #easter_dependent.
192
+ # @param i [Fixnum] Variable from #easter_dependent.
193
+ # @param k [Fixnum] Variable from #easter_dependent.
194
+ # @return [Array] Partial variables for calculus.
195
+ def easter_finalize(a, x, e, i, k)
196
+ h = ((19 * a) + x + 15) % 30
197
+ l = (32 + (2 * e) + (2 * i) - h - k) % 7
198
+
199
+ [h, l, ((a + (11 * h) + (22 * l)) / 451.0).floor]
200
+ end
201
+
202
+ # Final part of Easter calculation.
203
+ #
204
+ # @param prev [Fixnum] Variable from #easter_finalize.
205
+ # @return [Array] Day and month of Easter daye.
206
+ def easter_summarize(prev)
207
+ h, l, m = prev
208
+ [((h + l - (7 * m) + 114) % 31) + 1, ((h + l - (7 * m) + 114) / 31.0).floor]
209
+ end
174
210
  end
175
211
 
176
212
  # Returns the UTC::Time representation of the current datetime.
@@ -210,32 +246,8 @@ module Lazier
210
246
  def lstrftime(format = nil)
211
247
  rv = nil
212
248
  names = ::Lazier.settings.date_names
213
-
214
- final_format = ::DateTime.custom_format(format).ensure_string.gsub(/(%{1,2}:?[abz])/i) do |match|
215
- mrv = match
216
-
217
- # Handling of %z is to fix ruby 1.8 bug in OSX: http://bugs.ruby-lang.org/issues/2396
218
- if match !~ /^%%/ then
219
- case match
220
- when "%a"
221
- mrv = names[:short_days][self.wday]
222
- when "%A"
223
- mrv = names[:long_days][self.wday]
224
- when "%b"
225
- mrv = names[:short_months][self.month - 1]
226
- when "%B"
227
- mrv = names[:long_months][self.month - 1]
228
- when "%z"
229
- mrv = ::Lazier.is_ruby_18? ? self.formatted_offset(false) : nil
230
- when "%:z"
231
- mrv = ::Lazier.is_ruby_18? ? self.formatted_offset(true) : nil
232
- end
233
- end
234
-
235
- mrv ? mrv.sub("%", "%%") : match
236
- end
237
-
238
- self.strftime(final_format)
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] })
239
251
  end
240
252
 
241
253
  # Formats a datetime in the current timezone.
@@ -305,23 +317,13 @@ module Lazier
305
317
  # @return [Array] A list of names of timezones.
306
318
  def list_all(with_dst = true, dst_label = nil)
307
319
  dst_label ||= "(DST)"
308
- dst_key = "DST-#{dst_label}"
309
- @zones_names ||= { "STANDARD" => ::ActiveSupport::TimeZone.all.collect(&:to_s) }
310
-
311
- if with_dst && @zones_names[dst_key].blank? then
312
- @zones_names[dst_key] = []
313
-
314
- ::ActiveSupport::TimeZone.all.each do |zone|
315
- zone.aliases.each do |zone_alias|
316
- @zones_names[dst_key] << zone.to_str(zone_alias)
317
- @zones_names[dst_key] << zone.to_str_with_dst(dst_label, nil, zone_alias) if zone.uses_dst? && zone_alias !~ /(#{Regexp.quote(dst_label)})$/
318
- end
319
- end
320
320
 
321
- @zones_names[dst_key]= @zones_names[dst_key].uniq.compact.sort { |a,b| ::ActiveSupport::TimeZone.compare(a, b) } # Sort by name
322
- end
321
+ @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
323
325
 
324
- @zones_names[with_dst ? dst_key : "STANDARD"]
326
+ @zones_names["#{with_dst ? "DST[#{dst_label}]-" : ""}STANDARD"]
325
327
  end
326
328
 
327
329
  # Returns a string representation of a timezone.
@@ -382,32 +384,17 @@ module Lazier
382
384
  end
383
385
 
384
386
  # Returns a list of valid aliases (city names) for this timezone (basing on offset).
385
- #
386
- # @param dst_label [String] Label for the DST indication. Defaults to `(DST)`.
387
387
  # @return [Array] A list of aliases for this timezone
388
- def aliases(dst_label = nil)
389
- reference = self.name
390
- reference = self.class::MAPPING[self.name] if self.class::MAPPING.has_key?(self.name) # We are an alias
391
- reference = reference.gsub("_", " ")
392
-
393
- if @aliases.blank? then
394
- # First we search for aliases by name
395
- @aliases = [reference]
396
-
397
- self.class::MAPPING.each do |name, zone|
398
- if zone.gsub("_", " ") == reference then
399
- if name == "International Date Line West" || name == "UTC" || name.include?("(US & Canada)")
400
- @aliases << name
401
- else
402
- @aliases << reference.gsub(/\/.*/, "/" + name)
403
- end
404
- end
405
- end
388
+ def aliases
389
+ reference = self.class::MAPPING.fetch(self.name, self.name).gsub("_", " ")
406
390
 
407
- @aliases = @aliases.uniq.compact.sort
408
- end
409
-
410
- @aliases
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
411
398
  end
412
399
 
413
400
  # Returns the current offset for this timezone, taking care of Daylight Saving Time (DST).
@@ -479,19 +466,18 @@ module Lazier
479
466
  # @param year [Fixnum] The year to which refer to. Defaults to the current year.
480
467
  # @return [Fixnum|Rational] The correction for dst.
481
468
  def dst_correction(rational = false, year = nil)
482
- period = self.dst_period(year)
483
- rv = period ? period.std_offset : 0
484
- rational ? self.class.rationalize_offset(rv) : rv
469
+ self.dst_offset(rational, year, :std_offset)
485
470
  end
486
471
 
487
472
  # Returns the standard offset for this timezone timezone when the Daylight Saving Time (DST) is active.
488
473
  #
489
474
  # @param rational [Boolean] If to return the offset as a Rational.
490
475
  # @param year [Fixnum] The year to which refer to. Defaults to the current year.
476
+ # @param method [Symbol] The method to use for getting the offset. Default is total offset from UTC.
491
477
  # @return [Fixnum|Rational] The DST offset for this timezone or `0`, if the timezone doesn't use DST for that year.
492
- def dst_offset(rational = false, year = nil)
478
+ def dst_offset(rational = false, year = nil, method = :utc_total_offset)
493
479
  period = self.dst_period(year)
494
- rv = period ? period.utc_total_offset : 0
480
+ rv = period ? period.send(method) : 0
495
481
  rational ? self.class.rationalize_offset(rv) : rv
496
482
  end
497
483