csd 0.1.5 → 0.1.6
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/COPYING +1 -2
- data/README.rdoc +7 -1
- data/Rakefile +7 -2
- data/VERSION +1 -1
- data/csd.gemspec +18 -216
- data/lib/csd.rb +6 -16
- data/lib/csd/application.rb +2 -2
- data/lib/csd/application/default.rb +15 -14
- data/lib/csd/application/default/base.rb +1 -1
- data/lib/csd/application/minisip.rb +43 -11
- data/lib/csd/application/minisip/about.yml +5 -5
- data/lib/csd/application/minisip/base.rb +82 -70
- data/lib/csd/application/minisip/error.rb +1 -1
- data/lib/csd/application/minisip/options/common.rb +1 -1
- data/lib/csd/application/minisip/options/compile.rb +1 -1
- data/lib/csd/application/minisip/options/package.rb +1 -1
- data/lib/csd/application/minisip/unix.rb +40 -27
- data/lib/csd/application/minisip/unix/darwin.rb +12 -0
- data/lib/csd/application/minisip/unix/linux.rb +1 -11
- data/lib/csd/application/minisip/unix/linux/debian.rb +14 -25
- data/lib/csd/application/minisip/unix/linux/debian/ubuntu10.rb +12 -13
- data/lib/csd/applications.rb +5 -5
- data/lib/csd/commands.rb +164 -89
- data/lib/csd/container.rb +61 -0
- data/lib/csd/error.rb +10 -1
- data/lib/csd/extensions.rb +3 -2
- data/lib/csd/extensions/core/array.rb +29 -1
- data/lib/csd/extensions/core/dir.rb +15 -24
- data/lib/csd/extensions/core/object.rb +10 -2
- data/lib/csd/extensions/core/option_parser.rb +22 -3
- data/lib/csd/extensions/core/pathname.rb +30 -2
- data/lib/csd/extensions/core/string.rb +51 -4
- data/lib/csd/extensions/gem/platform.rb +18 -3
- data/lib/csd/{options.rb → options_parser.rb} +16 -20
- data/lib/csd/path_container.rb +24 -0
- data/lib/csd/user_interface.rb +2 -0
- data/lib/csd/user_interface/base.rb +26 -0
- data/lib/csd/user_interface/cli.rb +37 -0
- data/lib/csd/vendor/active_support/MIT-LICENSE +20 -0
- data/lib/csd/vendor/active_support/inflector.rb +155 -0
- data/lib/csd/vendor/term/GPL2-LICENSE +339 -0
- data/lib/csd/vendor/term/ansicolor.rb +113 -0
- data/lib/csd/version.rb +13 -4
- data/test/application/test_minisip.rb +45 -0
- data/test/functional/test_applications.rb +10 -16
- data/test/functional/test_commands.rb +260 -23
- data/test/unit/test_string.rb +1 -1
- metadata +18 -216
- data/lib/active_support.rb +0 -75
- data/lib/active_support/all.rb +0 -3
- data/lib/active_support/backtrace_cleaner.rb +0 -94
- data/lib/active_support/base64.rb +0 -42
- data/lib/active_support/basic_object.rb +0 -21
- data/lib/active_support/benchmarkable.rb +0 -60
- data/lib/active_support/buffered_logger.rb +0 -132
- data/lib/active_support/builder.rb +0 -6
- data/lib/active_support/cache.rb +0 -626
- data/lib/active_support/cache/compressed_mem_cache_store.rb +0 -13
- data/lib/active_support/cache/file_store.rb +0 -188
- data/lib/active_support/cache/mem_cache_store.rb +0 -191
- data/lib/active_support/cache/memory_store.rb +0 -159
- data/lib/active_support/cache/strategy/local_cache.rb +0 -164
- data/lib/active_support/cache/synchronized_memory_store.rb +0 -11
- data/lib/active_support/callbacks.rb +0 -600
- data/lib/active_support/concern.rb +0 -29
- data/lib/active_support/configurable.rb +0 -36
- data/lib/active_support/core_ext.rb +0 -3
- data/lib/active_support/core_ext/array.rb +0 -7
- data/lib/active_support/core_ext/array/access.rb +0 -46
- data/lib/active_support/core_ext/array/conversions.rb +0 -164
- data/lib/active_support/core_ext/array/extract_options.rb +0 -29
- data/lib/active_support/core_ext/array/grouping.rb +0 -100
- data/lib/active_support/core_ext/array/random_access.rb +0 -20
- data/lib/active_support/core_ext/array/uniq_by.rb +0 -17
- data/lib/active_support/core_ext/array/wrap.rb +0 -22
- data/lib/active_support/core_ext/benchmark.rb +0 -7
- data/lib/active_support/core_ext/big_decimal.rb +0 -1
- data/lib/active_support/core_ext/big_decimal/conversions.rb +0 -27
- data/lib/active_support/core_ext/cgi.rb +0 -1
- data/lib/active_support/core_ext/cgi/escape_skipping_slashes.rb +0 -19
- data/lib/active_support/core_ext/class.rb +0 -4
- data/lib/active_support/core_ext/class/attribute.rb +0 -67
- data/lib/active_support/core_ext/class/attribute_accessors.rb +0 -63
- data/lib/active_support/core_ext/class/delegating_attributes.rb +0 -44
- data/lib/active_support/core_ext/class/inheritable_attributes.rb +0 -232
- data/lib/active_support/core_ext/class/subclasses.rb +0 -55
- data/lib/active_support/core_ext/date/acts_like.rb +0 -8
- data/lib/active_support/core_ext/date/calculations.rb +0 -240
- data/lib/active_support/core_ext/date/conversions.rb +0 -99
- data/lib/active_support/core_ext/date/freeze.rb +0 -31
- data/lib/active_support/core_ext/date_time/acts_like.rb +0 -13
- data/lib/active_support/core_ext/date_time/calculations.rb +0 -113
- data/lib/active_support/core_ext/date_time/conversions.rb +0 -102
- data/lib/active_support/core_ext/date_time/zones.rb +0 -17
- data/lib/active_support/core_ext/enumerable.rb +0 -119
- data/lib/active_support/core_ext/exception.rb +0 -3
- data/lib/active_support/core_ext/file.rb +0 -2
- data/lib/active_support/core_ext/file/atomic.rb +0 -41
- data/lib/active_support/core_ext/file/path.rb +0 -5
- data/lib/active_support/core_ext/float.rb +0 -1
- data/lib/active_support/core_ext/float/rounding.rb +0 -19
- data/lib/active_support/core_ext/hash.rb +0 -8
- data/lib/active_support/core_ext/hash/conversions.rb +0 -150
- data/lib/active_support/core_ext/hash/deep_merge.rb +0 -16
- data/lib/active_support/core_ext/hash/diff.rb +0 -13
- data/lib/active_support/core_ext/hash/except.rb +0 -24
- data/lib/active_support/core_ext/hash/indifferent_access.rb +0 -14
- data/lib/active_support/core_ext/hash/keys.rb +0 -45
- data/lib/active_support/core_ext/hash/reverse_merge.rb +0 -28
- data/lib/active_support/core_ext/hash/slice.rb +0 -38
- data/lib/active_support/core_ext/integer.rb +0 -3
- data/lib/active_support/core_ext/integer/inflections.rb +0 -14
- data/lib/active_support/core_ext/integer/multiple.rb +0 -6
- data/lib/active_support/core_ext/integer/time.rb +0 -39
- data/lib/active_support/core_ext/kernel.rb +0 -5
- data/lib/active_support/core_ext/kernel/agnostics.rb +0 -11
- data/lib/active_support/core_ext/kernel/debugger.rb +0 -16
- data/lib/active_support/core_ext/kernel/reporting.rb +0 -62
- data/lib/active_support/core_ext/kernel/requires.rb +0 -26
- data/lib/active_support/core_ext/kernel/singleton_class.rb +0 -13
- data/lib/active_support/core_ext/load_error.rb +0 -23
- data/lib/active_support/core_ext/logger.rb +0 -146
- data/lib/active_support/core_ext/module.rb +0 -12
- data/lib/active_support/core_ext/module/aliasing.rb +0 -70
- data/lib/active_support/core_ext/module/anonymous.rb +0 -24
- data/lib/active_support/core_ext/module/attr_accessor_with_default.rb +0 -31
- data/lib/active_support/core_ext/module/attr_internal.rb +0 -32
- data/lib/active_support/core_ext/module/attribute_accessors.rb +0 -66
- data/lib/active_support/core_ext/module/delegation.rb +0 -146
- data/lib/active_support/core_ext/module/deprecation.rb +0 -9
- data/lib/active_support/core_ext/module/introspection.rb +0 -88
- data/lib/active_support/core_ext/module/method_names.rb +0 -14
- data/lib/active_support/core_ext/module/reachable.rb +0 -10
- data/lib/active_support/core_ext/module/remove_method.rb +0 -6
- data/lib/active_support/core_ext/module/synchronization.rb +0 -42
- data/lib/active_support/core_ext/name_error.rb +0 -18
- data/lib/active_support/core_ext/numeric.rb +0 -2
- data/lib/active_support/core_ext/numeric/bytes.rb +0 -44
- data/lib/active_support/core_ext/numeric/time.rb +0 -77
- data/lib/active_support/core_ext/object.rb +0 -14
- data/lib/active_support/core_ext/object/acts_like.rb +0 -10
- data/lib/active_support/core_ext/object/blank.rb +0 -76
- data/lib/active_support/core_ext/object/conversions.rb +0 -4
- data/lib/active_support/core_ext/object/duplicable.rb +0 -65
- data/lib/active_support/core_ext/object/extending.rb +0 -11
- data/lib/active_support/core_ext/object/instance_variables.rb +0 -67
- data/lib/active_support/core_ext/object/misc.rb +0 -2
- data/lib/active_support/core_ext/object/returning.rb +0 -42
- data/lib/active_support/core_ext/object/to_param.rb +0 -49
- data/lib/active_support/core_ext/object/to_query.rb +0 -27
- data/lib/active_support/core_ext/object/try.rb +0 -36
- data/lib/active_support/core_ext/object/with_options.rb +0 -26
- data/lib/active_support/core_ext/proc.rb +0 -14
- data/lib/active_support/core_ext/process.rb +0 -1
- data/lib/active_support/core_ext/process/daemon.rb +0 -23
- data/lib/active_support/core_ext/range.rb +0 -4
- data/lib/active_support/core_ext/range/blockless_step.rb +0 -29
- data/lib/active_support/core_ext/range/conversions.rb +0 -21
- data/lib/active_support/core_ext/range/include_range.rb +0 -21
- data/lib/active_support/core_ext/range/overlaps.rb +0 -8
- data/lib/active_support/core_ext/regexp.rb +0 -5
- data/lib/active_support/core_ext/rexml.rb +0 -46
- data/lib/active_support/core_ext/string.rb +0 -12
- data/lib/active_support/core_ext/string/access.rb +0 -99
- data/lib/active_support/core_ext/string/behavior.rb +0 -7
- data/lib/active_support/core_ext/string/conversions.rb +0 -61
- data/lib/active_support/core_ext/string/encoding.rb +0 -11
- data/lib/active_support/core_ext/string/exclude.rb +0 -6
- data/lib/active_support/core_ext/string/filters.rb +0 -49
- data/lib/active_support/core_ext/string/inflections.rb +0 -149
- data/lib/active_support/core_ext/string/interpolation.rb +0 -2
- data/lib/active_support/core_ext/string/multibyte.rb +0 -72
- data/lib/active_support/core_ext/string/output_safety.rb +0 -109
- data/lib/active_support/core_ext/string/starts_ends_with.rb +0 -4
- data/lib/active_support/core_ext/string/xchar.rb +0 -18
- data/lib/active_support/core_ext/time/acts_like.rb +0 -8
- data/lib/active_support/core_ext/time/calculations.rb +0 -282
- data/lib/active_support/core_ext/time/conversions.rb +0 -85
- data/lib/active_support/core_ext/time/marshal.rb +0 -56
- data/lib/active_support/core_ext/time/publicize_conversion_methods.rb +0 -10
- data/lib/active_support/core_ext/time/zones.rb +0 -78
- data/lib/active_support/core_ext/uri.rb +0 -22
- data/lib/active_support/dependencies.rb +0 -628
- data/lib/active_support/dependencies/autoload.rb +0 -50
- data/lib/active_support/deprecation.rb +0 -18
- data/lib/active_support/deprecation/behaviors.rb +0 -38
- data/lib/active_support/deprecation/method_wrappers.rb +0 -29
- data/lib/active_support/deprecation/proxy_wrappers.rb +0 -74
- data/lib/active_support/deprecation/reporting.rb +0 -56
- data/lib/active_support/duration.rb +0 -105
- data/lib/active_support/gzip.rb +0 -25
- data/lib/active_support/hash_with_indifferent_access.rb +0 -145
- data/lib/active_support/i18n.rb +0 -8
- data/lib/active_support/inflections.rb +0 -56
- data/lib/active_support/inflector.rb +0 -7
- data/lib/active_support/inflector/inflections.rb +0 -211
- data/lib/active_support/inflector/methods.rb +0 -141
- data/lib/active_support/inflector/transliterate.rb +0 -97
- data/lib/active_support/json.rb +0 -2
- data/lib/active_support/json/backends/jsongem.rb +0 -43
- data/lib/active_support/json/backends/yajl.rb +0 -40
- data/lib/active_support/json/backends/yaml.rb +0 -90
- data/lib/active_support/json/decoding.rb +0 -51
- data/lib/active_support/json/encoding.rb +0 -254
- data/lib/active_support/json/variable.rb +0 -11
- data/lib/active_support/lazy_load_hooks.rb +0 -27
- data/lib/active_support/locale/en.yml +0 -36
- data/lib/active_support/memoizable.rb +0 -103
- data/lib/active_support/message_encryptor.rb +0 -71
- data/lib/active_support/message_verifier.rb +0 -62
- data/lib/active_support/multibyte.rb +0 -44
- data/lib/active_support/multibyte/chars.rb +0 -480
- data/lib/active_support/multibyte/exceptions.rb +0 -8
- data/lib/active_support/multibyte/unicode.rb +0 -393
- data/lib/active_support/multibyte/utils.rb +0 -60
- data/lib/active_support/notifications.rb +0 -81
- data/lib/active_support/notifications/fanout.rb +0 -93
- data/lib/active_support/notifications/instrumenter.rb +0 -56
- data/lib/active_support/option_merger.rb +0 -25
- data/lib/active_support/ordered_hash.rb +0 -158
- data/lib/active_support/ordered_options.rb +0 -27
- data/lib/active_support/railtie.rb +0 -100
- data/lib/active_support/rescuable.rb +0 -114
- data/lib/active_support/ruby/shim.rb +0 -22
- data/lib/active_support/secure_random.rb +0 -199
- data/lib/active_support/string_inquirer.rb +0 -21
- data/lib/active_support/test_case.rb +0 -42
- data/lib/active_support/testing/assertions.rb +0 -82
- data/lib/active_support/testing/declarative.rb +0 -40
- data/lib/active_support/testing/default.rb +0 -9
- data/lib/active_support/testing/deprecation.rb +0 -55
- data/lib/active_support/testing/isolation.rb +0 -154
- data/lib/active_support/testing/pending.rb +0 -48
- data/lib/active_support/testing/performance.rb +0 -455
- data/lib/active_support/testing/setup_and_teardown.rb +0 -111
- data/lib/active_support/time.rb +0 -34
- data/lib/active_support/time/autoload.rb +0 -5
- data/lib/active_support/time_with_zone.rb +0 -341
- data/lib/active_support/values/time_zone.rb +0 -377
- data/lib/active_support/values/unicode_tables.dat +0 -0
- data/lib/active_support/version.rb +0 -10
- data/lib/active_support/whiny_nil.rb +0 -60
- data/lib/active_support/xml_mini.rb +0 -158
- data/lib/active_support/xml_mini/jdom.rb +0 -168
- data/lib/active_support/xml_mini/libxml.rb +0 -80
- data/lib/active_support/xml_mini/libxmlsax.rb +0 -85
- data/lib/active_support/xml_mini/nokogiri.rb +0 -78
- data/lib/active_support/xml_mini/nokogirisax.rb +0 -83
- data/lib/active_support/xml_mini/rexml.rb +0 -129
- data/lib/csd/extensions/core/file.rb +0 -14
- data/lib/csd/global_open_struct.rb +0 -19
- data/lib/csd/path.rb +0 -32
- data/lib/csd/ui.rb +0 -2
- data/lib/csd/ui/cli.rb +0 -8
- data/lib/csd/ui/ui.rb +0 -45
- data/lib/term/ansicolor.rb +0 -102
- data/lib/term/ansicolor/.keep +0 -0
- data/lib/term/ansicolor/version.rb +0 -10
@@ -1,18 +0,0 @@
|
|
1
|
-
begin
|
2
|
-
# See http://fast-xs.rubyforge.org/ by Eric Wong.
|
3
|
-
# Also included with hpricot.
|
4
|
-
require 'fast_xs'
|
5
|
-
rescue LoadError
|
6
|
-
# fast_xs extension unavailable
|
7
|
-
else
|
8
|
-
begin
|
9
|
-
require 'builder'
|
10
|
-
rescue LoadError
|
11
|
-
# builder demands the first shot at defining String#to_xs
|
12
|
-
end
|
13
|
-
|
14
|
-
class String
|
15
|
-
alias_method :original_xs, :to_xs if method_defined?(:to_xs)
|
16
|
-
alias_method :to_xs, :fast_xs
|
17
|
-
end
|
18
|
-
end
|
@@ -1,282 +0,0 @@
|
|
1
|
-
require 'active_support/duration'
|
2
|
-
require 'active_support/core_ext/date/acts_like'
|
3
|
-
require 'active_support/core_ext/date/calculations'
|
4
|
-
require 'active_support/core_ext/date_time/conversions'
|
5
|
-
|
6
|
-
class Time
|
7
|
-
COMMON_YEAR_DAYS_IN_MONTH = [nil, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
|
8
|
-
DAYS_INTO_WEEK = { :monday => 0, :tuesday => 1, :wednesday => 2, :thursday => 3, :friday => 4, :saturday => 5, :sunday => 6 }
|
9
|
-
|
10
|
-
class << self
|
11
|
-
# Overriding case equality method so that it returns true for ActiveSupport::TimeWithZone instances
|
12
|
-
def ===(other)
|
13
|
-
other.is_a?(::Time)
|
14
|
-
end
|
15
|
-
|
16
|
-
# Return the number of days in the given month.
|
17
|
-
# If no year is specified, it will use the current year.
|
18
|
-
def days_in_month(month, year = now.year)
|
19
|
-
return 29 if month == 2 && ::Date.gregorian_leap?(year)
|
20
|
-
COMMON_YEAR_DAYS_IN_MONTH[month]
|
21
|
-
end
|
22
|
-
|
23
|
-
# Returns a new Time if requested year can be accommodated by Ruby's Time class
|
24
|
-
# (i.e., if year is within either 1970..2038 or 1902..2038, depending on system architecture);
|
25
|
-
# otherwise returns a DateTime
|
26
|
-
def time_with_datetime_fallback(utc_or_local, year, month=1, day=1, hour=0, min=0, sec=0, usec=0)
|
27
|
-
time = ::Time.send(utc_or_local, year, month, day, hour, min, sec, usec)
|
28
|
-
# This check is needed because Time.utc(y) returns a time object in the 2000s for 0 <= y <= 138.
|
29
|
-
time.year == year ? time : ::DateTime.civil_from_format(utc_or_local, year, month, day, hour, min, sec)
|
30
|
-
rescue
|
31
|
-
::DateTime.civil_from_format(utc_or_local, year, month, day, hour, min, sec)
|
32
|
-
end
|
33
|
-
|
34
|
-
# Wraps class method +time_with_datetime_fallback+ with +utc_or_local+ set to <tt>:utc</tt>.
|
35
|
-
def utc_time(*args)
|
36
|
-
time_with_datetime_fallback(:utc, *args)
|
37
|
-
end
|
38
|
-
|
39
|
-
# Wraps class method +time_with_datetime_fallback+ with +utc_or_local+ set to <tt>:local</tt>.
|
40
|
-
def local_time(*args)
|
41
|
-
time_with_datetime_fallback(:local, *args)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
# Tells whether the Time object's time lies in the past
|
46
|
-
def past?
|
47
|
-
self < ::Time.current
|
48
|
-
end
|
49
|
-
|
50
|
-
# Tells whether the Time object's time is today
|
51
|
-
def today?
|
52
|
-
to_date == ::Date.current
|
53
|
-
end
|
54
|
-
|
55
|
-
# Tells whether the Time object's time lies in the future
|
56
|
-
def future?
|
57
|
-
self > ::Time.current
|
58
|
-
end
|
59
|
-
|
60
|
-
# Seconds since midnight: Time.now.seconds_since_midnight
|
61
|
-
def seconds_since_midnight
|
62
|
-
to_i - change(:hour => 0).to_i + (usec / 1.0e+6)
|
63
|
-
end
|
64
|
-
|
65
|
-
# Returns a new Time where one or more of the elements have been changed according to the +options+ parameter. The time options
|
66
|
-
# (hour, minute, sec, usec) reset cascadingly, so if only the hour is passed, then minute, sec, and usec is set to 0. If the hour and
|
67
|
-
# minute is passed, then sec and usec is set to 0.
|
68
|
-
def change(options)
|
69
|
-
::Time.send(
|
70
|
-
utc? ? :utc_time : :local_time,
|
71
|
-
options[:year] || year,
|
72
|
-
options[:month] || month,
|
73
|
-
options[:day] || day,
|
74
|
-
options[:hour] || hour,
|
75
|
-
options[:min] || (options[:hour] ? 0 : min),
|
76
|
-
options[:sec] || ((options[:hour] || options[:min]) ? 0 : sec),
|
77
|
-
options[:usec] || ((options[:hour] || options[:min] || options[:sec]) ? 0 : usec)
|
78
|
-
)
|
79
|
-
end
|
80
|
-
|
81
|
-
# Uses Date to provide precise Time calculations for years, months, and days.
|
82
|
-
# The +options+ parameter takes a hash with any of these keys: <tt>:years</tt>,
|
83
|
-
# <tt>:months</tt>, <tt>:weeks</tt>, <tt>:days</tt>, <tt>:hours</tt>,
|
84
|
-
# <tt>:minutes</tt>, <tt>:seconds</tt>.
|
85
|
-
def advance(options)
|
86
|
-
unless options[:weeks].nil?
|
87
|
-
options[:weeks], partial_weeks = options[:weeks].divmod(1)
|
88
|
-
options[:days] = (options[:days] || 0) + 7 * partial_weeks
|
89
|
-
end
|
90
|
-
|
91
|
-
unless options[:days].nil?
|
92
|
-
options[:days], partial_days = options[:days].divmod(1)
|
93
|
-
options[:hours] = (options[:hours] || 0) + 24 * partial_days
|
94
|
-
end
|
95
|
-
|
96
|
-
d = to_date.advance(options)
|
97
|
-
time_advanced_by_date = change(:year => d.year, :month => d.month, :day => d.day)
|
98
|
-
seconds_to_advance = (options[:seconds] || 0) + (options[:minutes] || 0) * 60 + (options[:hours] || 0) * 3600
|
99
|
-
seconds_to_advance == 0 ? time_advanced_by_date : time_advanced_by_date.since(seconds_to_advance)
|
100
|
-
end
|
101
|
-
|
102
|
-
# Returns a new Time representing the time a number of seconds ago, this is basically a wrapper around the Numeric extension
|
103
|
-
def ago(seconds)
|
104
|
-
since(-seconds)
|
105
|
-
end
|
106
|
-
|
107
|
-
# Returns a new Time representing the time a number of seconds since the instance time
|
108
|
-
def since(seconds)
|
109
|
-
self + seconds
|
110
|
-
rescue
|
111
|
-
to_datetime.since(seconds)
|
112
|
-
end
|
113
|
-
alias :in :since
|
114
|
-
|
115
|
-
# Returns a new Time representing the time a number of specified months ago
|
116
|
-
def months_ago(months)
|
117
|
-
advance(:months => -months)
|
118
|
-
end
|
119
|
-
|
120
|
-
# Returns a new Time representing the time a number of specified months in the future
|
121
|
-
def months_since(months)
|
122
|
-
advance(:months => months)
|
123
|
-
end
|
124
|
-
|
125
|
-
# Returns a new Time representing the time a number of specified years ago
|
126
|
-
def years_ago(years)
|
127
|
-
advance(:years => -years)
|
128
|
-
end
|
129
|
-
|
130
|
-
# Returns a new Time representing the time a number of specified years in the future
|
131
|
-
def years_since(years)
|
132
|
-
advance(:years => years)
|
133
|
-
end
|
134
|
-
|
135
|
-
# Short-hand for years_ago(1)
|
136
|
-
def prev_year
|
137
|
-
years_ago(1)
|
138
|
-
end
|
139
|
-
|
140
|
-
# Short-hand for years_since(1)
|
141
|
-
def next_year
|
142
|
-
years_since(1)
|
143
|
-
end
|
144
|
-
|
145
|
-
# Short-hand for months_ago(1)
|
146
|
-
def prev_month
|
147
|
-
months_ago(1)
|
148
|
-
end
|
149
|
-
|
150
|
-
# Short-hand for months_since(1)
|
151
|
-
def next_month
|
152
|
-
months_since(1)
|
153
|
-
end
|
154
|
-
|
155
|
-
# Returns a new Time representing the "start" of this week (Monday, 0:00)
|
156
|
-
def beginning_of_week
|
157
|
-
days_to_monday = wday!=0 ? wday-1 : 6
|
158
|
-
(self - days_to_monday.days).midnight
|
159
|
-
end
|
160
|
-
alias :monday :beginning_of_week
|
161
|
-
alias :at_beginning_of_week :beginning_of_week
|
162
|
-
|
163
|
-
# Returns a new Time representing the end of this week, (end of Sunday)
|
164
|
-
def end_of_week
|
165
|
-
days_to_sunday = wday!=0 ? 7-wday : 0
|
166
|
-
(self + days_to_sunday.days).end_of_day
|
167
|
-
end
|
168
|
-
alias :at_end_of_week :end_of_week
|
169
|
-
|
170
|
-
# Returns a new Time representing the start of the given day in next week (default is Monday).
|
171
|
-
def next_week(day = :monday)
|
172
|
-
since(1.week).beginning_of_week.since(DAYS_INTO_WEEK[day].day).change(:hour => 0)
|
173
|
-
end
|
174
|
-
|
175
|
-
# Returns a new Time representing the start of the day (0:00)
|
176
|
-
def beginning_of_day
|
177
|
-
#(self - seconds_since_midnight).change(:usec => 0)
|
178
|
-
change(:hour => 0, :min => 0, :sec => 0, :usec => 0)
|
179
|
-
end
|
180
|
-
alias :midnight :beginning_of_day
|
181
|
-
alias :at_midnight :beginning_of_day
|
182
|
-
alias :at_beginning_of_day :beginning_of_day
|
183
|
-
|
184
|
-
# Returns a new Time representing the end of the day, 23:59:59.999999 (.999999999 in ruby1.9)
|
185
|
-
def end_of_day
|
186
|
-
change(:hour => 23, :min => 59, :sec => 59, :usec => 999999.999)
|
187
|
-
end
|
188
|
-
|
189
|
-
# Returns a new Time representing the start of the month (1st of the month, 0:00)
|
190
|
-
def beginning_of_month
|
191
|
-
#self - ((self.mday-1).days + self.seconds_since_midnight)
|
192
|
-
change(:day => 1,:hour => 0, :min => 0, :sec => 0, :usec => 0)
|
193
|
-
end
|
194
|
-
alias :at_beginning_of_month :beginning_of_month
|
195
|
-
|
196
|
-
# Returns a new Time representing the end of the month (end of the last day of the month)
|
197
|
-
def end_of_month
|
198
|
-
#self - ((self.mday-1).days + self.seconds_since_midnight)
|
199
|
-
last_day = ::Time.days_in_month(month, year)
|
200
|
-
change(:day => last_day, :hour => 23, :min => 59, :sec => 59, :usec => 999999.999)
|
201
|
-
end
|
202
|
-
alias :at_end_of_month :end_of_month
|
203
|
-
|
204
|
-
# Returns a new Time representing the start of the quarter (1st of january, april, july, october, 0:00)
|
205
|
-
def beginning_of_quarter
|
206
|
-
beginning_of_month.change(:month => [10, 7, 4, 1].detect { |m| m <= month })
|
207
|
-
end
|
208
|
-
alias :at_beginning_of_quarter :beginning_of_quarter
|
209
|
-
|
210
|
-
# Returns a new Time representing the end of the quarter (end of the last day of march, june, september, december)
|
211
|
-
def end_of_quarter
|
212
|
-
beginning_of_month.change(:month => [3, 6, 9, 12].detect { |m| m >= month }).end_of_month
|
213
|
-
end
|
214
|
-
alias :at_end_of_quarter :end_of_quarter
|
215
|
-
|
216
|
-
# Returns a new Time representing the start of the year (1st of january, 0:00)
|
217
|
-
def beginning_of_year
|
218
|
-
change(:month => 1, :day => 1, :hour => 0, :min => 0, :sec => 0, :usec => 0)
|
219
|
-
end
|
220
|
-
alias :at_beginning_of_year :beginning_of_year
|
221
|
-
|
222
|
-
# Returns a new Time representing the end of the year (end of the 31st of december)
|
223
|
-
def end_of_year
|
224
|
-
change(:month => 12, :day => 31, :hour => 23, :min => 59, :sec => 59, :usec => 999999.999)
|
225
|
-
end
|
226
|
-
alias :at_end_of_year :end_of_year
|
227
|
-
|
228
|
-
# Convenience method which returns a new Time representing the time 1 day ago
|
229
|
-
def yesterday
|
230
|
-
advance(:days => -1)
|
231
|
-
end
|
232
|
-
|
233
|
-
# Convenience method which returns a new Time representing the time 1 day since the instance time
|
234
|
-
def tomorrow
|
235
|
-
advance(:days => 1)
|
236
|
-
end
|
237
|
-
|
238
|
-
def plus_with_duration(other) #:nodoc:
|
239
|
-
if ActiveSupport::Duration === other
|
240
|
-
other.since(self)
|
241
|
-
else
|
242
|
-
plus_without_duration(other)
|
243
|
-
end
|
244
|
-
end
|
245
|
-
alias_method :plus_without_duration, :+
|
246
|
-
alias_method :+, :plus_with_duration
|
247
|
-
|
248
|
-
def minus_with_duration(other) #:nodoc:
|
249
|
-
if ActiveSupport::Duration === other
|
250
|
-
other.until(self)
|
251
|
-
else
|
252
|
-
minus_without_duration(other)
|
253
|
-
end
|
254
|
-
end
|
255
|
-
alias_method :minus_without_duration, :-
|
256
|
-
alias_method :-, :minus_with_duration
|
257
|
-
|
258
|
-
# Time#- can also be used to determine the number of seconds between two Time instances.
|
259
|
-
# We're layering on additional behavior so that ActiveSupport::TimeWithZone instances
|
260
|
-
# are coerced into values that Time#- will recognize
|
261
|
-
def minus_with_coercion(other)
|
262
|
-
other = other.comparable_time if other.respond_to?(:comparable_time)
|
263
|
-
other.is_a?(DateTime) ? to_f - other.to_f : minus_without_coercion(other)
|
264
|
-
end
|
265
|
-
alias_method :minus_without_coercion, :-
|
266
|
-
alias_method :-, :minus_with_coercion
|
267
|
-
|
268
|
-
# Layers additional behavior on Time#<=> so that DateTime and ActiveSupport::TimeWithZone instances
|
269
|
-
# can be chronologically compared with a Time
|
270
|
-
def compare_with_coercion(other)
|
271
|
-
# if other is an ActiveSupport::TimeWithZone, coerce a Time instance from it so we can do <=> comparison
|
272
|
-
other = other.comparable_time if other.respond_to?(:comparable_time)
|
273
|
-
if other.acts_like?(:date)
|
274
|
-
# other is a Date/DateTime, so coerce self #to_datetime and hand off to DateTime#<=>
|
275
|
-
to_datetime.compare_without_coercion(other)
|
276
|
-
else
|
277
|
-
compare_without_coercion(other)
|
278
|
-
end
|
279
|
-
end
|
280
|
-
alias_method :compare_without_coercion, :<=>
|
281
|
-
alias_method :<=>, :compare_with_coercion
|
282
|
-
end
|
@@ -1,85 +0,0 @@
|
|
1
|
-
require 'active_support/inflector'
|
2
|
-
require 'active_support/core_ext/time/publicize_conversion_methods'
|
3
|
-
require 'active_support/values/time_zone'
|
4
|
-
|
5
|
-
class Time
|
6
|
-
DATE_FORMATS = {
|
7
|
-
:db => "%Y-%m-%d %H:%M:%S",
|
8
|
-
:number => "%Y%m%d%H%M%S",
|
9
|
-
:time => "%H:%M",
|
10
|
-
:short => "%d %b %H:%M",
|
11
|
-
:long => "%B %d, %Y %H:%M",
|
12
|
-
:long_ordinal => lambda { |time| time.strftime("%B #{ActiveSupport::Inflector.ordinalize(time.day)}, %Y %H:%M") },
|
13
|
-
:rfc822 => lambda { |time| time.strftime("%a, %d %b %Y %H:%M:%S #{time.formatted_offset(false)}") }
|
14
|
-
}
|
15
|
-
|
16
|
-
# Converts to a formatted string. See DATE_FORMATS for builtin formats.
|
17
|
-
#
|
18
|
-
# This method is aliased to <tt>to_s</tt>.
|
19
|
-
#
|
20
|
-
# time = Time.now # => Thu Jan 18 06:10:17 CST 2007
|
21
|
-
#
|
22
|
-
# time.to_formatted_s(:time) # => "06:10:17"
|
23
|
-
# time.to_s(:time) # => "06:10:17"
|
24
|
-
#
|
25
|
-
# time.to_formatted_s(:db) # => "2007-01-18 06:10:17"
|
26
|
-
# time.to_formatted_s(:number) # => "20070118061017"
|
27
|
-
# time.to_formatted_s(:short) # => "18 Jan 06:10"
|
28
|
-
# time.to_formatted_s(:long) # => "January 18, 2007 06:10"
|
29
|
-
# time.to_formatted_s(:long_ordinal) # => "January 18th, 2007 06:10"
|
30
|
-
# time.to_formatted_s(:rfc822) # => "Thu, 18 Jan 2007 06:10:17 -0600"
|
31
|
-
#
|
32
|
-
# == Adding your own time formats to +to_formatted_s+
|
33
|
-
# You can add your own formats to the Time::DATE_FORMATS hash.
|
34
|
-
# Use the format name as the hash key and either a strftime string
|
35
|
-
# or Proc instance that takes a time argument as the value.
|
36
|
-
#
|
37
|
-
# # config/initializers/time_formats.rb
|
38
|
-
# Time::DATE_FORMATS[:month_and_year] = "%B %Y"
|
39
|
-
# Time::DATE_FORMATS[:short_ordinal] = lambda { |time| time.strftime("%B #{time.day.ordinalize}") }
|
40
|
-
def to_formatted_s(format = :default)
|
41
|
-
if formatter = DATE_FORMATS[format]
|
42
|
-
formatter.respond_to?(:call) ? formatter.call(self).to_s : strftime(formatter)
|
43
|
-
else
|
44
|
-
to_default_s
|
45
|
-
end
|
46
|
-
end
|
47
|
-
alias_method :to_default_s, :to_s
|
48
|
-
alias_method :to_s, :to_formatted_s
|
49
|
-
|
50
|
-
# Returns the UTC offset as an +HH:MM formatted string.
|
51
|
-
#
|
52
|
-
# Time.local(2000).formatted_offset # => "-06:00"
|
53
|
-
# Time.local(2000).formatted_offset(false) # => "-0600"
|
54
|
-
def formatted_offset(colon = true, alternate_utc_string = nil)
|
55
|
-
utc? && alternate_utc_string || ActiveSupport::TimeZone.seconds_to_utc_offset(utc_offset, colon)
|
56
|
-
end
|
57
|
-
|
58
|
-
# Converts a Time object to a Date, dropping hour, minute, and second precision.
|
59
|
-
#
|
60
|
-
# my_time = Time.now # => Mon Nov 12 22:59:51 -0500 2007
|
61
|
-
# my_time.to_date # => Mon, 12 Nov 2007
|
62
|
-
#
|
63
|
-
# your_time = Time.parse("1/13/2009 1:13:03 P.M.") # => Tue Jan 13 13:13:03 -0500 2009
|
64
|
-
# your_time.to_date # => Tue, 13 Jan 2009
|
65
|
-
def to_date
|
66
|
-
::Date.new(year, month, day)
|
67
|
-
end unless method_defined?(:to_date)
|
68
|
-
|
69
|
-
# A method to keep Time, Date and DateTime instances interchangeable on conversions.
|
70
|
-
# In this case, it simply returns +self+.
|
71
|
-
def to_time
|
72
|
-
self
|
73
|
-
end unless method_defined?(:to_time)
|
74
|
-
|
75
|
-
# Converts a Time instance to a Ruby DateTime instance, preserving UTC offset.
|
76
|
-
#
|
77
|
-
# my_time = Time.now # => Mon Nov 12 23:04:21 -0500 2007
|
78
|
-
# my_time.to_datetime # => Mon, 12 Nov 2007 23:04:21 -0500
|
79
|
-
#
|
80
|
-
# your_time = Time.parse("1/13/2009 1:13:03 P.M.") # => Tue Jan 13 13:13:03 -0500 2009
|
81
|
-
# your_time.to_datetime # => Tue, 13 Jan 2009 13:13:03 -0500
|
82
|
-
def to_datetime
|
83
|
-
::DateTime.civil(year, month, day, hour, min, sec, Rational(utc_offset, 86400))
|
84
|
-
end unless method_defined?(:to_datetime)
|
85
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
# Pre-1.9 versions of Ruby have a bug with marshaling Time instances, where utc instances are
|
2
|
-
# unmarshalled in the local zone, instead of utc. We're layering behavior on the _dump and _load
|
3
|
-
# methods so that utc instances can be flagged on dump, and coerced back to utc on load.
|
4
|
-
if !Marshal.load(Marshal.dump(Time.now.utc)).utc?
|
5
|
-
class Time
|
6
|
-
class << self
|
7
|
-
alias_method :_load_without_utc_flag, :_load
|
8
|
-
def _load(marshaled_time)
|
9
|
-
time = _load_without_utc_flag(marshaled_time)
|
10
|
-
time.instance_eval do
|
11
|
-
if defined?(@marshal_with_utc_coercion)
|
12
|
-
val = remove_instance_variable("@marshal_with_utc_coercion")
|
13
|
-
end
|
14
|
-
val ? utc : self
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
alias_method :_dump_without_utc_flag, :_dump
|
20
|
-
def _dump(*args)
|
21
|
-
obj = dup
|
22
|
-
obj.instance_variable_set('@marshal_with_utc_coercion', utc?)
|
23
|
-
obj._dump_without_utc_flag(*args)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
# Ruby 1.9.2 adds utc_offset and zone to Time, but marshaling only
|
29
|
-
# preserves utc_offset. Preserve zone also, even though it may not
|
30
|
-
# work in some edge cases.
|
31
|
-
if Time.local(2010).zone != Marshal.load(Marshal.dump(Time.local(2010))).zone
|
32
|
-
class Time
|
33
|
-
class << self
|
34
|
-
alias_method :_load_without_zone, :_load
|
35
|
-
def _load(marshaled_time)
|
36
|
-
time = _load_without_zone(marshaled_time)
|
37
|
-
time.instance_eval do
|
38
|
-
if zone = defined?(@_zone) && remove_instance_variable('@_zone')
|
39
|
-
ary = to_a
|
40
|
-
ary[-1] = zone
|
41
|
-
utc? ? Time.utc(*ary) : Time.local(*ary)
|
42
|
-
else
|
43
|
-
self
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
alias_method :_dump_without_zone, :_dump
|
50
|
-
def _dump(*args)
|
51
|
-
obj = dup
|
52
|
-
obj.instance_variable_set('@_zone', zone)
|
53
|
-
obj._dump_without_zone(*args)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|