activesupport 5.0.7.2 → 5.1.7
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of activesupport might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +464 -694
- data/MIT-LICENSE +1 -1
- data/README.rdoc +1 -1
- data/lib/active_support.rb +8 -4
- data/lib/active_support/all.rb +3 -3
- data/lib/active_support/array_inquirer.rb +7 -5
- data/lib/active_support/backtrace_cleaner.rb +4 -4
- data/lib/active_support/benchmarkable.rb +3 -3
- data/lib/active_support/builder.rb +1 -1
- data/lib/active_support/cache.rb +41 -48
- data/lib/active_support/cache/file_store.rb +11 -20
- data/lib/active_support/cache/mem_cache_store.rb +30 -40
- data/lib/active_support/cache/memory_store.rb +13 -13
- data/lib/active_support/cache/null_store.rb +4 -4
- data/lib/active_support/cache/strategy/local_cache.rb +13 -22
- data/lib/active_support/cache/strategy/local_cache_middleware.rb +4 -5
- data/lib/active_support/callbacks.rb +649 -584
- data/lib/active_support/concurrency/load_interlock_aware_monitor.rb +17 -0
- data/lib/active_support/concurrency/share_lock.rb +20 -21
- data/lib/active_support/configurable.rb +5 -5
- data/lib/active_support/core_ext.rb +1 -2
- data/lib/active_support/core_ext/array.rb +7 -7
- data/lib/active_support/core_ext/array/access.rb +1 -1
- data/lib/active_support/core_ext/array/conversions.rb +15 -15
- data/lib/active_support/core_ext/array/grouping.rb +1 -1
- data/lib/active_support/core_ext/array/inquiry.rb +1 -1
- data/lib/active_support/core_ext/array/prepend_and_append.rb +1 -1
- data/lib/active_support/core_ext/benchmark.rb +1 -1
- data/lib/active_support/core_ext/big_decimal.rb +1 -1
- data/lib/active_support/core_ext/big_decimal/conversions.rb +4 -6
- data/lib/active_support/core_ext/class.rb +2 -2
- data/lib/active_support/core_ext/class/attribute.rb +5 -5
- data/lib/active_support/core_ext/class/attribute_accessors.rb +1 -1
- data/lib/active_support/core_ext/class/subclasses.rb +18 -4
- data/lib/active_support/core_ext/date.rb +5 -5
- data/lib/active_support/core_ext/date/acts_like.rb +1 -1
- data/lib/active_support/core_ext/date/blank.rb +1 -1
- data/lib/active_support/core_ext/date/calculations.rb +8 -8
- data/lib/active_support/core_ext/date/conversions.rb +12 -12
- data/lib/active_support/core_ext/date/zones.rb +2 -2
- data/lib/active_support/core_ext/date_and_time/calculations.rb +27 -22
- data/lib/active_support/core_ext/date_and_time/compatibility.rb +1 -1
- data/lib/active_support/core_ext/date_and_time/zones.rb +7 -8
- data/lib/active_support/core_ext/date_time.rb +5 -5
- data/lib/active_support/core_ext/date_time/acts_like.rb +2 -2
- data/lib/active_support/core_ext/date_time/blank.rb +1 -1
- data/lib/active_support/core_ext/date_time/calculations.rb +20 -10
- data/lib/active_support/core_ext/date_time/compatibility.rb +2 -2
- data/lib/active_support/core_ext/date_time/conversions.rb +12 -12
- data/lib/active_support/core_ext/digest/uuid.rb +4 -4
- data/lib/active_support/core_ext/enumerable.rb +23 -12
- data/lib/active_support/core_ext/file.rb +1 -1
- data/lib/active_support/core_ext/file/atomic.rb +4 -4
- data/lib/active_support/core_ext/hash.rb +9 -9
- data/lib/active_support/core_ext/hash/compact.rb +12 -9
- data/lib/active_support/core_ext/hash/conversions.rb +36 -37
- data/lib/active_support/core_ext/hash/indifferent_access.rb +1 -2
- data/lib/active_support/core_ext/hash/keys.rb +6 -6
- data/lib/active_support/core_ext/hash/reverse_merge.rb +1 -1
- data/lib/active_support/core_ext/hash/slice.rb +4 -4
- data/lib/active_support/core_ext/hash/transform_values.rb +1 -0
- data/lib/active_support/core_ext/integer.rb +3 -3
- data/lib/active_support/core_ext/integer/inflections.rb +1 -1
- data/lib/active_support/core_ext/integer/time.rb +2 -2
- data/lib/active_support/core_ext/kernel.rb +4 -4
- data/lib/active_support/core_ext/kernel/concern.rb +1 -1
- data/lib/active_support/core_ext/kernel/reporting.rb +1 -1
- data/lib/active_support/core_ext/load_error.rb +1 -18
- data/lib/active_support/core_ext/module.rb +11 -12
- data/lib/active_support/core_ext/module/aliasing.rb +3 -48
- data/lib/active_support/core_ext/module/attr_internal.rb +4 -4
- data/lib/active_support/core_ext/module/attribute_accessors.rb +11 -5
- data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +20 -13
- data/lib/active_support/core_ext/module/concerning.rb +1 -1
- data/lib/active_support/core_ext/module/delegation.rb +85 -16
- data/lib/active_support/core_ext/module/introspection.rb +3 -11
- data/lib/active_support/core_ext/module/reachable.rb +2 -2
- data/lib/active_support/core_ext/numeric.rb +4 -4
- data/lib/active_support/core_ext/numeric/conversions.rb +3 -9
- data/lib/active_support/core_ext/numeric/inquiry.rb +21 -21
- data/lib/active_support/core_ext/numeric/time.rb +5 -5
- data/lib/active_support/core_ext/object.rb +12 -12
- data/lib/active_support/core_ext/object/blank.rb +3 -1
- data/lib/active_support/core_ext/object/conversions.rb +4 -4
- data/lib/active_support/core_ext/object/deep_dup.rb +1 -1
- data/lib/active_support/core_ext/object/duplicable.rb +34 -4
- data/lib/active_support/core_ext/object/inclusion.rb +1 -1
- data/lib/active_support/core_ext/object/json.rb +26 -12
- data/lib/active_support/core_ext/object/to_param.rb +1 -1
- data/lib/active_support/core_ext/object/to_query.rb +8 -5
- data/lib/active_support/core_ext/object/try.rb +1 -1
- data/lib/active_support/core_ext/object/with_options.rb +12 -1
- data/lib/active_support/core_ext/range.rb +4 -4
- data/lib/active_support/core_ext/range/conversions.rb +1 -1
- data/lib/active_support/core_ext/regexp.rb +4 -0
- data/lib/active_support/core_ext/securerandom.rb +3 -3
- data/lib/active_support/core_ext/string.rb +13 -13
- data/lib/active_support/core_ext/string/access.rb +6 -6
- data/lib/active_support/core_ext/string/conversions.rb +2 -2
- data/lib/active_support/core_ext/string/filters.rb +3 -3
- data/lib/active_support/core_ext/string/indent.rb +4 -4
- data/lib/active_support/core_ext/string/inflections.rb +10 -14
- data/lib/active_support/core_ext/string/inquiry.rb +1 -1
- data/lib/active_support/core_ext/string/multibyte.rb +1 -1
- data/lib/active_support/core_ext/string/output_safety.rb +19 -20
- data/lib/active_support/core_ext/string/strip.rb +1 -1
- data/lib/active_support/core_ext/string/zones.rb +2 -2
- data/lib/active_support/core_ext/time.rb +5 -5
- data/lib/active_support/core_ext/time/acts_like.rb +1 -1
- data/lib/active_support/core_ext/time/calculations.rb +46 -29
- data/lib/active_support/core_ext/time/conversions.rb +15 -12
- data/lib/active_support/core_ext/time/zones.rb +3 -3
- data/lib/active_support/core_ext/uri.rb +2 -2
- data/lib/active_support/dependencies.rb +45 -46
- data/lib/active_support/dependencies/interlock.rb +1 -1
- data/lib/active_support/deprecation.rb +9 -8
- data/lib/active_support/deprecation/behaviors.rb +3 -3
- data/lib/active_support/deprecation/constant_accessor.rb +50 -0
- data/lib/active_support/deprecation/instance_delegator.rb +2 -2
- data/lib/active_support/deprecation/method_wrappers.rb +10 -3
- data/lib/active_support/deprecation/proxy_wrappers.rb +6 -4
- data/lib/active_support/deprecation/reporting.rb +7 -7
- data/lib/active_support/duration.rb +221 -28
- data/lib/active_support/duration/iso8601_parser.rb +66 -65
- data/lib/active_support/duration/iso8601_serializer.rb +11 -9
- data/lib/active_support/evented_file_update_checker.rb +59 -55
- data/lib/active_support/execution_wrapper.rb +3 -3
- data/lib/active_support/executor.rb +1 -1
- data/lib/active_support/file_update_checker.rb +54 -50
- data/lib/active_support/gem_version.rb +2 -2
- data/lib/active_support/gzip.rb +4 -4
- data/lib/active_support/hash_with_indifferent_access.rb +40 -28
- data/lib/active_support/i18n.rb +5 -5
- data/lib/active_support/i18n_railtie.rb +14 -9
- data/lib/active_support/inflections.rb +11 -11
- data/lib/active_support/inflector.rb +5 -5
- data/lib/active_support/inflector/inflections.rb +11 -9
- data/lib/active_support/inflector/methods.rb +52 -51
- data/lib/active_support/inflector/transliterate.rb +8 -11
- data/lib/active_support/json.rb +2 -2
- data/lib/active_support/json/decoding.rb +3 -3
- data/lib/active_support/json/encoding.rb +8 -7
- data/lib/active_support/key_generator.rb +17 -17
- data/lib/active_support/lazy_load_hooks.rb +2 -2
- data/lib/active_support/log_subscriber.rb +9 -7
- data/lib/active_support/log_subscriber/test_helper.rb +9 -9
- data/lib/active_support/logger.rb +3 -3
- data/lib/active_support/logger_silence.rb +3 -3
- data/lib/active_support/logger_thread_safe_level.rb +1 -1
- data/lib/active_support/message_encryptor.rb +77 -35
- data/lib/active_support/message_verifier.rb +7 -7
- data/lib/active_support/multibyte.rb +2 -2
- data/lib/active_support/multibyte/chars.rb +23 -21
- data/lib/active_support/multibyte/unicode.rb +68 -89
- data/lib/active_support/notifications.rb +7 -5
- data/lib/active_support/notifications/fanout.rb +3 -3
- data/lib/active_support/notifications/instrumenter.rb +5 -5
- data/lib/active_support/number_helper.rb +5 -4
- data/lib/active_support/number_helper/number_converter.rb +11 -11
- data/lib/active_support/number_helper/number_to_currency_converter.rb +3 -3
- data/lib/active_support/number_helper/number_to_delimited_converter.rb +1 -2
- data/lib/active_support/number_helper/number_to_human_converter.rb +8 -10
- data/lib/active_support/number_helper/number_to_human_size_converter.rb +6 -11
- data/lib/active_support/number_helper/number_to_percentage_converter.rb +1 -1
- data/lib/active_support/number_helper/number_to_phone_converter.rb +1 -3
- data/lib/active_support/number_helper/number_to_rounded_converter.rb +12 -32
- data/lib/active_support/number_helper/rounding_helper.rb +64 -0
- data/lib/active_support/option_merger.rb +1 -1
- data/lib/active_support/ordered_hash.rb +3 -3
- data/lib/active_support/ordered_options.rb +6 -4
- data/lib/active_support/per_thread_registry.rb +5 -5
- data/lib/active_support/rails.rb +12 -6
- data/lib/active_support/railtie.rb +3 -3
- data/lib/active_support/reloader.rb +1 -1
- data/lib/active_support/rescuable.rb +6 -6
- data/lib/active_support/security_utils.rb +1 -1
- data/lib/active_support/string_inquirer.rb +8 -2
- data/lib/active_support/subscriber.rb +9 -5
- data/lib/active_support/tagged_logging.rb +4 -4
- data/lib/active_support/test_case.rb +12 -29
- data/lib/active_support/testing/assertions.rb +100 -2
- data/lib/active_support/testing/autorun.rb +2 -2
- data/lib/active_support/testing/constant_lookup.rb +0 -1
- data/lib/active_support/testing/declarative.rb +1 -1
- data/lib/active_support/testing/deprecation.rb +3 -2
- data/lib/active_support/testing/isolation.rb +15 -22
- data/lib/active_support/testing/method_call_assertions.rb +1 -1
- data/lib/active_support/testing/setup_and_teardown.rb +2 -2
- data/lib/active_support/testing/stream.rb +28 -28
- data/lib/active_support/testing/tagged_logging.rb +1 -1
- data/lib/active_support/testing/time_helpers.rb +45 -11
- data/lib/active_support/time.rb +12 -12
- data/lib/active_support/time_with_zone.rb +16 -14
- data/lib/active_support/values/time_zone.rb +100 -31
- data/lib/active_support/values/unicode_tables.dat +0 -0
- data/lib/active_support/version.rb +1 -1
- data/lib/active_support/xml_mini.rb +34 -36
- data/lib/active_support/xml_mini/jdom.rb +112 -112
- data/lib/active_support/xml_mini/libxml.rb +12 -11
- data/lib/active_support/xml_mini/libxmlsax.rb +13 -14
- data/lib/active_support/xml_mini/nokogiri.rb +10 -10
- data/lib/active_support/xml_mini/nokogirisax.rb +12 -13
- data/lib/active_support/xml_mini/rexml.rb +9 -9
- metadata +8 -9
- data/lib/active_support/concurrency/latch.rb +0 -26
- data/lib/active_support/core_ext/kernel/debugger.rb +0 -3
- data/lib/active_support/core_ext/module/method_transplanting.rb +0 -3
- data/lib/active_support/core_ext/module/qualified_const.rb +0 -70
- data/lib/active_support/core_ext/struct.rb +0 -3
- data/lib/active_support/core_ext/time/marshal.rb +0 -3
@@ -1,15 +1,15 @@
|
|
1
|
-
require
|
1
|
+
require "active_support/core_ext/object/try"
|
2
2
|
|
3
3
|
module DateAndTime
|
4
4
|
module Calculations
|
5
5
|
DAYS_INTO_WEEK = {
|
6
|
-
:
|
7
|
-
:
|
8
|
-
:
|
9
|
-
:
|
10
|
-
:
|
11
|
-
:
|
12
|
-
:
|
6
|
+
monday: 0,
|
7
|
+
tuesday: 1,
|
8
|
+
wednesday: 2,
|
9
|
+
thursday: 3,
|
10
|
+
friday: 4,
|
11
|
+
saturday: 5,
|
12
|
+
sunday: 6
|
13
13
|
}
|
14
14
|
WEEKEND_DAYS = [ 6, 0 ]
|
15
15
|
|
@@ -60,42 +60,42 @@ module DateAndTime
|
|
60
60
|
|
61
61
|
# Returns a new date/time the specified number of days ago.
|
62
62
|
def days_ago(days)
|
63
|
-
advance(:
|
63
|
+
advance(days: -days)
|
64
64
|
end
|
65
65
|
|
66
66
|
# Returns a new date/time the specified number of days in the future.
|
67
67
|
def days_since(days)
|
68
|
-
advance(:
|
68
|
+
advance(days: days)
|
69
69
|
end
|
70
70
|
|
71
71
|
# Returns a new date/time the specified number of weeks ago.
|
72
72
|
def weeks_ago(weeks)
|
73
|
-
advance(:
|
73
|
+
advance(weeks: -weeks)
|
74
74
|
end
|
75
75
|
|
76
76
|
# Returns a new date/time the specified number of weeks in the future.
|
77
77
|
def weeks_since(weeks)
|
78
|
-
advance(:
|
78
|
+
advance(weeks: weeks)
|
79
79
|
end
|
80
80
|
|
81
81
|
# Returns a new date/time the specified number of months ago.
|
82
82
|
def months_ago(months)
|
83
|
-
advance(:
|
83
|
+
advance(months: -months)
|
84
84
|
end
|
85
85
|
|
86
86
|
# Returns a new date/time the specified number of months in the future.
|
87
87
|
def months_since(months)
|
88
|
-
advance(:
|
88
|
+
advance(months: months)
|
89
89
|
end
|
90
90
|
|
91
91
|
# Returns a new date/time the specified number of years ago.
|
92
92
|
def years_ago(years)
|
93
|
-
advance(:
|
93
|
+
advance(years: -years)
|
94
94
|
end
|
95
95
|
|
96
96
|
# Returns a new date/time the specified number of years in the future.
|
97
97
|
def years_since(years)
|
98
|
-
advance(:
|
98
|
+
advance(years: years)
|
99
99
|
end
|
100
100
|
|
101
101
|
# Returns a new date/time at the start of the month.
|
@@ -108,7 +108,7 @@ module DateAndTime
|
|
108
108
|
# now = DateTime.current # => Thu, 18 Jun 2015 15:23:13 +0000
|
109
109
|
# now.beginning_of_month # => Mon, 01 Jun 2015 00:00:00 +0000
|
110
110
|
def beginning_of_month
|
111
|
-
first_hour(change(:
|
111
|
+
first_hour(change(day: 1))
|
112
112
|
end
|
113
113
|
alias :at_beginning_of_month :beginning_of_month
|
114
114
|
|
@@ -123,7 +123,7 @@ module DateAndTime
|
|
123
123
|
# now.beginning_of_quarter # => Wed, 01 Jul 2015 00:00:00 +0000
|
124
124
|
def beginning_of_quarter
|
125
125
|
first_quarter_month = [10, 7, 4, 1].detect { |m| m <= month }
|
126
|
-
beginning_of_month.change(:
|
126
|
+
beginning_of_month.change(month: first_quarter_month)
|
127
127
|
end
|
128
128
|
alias :at_beginning_of_quarter :beginning_of_quarter
|
129
129
|
|
@@ -138,7 +138,7 @@ module DateAndTime
|
|
138
138
|
# now.end_of_quarter # => Wed, 30 Sep 2015 23:59:59 +0000
|
139
139
|
def end_of_quarter
|
140
140
|
last_quarter_month = [3, 6, 9, 12].detect { |m| m >= month }
|
141
|
-
beginning_of_month.change(:
|
141
|
+
beginning_of_month.change(month: last_quarter_month).end_of_month
|
142
142
|
end
|
143
143
|
alias :at_end_of_quarter :end_of_quarter
|
144
144
|
|
@@ -152,7 +152,7 @@ module DateAndTime
|
|
152
152
|
# now = DateTime.current # => Fri, 10 Jul 2015 18:41:29 +0000
|
153
153
|
# now.beginning_of_year # => Thu, 01 Jan 2015 00:00:00 +0000
|
154
154
|
def beginning_of_year
|
155
|
-
change(:
|
155
|
+
change(month: 1).beginning_of_month
|
156
156
|
end
|
157
157
|
alias :at_beginning_of_year :beginning_of_year
|
158
158
|
|
@@ -290,12 +290,17 @@ module DateAndTime
|
|
290
290
|
# Returns a new date/time representing the end of the year.
|
291
291
|
# DateTime objects will have a time set to 23:59:59.
|
292
292
|
def end_of_year
|
293
|
-
change(:
|
293
|
+
change(month: 12).end_of_month
|
294
294
|
end
|
295
295
|
alias :at_end_of_year :end_of_year
|
296
296
|
|
297
|
+
# Returns a Range representing the whole day of the current date/time.
|
298
|
+
def all_day
|
299
|
+
beginning_of_day..end_of_day
|
300
|
+
end
|
301
|
+
|
297
302
|
# Returns a Range representing the whole week of the current date/time.
|
298
|
-
# Week starts on start_day, default is <tt>Date.
|
303
|
+
# Week starts on start_day, default is <tt>Date.beginning_of_week</tt> or <tt>config.beginning_of_week</tt> when set.
|
299
304
|
def all_week(start_day = Date.beginning_of_week)
|
300
305
|
beginning_of_week(start_day)..end_of_week(start_day)
|
301
306
|
end
|
@@ -22,19 +22,18 @@ module DateAndTime
|
|
22
22
|
if time_zone
|
23
23
|
time_with_zone(time, time_zone)
|
24
24
|
else
|
25
|
-
time ||
|
25
|
+
time || to_time
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
29
|
private
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
31
|
+
def time_with_zone(time, zone)
|
32
|
+
if time
|
33
|
+
ActiveSupport::TimeWithZone.new(time.utc? ? time : time.getutc, zone)
|
34
|
+
else
|
35
|
+
ActiveSupport::TimeWithZone.new(nil, zone, to_time(:utc))
|
36
|
+
end
|
36
37
|
end
|
37
|
-
end
|
38
38
|
end
|
39
39
|
end
|
40
|
-
|
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
1
|
+
require "active_support/core_ext/date_time/acts_like"
|
2
|
+
require "active_support/core_ext/date_time/blank"
|
3
|
+
require "active_support/core_ext/date_time/calculations"
|
4
|
+
require "active_support/core_ext/date_time/compatibility"
|
5
|
+
require "active_support/core_ext/date_time/conversions"
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "date"
|
2
2
|
|
3
3
|
class DateTime
|
4
4
|
class << self
|
@@ -47,13 +47,23 @@ class DateTime
|
|
47
47
|
# DateTime.new(2012, 8, 29, 22, 35, 0).change(year: 1981, day: 1) # => DateTime.new(1981, 8, 1, 22, 35, 0)
|
48
48
|
# DateTime.new(2012, 8, 29, 22, 35, 0).change(year: 1981, hour: 0) # => DateTime.new(1981, 8, 29, 0, 0, 0)
|
49
49
|
def change(options)
|
50
|
+
if new_nsec = options[:nsec]
|
51
|
+
raise ArgumentError, "Can't change both :nsec and :usec at the same time: #{options.inspect}" if options[:usec]
|
52
|
+
new_fraction = Rational(new_nsec, 1000000000)
|
53
|
+
else
|
54
|
+
new_usec = options.fetch(:usec, (options[:hour] || options[:min] || options[:sec]) ? 0 : Rational(nsec, 1000))
|
55
|
+
new_fraction = Rational(new_usec, 1000000)
|
56
|
+
end
|
57
|
+
|
58
|
+
raise ArgumentError, "argument out of range" if new_fraction >= 1
|
59
|
+
|
50
60
|
::DateTime.civil(
|
51
61
|
options.fetch(:year, year),
|
52
62
|
options.fetch(:month, month),
|
53
63
|
options.fetch(:day, day),
|
54
64
|
options.fetch(:hour, hour),
|
55
65
|
options.fetch(:min, options[:hour] ? 0 : min),
|
56
|
-
options.fetch(:sec, (options[:hour] || options[:min]) ? 0 : sec +
|
66
|
+
options.fetch(:sec, (options[:hour] || options[:min]) ? 0 : sec) + new_fraction,
|
57
67
|
options.fetch(:offset, offset),
|
58
68
|
options.fetch(:start, start)
|
59
69
|
)
|
@@ -75,7 +85,7 @@ class DateTime
|
|
75
85
|
end
|
76
86
|
|
77
87
|
d = to_date.advance(options)
|
78
|
-
datetime_advanced_by_date = change(:
|
88
|
+
datetime_advanced_by_date = change(year: d.year, month: d.month, day: d.day)
|
79
89
|
seconds_to_advance = \
|
80
90
|
options.fetch(:seconds, 0) +
|
81
91
|
options.fetch(:minutes, 0) * 60 +
|
@@ -104,7 +114,7 @@ class DateTime
|
|
104
114
|
|
105
115
|
# Returns a new DateTime representing the start of the day (0:00).
|
106
116
|
def beginning_of_day
|
107
|
-
change(:
|
117
|
+
change(hour: 0)
|
108
118
|
end
|
109
119
|
alias :midnight :beginning_of_day
|
110
120
|
alias :at_midnight :beginning_of_day
|
@@ -112,7 +122,7 @@ class DateTime
|
|
112
122
|
|
113
123
|
# Returns a new DateTime representing the middle of the day (12:00)
|
114
124
|
def middle_of_day
|
115
|
-
change(:
|
125
|
+
change(hour: 12)
|
116
126
|
end
|
117
127
|
alias :midday :middle_of_day
|
118
128
|
alias :noon :middle_of_day
|
@@ -122,31 +132,31 @@ class DateTime
|
|
122
132
|
|
123
133
|
# Returns a new DateTime representing the end of the day (23:59:59).
|
124
134
|
def end_of_day
|
125
|
-
change(:
|
135
|
+
change(hour: 23, min: 59, sec: 59, usec: Rational(999999999, 1000))
|
126
136
|
end
|
127
137
|
alias :at_end_of_day :end_of_day
|
128
138
|
|
129
139
|
# Returns a new DateTime representing the start of the hour (hh:00:00).
|
130
140
|
def beginning_of_hour
|
131
|
-
change(:
|
141
|
+
change(min: 0)
|
132
142
|
end
|
133
143
|
alias :at_beginning_of_hour :beginning_of_hour
|
134
144
|
|
135
145
|
# Returns a new DateTime representing the end of the hour (hh:59:59).
|
136
146
|
def end_of_hour
|
137
|
-
change(:
|
147
|
+
change(min: 59, sec: 59, usec: Rational(999999999, 1000))
|
138
148
|
end
|
139
149
|
alias :at_end_of_hour :end_of_hour
|
140
150
|
|
141
151
|
# Returns a new DateTime representing the start of the minute (hh:mm:00).
|
142
152
|
def beginning_of_minute
|
143
|
-
change(:
|
153
|
+
change(sec: 0)
|
144
154
|
end
|
145
155
|
alias :at_beginning_of_minute :beginning_of_minute
|
146
156
|
|
147
157
|
# Returns a new DateTime representing the end of the minute (hh:mm:59).
|
148
158
|
def end_of_minute
|
149
|
-
change(:
|
159
|
+
change(sec: 59, usec: Rational(999999999, 1000))
|
150
160
|
end
|
151
161
|
alias :at_end_of_minute :end_of_minute
|
152
162
|
|
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "active_support/core_ext/date_and_time/compatibility"
|
2
|
+
require "active_support/core_ext/module/remove_method"
|
3
3
|
|
4
4
|
class DateTime
|
5
5
|
include DateAndTime::Compatibility
|
@@ -1,8 +1,8 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
1
|
+
require "date"
|
2
|
+
require "active_support/inflector/methods"
|
3
|
+
require "active_support/core_ext/time/conversions"
|
4
|
+
require "active_support/core_ext/date_time/calculations"
|
5
|
+
require "active_support/values/time_zone"
|
6
6
|
|
7
7
|
class DateTime
|
8
8
|
# Convert to a formatted string. See Time::DATE_FORMATS for predefined formats.
|
@@ -64,7 +64,7 @@ class DateTime
|
|
64
64
|
# # => Sun, 01 Jan 2012 00:00:00 +0300
|
65
65
|
# DateTime.civil_from_format :local, 2012, 12, 17
|
66
66
|
# # => Mon, 17 Dec 2012 00:00:00 +0000
|
67
|
-
def self.civil_from_format(utc_or_local, year, month=1, day=1, hour=0, min=0, sec=0)
|
67
|
+
def self.civil_from_format(utc_or_local, year, month = 1, day = 1, hour = 0, min = 0, sec = 0)
|
68
68
|
if utc_or_local.to_sym == :local
|
69
69
|
offset = ::Time.local(year, month, day).utc_offset.to_r / 86400
|
70
70
|
else
|
@@ -95,11 +95,11 @@ class DateTime
|
|
95
95
|
|
96
96
|
private
|
97
97
|
|
98
|
-
|
99
|
-
|
100
|
-
|
98
|
+
def offset_in_seconds
|
99
|
+
(offset * 86400).to_i
|
100
|
+
end
|
101
101
|
|
102
|
-
|
103
|
-
|
104
|
-
|
102
|
+
def seconds_since_unix_epoch
|
103
|
+
(jd - 2440588) * 86400 - offset_in_seconds + seconds_since_midnight
|
104
|
+
end
|
105
105
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "securerandom"
|
2
2
|
|
3
3
|
module Digest
|
4
4
|
module UUID
|
@@ -26,7 +26,7 @@ module Digest
|
|
26
26
|
hash.update(uuid_namespace)
|
27
27
|
hash.update(name)
|
28
28
|
|
29
|
-
ary = hash.digest.unpack(
|
29
|
+
ary = hash.digest.unpack("NnnnnN")
|
30
30
|
ary[2] = (ary[2] & 0x0FFF) | (version << 12)
|
31
31
|
ary[3] = (ary[3] & 0x3FFF) | 0x8000
|
32
32
|
|
@@ -35,12 +35,12 @@ module Digest
|
|
35
35
|
|
36
36
|
# Convenience method for uuid_from_hash using Digest::MD5.
|
37
37
|
def self.uuid_v3(uuid_namespace, name)
|
38
|
-
|
38
|
+
uuid_from_hash(Digest::MD5, uuid_namespace, name)
|
39
39
|
end
|
40
40
|
|
41
41
|
# Convenience method for uuid_from_hash using Digest::SHA1.
|
42
42
|
def self.uuid_v5(uuid_namespace, name)
|
43
|
-
|
43
|
+
uuid_from_hash(Digest::SHA1, uuid_namespace, name)
|
44
44
|
end
|
45
45
|
|
46
46
|
# Convenience method for SecureRandom.uuid.
|
@@ -51,12 +51,14 @@ module Enumerable
|
|
51
51
|
# Convert an enumerable to a hash.
|
52
52
|
#
|
53
53
|
# people.index_by(&:login)
|
54
|
-
#
|
54
|
+
# # => { "nextangle" => <Person ...>, "chade-" => <Person ...>, ...}
|
55
55
|
# people.index_by { |person| "#{person.first_name} #{person.last_name}" }
|
56
|
-
#
|
56
|
+
# # => { "Chade- Fowlersburg-e" => <Person ...>, "David Heinemeier Hansson" => <Person ...>, ...}
|
57
57
|
def index_by
|
58
58
|
if block_given?
|
59
|
-
|
59
|
+
result = {}
|
60
|
+
each { |elem| result[yield(elem)] = elem }
|
61
|
+
result
|
60
62
|
else
|
61
63
|
to_enum(:index_by) { size if respond_to?(:size) }
|
62
64
|
end
|
@@ -87,10 +89,10 @@ module Enumerable
|
|
87
89
|
# Returns a copy of the enumerable without the specified elements.
|
88
90
|
#
|
89
91
|
# ["David", "Rafael", "Aaron", "Todd"].without "Aaron", "Todd"
|
90
|
-
#
|
92
|
+
# # => ["David", "Rafael"]
|
91
93
|
#
|
92
94
|
# {foo: 1, bar: 2, baz: 3}.without :bar
|
93
|
-
#
|
95
|
+
# # => {foo: 1, baz: 3}
|
94
96
|
def without(*elements)
|
95
97
|
reject { |element| elements.include?(element) }
|
96
98
|
end
|
@@ -98,10 +100,10 @@ module Enumerable
|
|
98
100
|
# Convert an enumerable to an array based on the given key.
|
99
101
|
#
|
100
102
|
# [{ name: "David" }, { name: "Rafael" }, { name: "Aaron" }].pluck(:name)
|
101
|
-
#
|
103
|
+
# # => ["David", "Rafael", "Aaron"]
|
102
104
|
#
|
103
105
|
# [{ id: 1, name: "David" }, { id: 2, name: "Rafael" }].pluck(:id, :name)
|
104
|
-
#
|
106
|
+
# # => [[1, "David"], [2, "Rafael"]]
|
105
107
|
def pluck(*keys)
|
106
108
|
if keys.many?
|
107
109
|
map { |element| keys.map { |key| element[key] } }
|
@@ -135,12 +137,21 @@ end
|
|
135
137
|
# and fall back to the compatible implementation, but that's much slower than
|
136
138
|
# just calling the compat method in the first place.
|
137
139
|
if Array.instance_methods(false).include?(:sum) && !(%w[a].sum rescue false)
|
138
|
-
|
139
|
-
|
140
|
+
# Using Refinements here in order not to expose our internal method
|
141
|
+
using Module.new {
|
142
|
+
refine Array do
|
143
|
+
alias :orig_sum :sum
|
144
|
+
end
|
145
|
+
}
|
140
146
|
|
141
|
-
|
142
|
-
|
143
|
-
|
147
|
+
class Array
|
148
|
+
def sum(init = nil, &block) #:nodoc:
|
149
|
+
if init.is_a?(Numeric) || first.is_a?(Numeric)
|
150
|
+
init ||= 0
|
151
|
+
orig_sum(init, &block)
|
152
|
+
else
|
153
|
+
super
|
154
|
+
end
|
144
155
|
end
|
145
156
|
end
|
146
157
|
end
|
@@ -1 +1 @@
|
|
1
|
-
require
|
1
|
+
require "active_support/core_ext/file/atomic"
|