Fixing issues with Ruby 1.8.7

This commit is contained in:
Sam Lown 2011-04-08 22:34:25 +02:00
parent 33b844b596
commit a6becd7305
8 changed files with 118 additions and 41 deletions

View file

@ -3,6 +3,29 @@ module CouchRest
module CoreExtensions
module TimeParsing
if RUBY_VERSION < "1.9.0"
# Overrwrite Ruby's standard new method to provide compatible support
# of 1.9.2's Time.new method.
#
# Only supports syntax like:
#
# Time.new(2011, 4, 1, 18, 50, 32, "+02:00")
# # or
# Time.new(2011, 4, 1, 18, 50, 32)
#
def new(*args)
return super() if (args.empty?)
zone = args.delete_at(6)
time = mktime(*args)
if zone =~ /([\+|\-]?)(\d{2}):?(\d{2})/
tz_difference = ("#{$1 == '-' ? '+' : '-'}#{$2}".to_i * 3600) + ($3.to_i * 60)
time + tz_difference + zone_offset(time.zone)
else
time
end
end
end
# Attemtps to parse a time string in ISO8601 format.
# If no match is found, the standard time parse will be used.
#