Extended maintenance of Ruby versions 1.8.7 and 1.9.2 ended on July 31, 2014. Read more

In Files

  • date.rb
  • date/format.rb

Class/Module Index [+]

Quicksearch

DateTime

Public Class Methods

_strptime(str, fmt='%FT%T%z') click to toggle source
 
               # File date/format.rb, line 1162
def self._strptime(str, fmt='%FT%T%z')
  super(str, fmt)
end
            
civil(y=-4712, m=1, d=1, h=0, min=0, s=0, of=0, sg=ITALY) click to toggle source

Create a new DateTime object corresponding to the specified Civil Date and hour h, minute min, second s.

The 24-hour clock is used. Negative values of h, min, and sec are treating as counting backwards from the end of the next larger unit (e.g. a min of -2 is treated as 58). No wraparound is performed. If an invalid time portion is specified, an ArgumentError is raised.

of is the offset from UTC as a fraction of a day (defaults to 0). sg specifies the Day of Calendar Reform.

y defaults to -4712, m to 1, and d to 1; this is Julian Day Number day 0. The time values default to 0.

 
               # File date.rb, line 1519
def self.civil(y=-4712, m=1, d=1, h=0, min=0, s=0, of=0, sg=ITALY)
  unless (jd = valid_civil?(y, m, d, sg)) &&
         (fr = valid_time?(h, min, s))
    raise ArgumentError, 'invalid date'
  end
  if String === of
    of = Rational(zone_to_diff(of) || 0, 86400)
  end
  new!(jd_to_ajd(jd, fr, of), of, sg)
end
            
Also aliased as: new
commercial(y=1582, w=41, d=5, h=0, min=0, s=0, of=0, sg=ITALY) click to toggle source

Create a new DateTime object corresponding to the specified Commercial Date and hour h, minute min, second s.

The 24-hour clock is used. Negative values of h, min, and sec are treating as counting backwards from the end of the next larger unit (e.g. a min of -2 is treated as 58). No wraparound is performed. If an invalid time portion is specified, an ArgumentError is raised.

of is the offset from UTC as a fraction of a day (defaults to 0). sg specifies the Day of Calendar Reform.

y defaults to 1582, w to 41, and d to 5; this is the Day of Calendar Reform for Italy and the Catholic countries. The time values default to 0.

 
               # File date.rb, line 1547
def self.commercial(y=1582, w=41, d=5, h=0, min=0, s=0, of=0, sg=ITALY)
  unless (jd = valid_commercial?(y, w, d, sg)) &&
         (fr = valid_time?(h, min, s))
    raise ArgumentError, 'invalid date'
  end
  if String === of
    of = Rational(zone_to_diff(of) || 0, 86400)
  end
  new!(jd_to_ajd(jd, fr, of), of, sg)
end
            
jd(jd=0, h=0, min=0, s=0, of=0, sg=ITALY) click to toggle source

Create a new DateTime object corresponding to the specified Julian Day Number jd and hour h, minute min, second s.

The 24-hour clock is used. Negative values of h, min, and sec are treating as counting backwards from the end of the next larger unit (e.g. a min of -2 is treated as 58). No wraparound is performed. If an invalid time portion is specified, an ArgumentError is raised.

of is the offset from UTC as a fraction of a day (defaults to 0). sg specifies the Day of Calendar Reform.

All day/time values default to 0.

 
               # File date.rb, line 1469
def self.jd(jd=0, h=0, min=0, s=0, of=0, sg=ITALY)
  unless (jd = valid_jd?(jd, sg)) &&
         (fr = valid_time?(h, min, s))
    raise ArgumentError, 'invalid date'
  end
  if String === of
    of = Rational(zone_to_diff(of) || 0, 86400)
  end
  new!(jd_to_ajd(jd, fr, of), of, sg)
end
            
new(y=-4712, m=1, d=1, h=0, min=0, s=0, of=0, sg=ITALY) click to toggle source
Alias for: civil
ordinal(y=-4712, d=1, h=0, min=0, s=0, of=0, sg=ITALY) click to toggle source

Create a new DateTime object corresponding to the specified Ordinal Date and hour h, minute min, second s.

The 24-hour clock is used. Negative values of h, min, and sec are treating as counting backwards from the end of the next larger unit (e.g. a min of -2 is treated as 58). No wraparound is performed. If an invalid time portion is specified, an ArgumentError is raised.

of is the offset from UTC as a fraction of a day (defaults to 0). sg specifies the Day of Calendar Reform.

y defaults to -4712, and d to 1; this is Julian Day Number day 0. The time values default to 0.

 
               # File date.rb, line 1494
def self.ordinal(y=-4712, d=1, h=0, min=0, s=0, of=0, sg=ITALY)
  unless (jd = valid_ordinal?(y, d, sg)) &&
         (fr = valid_time?(h, min, s))
    raise ArgumentError, 'invalid date'
  end
  if String === of
    of = Rational(zone_to_diff(of) || 0, 86400)
  end
  new!(jd_to_ajd(jd, fr, of), of, sg)
end
            
parse(str='-4712-01-01T00:00:00+00:00', comp=false, sg=ITALY) click to toggle source

Create a new DateTime object by parsing from a String, without specifying the format.

str is a String holding a date-time representation. comp specifies whether to interpret 2-digit years as 19XX (>= 69) or 20XX (< 69); the default is not to. The method will attempt to parse a date-time from the String using various heuristics; see #_parse in date/format.rb for more details. If parsing fails, an ArgumentError will be raised.

The default str is ‘-4712-01-01T00:00:00+00:00’; this is Julian Day Number day 0.

sg specifies the Day of Calendar Reform.

 
               # File date.rb, line 1619
def self.parse(str='-4712-01-01T00:00:00+00:00', comp=false, sg=ITALY)
  elem = _parse(str, comp)
  new_by_frags(elem, sg)
end
            
strptime(str='-4712-01-01T00:00:00+00:00', fmt='%FT%T%z', sg=ITALY) click to toggle source

Create a new DateTime object by parsing from a String according to a specified format.

str is a String holding a date-time representation. fmt is the format that the date-time is in. See date/format.rb for details on supported formats.

The default str is ‘-4712-01-01T00:00:00+00:00’, and the default fmt is ‘%FT%T%z’. This gives midnight on Julian Day Number day 0.

sg specifies the Day of Calendar Reform.

An ArgumentError will be raised if str cannot be parsed.

 
               # File date.rb, line 1599
def self.strptime(str='-4712-01-01T00:00:00+00:00', fmt='%FT%T%z', sg=ITALY)
  elem = _strptime(str, fmt)
  new_by_frags(elem, sg)
end
            

Public Instance Methods

strftime(fmt='%FT%T%:z') click to toggle source
 
               # File date/format.rb, line 1158
def strftime(fmt='%FT%T%:z')
  super(fmt)
end
            
to_s() click to toggle source

:minute, :second, :second_fraction

 
               # File date.rb, line 1627
def to_s # 4p
  format('%.4d-%02d-%02dT%02d:%02d:%02d%s',
         year, mon, mday, hour, min, sec, zone)
end
            

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.

blog comments powered by Disqus