Class: Time

Inherits:
Object
  • Object
show all
Defined in:
lib/time.rb

Overview

Defined Under Namespace

Classes: Time

Constant Summary collapse

VERSION =

:nodoc:

"0.4.1"

Instance Method Summary collapse

Instance Method Details

#httpdateObject

Returns a string which represents the time as RFC 1123 date of HTTP-date defined by RFC 2616:

day-of-week, DD month-name CCYY hh:mm:ss GMT

Note that the result is always UTC (GMT).

require 'time'

t = Time.now
t.httpdate # => "Thu, 06 Oct 2011 02:26:12 GMT"

You must require 'time' to use this method.



695
696
697
# File 'lib/time.rb', line 695

def httpdate
  getutc.strftime('%a, %d %b %Y %T GMT')
end

#rfc2822Object Also known as: rfc822

Returns a string which represents the time as date-time defined by RFC 2822:

day-of-week, DD month-name CCYY hh:mm:ss zone

where zone is [+-]hhmm.

If self is a UTC time, -0000 is used as zone.

require 'time'

t = Time.now
t.rfc2822  # => "Wed, 05 Oct 2011 22:26:12 -0400"

You must require 'time' to use this method.



675
676
677
# File 'lib/time.rb', line 675

def rfc2822
  strftime('%a, %d %b %Y %T ') << (utc? ? '-0000' : strftime('%z'))
end

#xmlschema(fraction_digits = 0) ⇒ Object Also known as: iso8601

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.



721
722
723
724
725
726
727
728
# File 'lib/time.rb', line 721

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