Class | DateTime |
In: |
lib/date/format.rb
lib/date.rb |
Parent: | Date |
Class representing a date and time.
See the documentation to the file date.rb for an overview.
DateTime objects are immutable once created.
The following methods are defined in Date, but declared private there. They are made public in DateTime. They are documented here.
Get the hour-of-the-day of the time. This is given using the 24-hour clock, counting from midnight. The first hour after midnight is hour 0; the last hour of the day is hour 23.
Get the minute-of-the-hour of the time.
Get the second-of-the-minute of the time.
Get the fraction of a second of the time. This is returned as a Rational. The unit is in days. I do NOT recommend you to use this method.
Get the time zone as a String. This is representation of the time offset such as "+1000", not the true time-zone name.
Get the time zone offset as a fraction of a day. This is returned as a Rational.
Create a new DateTime object, identical to the current one, except with a new time zone offset of of. of is the new offset from UTC as a fraction of a day.
civil | -> | new |
# File lib/date/format.rb, line 1162 1162: def self._strptime(str, fmt='%FT%T%z') 1163: super(str, fmt) 1164: end
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 lib/date.rb, line 1520 1520: def self.civil(y=-4712, m=1, d=1, h=0, min=0, s=0, of=0, sg=ITALY) 1521: unless (jd = valid_civil?(y, m, d, sg)) && 1522: (fr = valid_time?(h, min, s)) 1523: raise ArgumentError, 'invalid date' 1524: end 1525: if String === of 1526: of = Rational(zone_to_diff(of) || 0, 86400) 1527: end 1528: new!(jd_to_ajd(jd, fr, of), of, sg) 1529: end
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 lib/date.rb, line 1548 1548: def self.commercial(y=1582, w=41, d=5, h=0, min=0, s=0, of=0, sg=ITALY) 1549: unless (jd = valid_commercial?(y, w, d, sg)) && 1550: (fr = valid_time?(h, min, s)) 1551: raise ArgumentError, 'invalid date' 1552: end 1553: if String === of 1554: of = Rational(zone_to_diff(of) || 0, 86400) 1555: end 1556: new!(jd_to_ajd(jd, fr, of), of, sg) 1557: end
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 lib/date.rb, line 1470 1470: def self.jd(jd=0, h=0, min=0, s=0, of=0, sg=ITALY) 1471: unless (jd = valid_jd?(jd, sg)) && 1472: (fr = valid_time?(h, min, s)) 1473: raise ArgumentError, 'invalid date' 1474: end 1475: if String === of 1476: of = Rational(zone_to_diff(of) || 0, 86400) 1477: end 1478: new!(jd_to_ajd(jd, fr, of), of, sg) 1479: end
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 lib/date.rb, line 1495 1495: def self.ordinal(y=-4712, d=1, h=0, min=0, s=0, of=0, sg=ITALY) 1496: unless (jd = valid_ordinal?(y, d, sg)) && 1497: (fr = valid_time?(h, min, s)) 1498: raise ArgumentError, 'invalid date' 1499: end 1500: if String === of 1501: of = Rational(zone_to_diff(of) || 0, 86400) 1502: end 1503: new!(jd_to_ajd(jd, fr, of), of, sg) 1504: end
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 lib/date.rb, line 1620 1620: def self.parse(str='-4712-01-01T00:00:00+00:00', comp=false, sg=ITALY) 1621: elem = _parse(str, comp) 1622: new_by_frags(elem, sg) 1623: end
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 lib/date.rb, line 1600 1600: def self.strptime(str='-4712-01-01T00:00:00+00:00', fmt='%FT%T%z', sg=ITALY) 1601: elem = _strptime(str, fmt) 1602: new_by_frags(elem, sg) 1603: end