diff options
Diffstat (limited to 'lib/time.rb')
-rw-r--r-- | lib/time.rb | 63 |
1 files changed, 33 insertions, 30 deletions
diff --git a/lib/time.rb b/lib/time.rb index 970932a200..10f75b1dda 100644 --- a/lib/time.rb +++ b/lib/time.rb @@ -26,7 +26,7 @@ require 'date' class Time - VERSION = "0.3.0" + VERSION = "0.4.0" class << Time @@ -391,6 +391,8 @@ class Time # heuristic to detect the format of the input string, you provide # a second argument that describes the format of the string. # + # Raises `ArgumentError` if the date or format is invalid. + # # If a block is given, the year described in +date+ is converted by the # block. For example: # @@ -693,35 +695,36 @@ class Time getutc.strftime('%a, %d %b %Y %T GMT') end - # - # Returns a string which represents the time as a dateTime defined by XML - # Schema: - # - # CCYY-MM-DDThh:mm:ssTZD - # CCYY-MM-DDThh:mm:ss.sssTZD - # - # where TZD is Z or [+-]hh:mm. - # - # If self is a UTC time, Z is used as TZD. [+-]hh:mm is used otherwise. - # - # +fraction_digits+ specifies a number of digits to use for fractional - # seconds. Its default value is 0. - # - # require 'time' - # - # t = Time.now - # t.iso8601 # => "2011-10-05T22:26:12-04:00" - # - # You must require 'time' to use this method. - # - def xmlschema(fraction_digits=0) - fraction_digits = fraction_digits.to_i - s = strftime("%FT%T") - if fraction_digits > 0 - s << strftime(".%#{fraction_digits}N") + unless method_defined?(:xmlschema) + # + # Returns a string which represents the time as a dateTime defined by XML + # Schema: + # + # CCYY-MM-DDThh:mm:ssTZD + # CCYY-MM-DDThh:mm:ss.sssTZD + # + # where TZD is Z or [+-]hh:mm. + # + # If self is a UTC time, Z is used as TZD. [+-]hh:mm is used otherwise. + # + # +fraction_digits+ specifies a number of digits to use for fractional + # seconds. Its default value is 0. + # + # require 'time' + # + # t = Time.now + # t.iso8601 # => "2011-10-05T22:26:12-04:00" + # + # You must require 'time' to use this method. + # + def xmlschema(fraction_digits=0) + fraction_digits = fraction_digits.to_i + s = strftime("%FT%T") + if fraction_digits > 0 + s << strftime(".%#{fraction_digits}N") + end + s << (utc? ? 'Z' : strftime("%:z")) end - s << (utc? ? 'Z' : strftime("%:z")) end - alias iso8601 xmlschema + alias iso8601 xmlschema unless method_defined?(:iso8601) end - |