date2 - An alternative date class

Date

Super Class

Object

Included Modules

Comparable

Class Methods

exist2?(year, day-of-year[, start=ITALY])

Returns a Julian day number if the given ordinal date is an existent day, and nil if not.

See also new1 and new2.

exist3?(year, month, day-of-month[, start=ITALY])
exist? (year, month, day-of-month[, start=ITALY])

Returns a Julian day number if the given calendar date is an existent day, and nil if not.

See also new1 and new3.

existw?(year, week, day-of-week[, start=ITALY])

Returns a Julian day number if the given calendar week is an existent day, and nil if not.

See also new1 and neww.

new1([jd=0[, start=ITALY]])

Creates a date object denoting the given Julian day number.

The Julian day number is in elapsed days since noon (Greenwich mean time) on January 1, 4713 BCE (in the Julian calendar).

In this class, the Julian day number is used only as a serial number for dates; hence it usually has no fractions (It suggests that it is noon).

In this class, some important methods do not accept negative Julian day numbers.

See also new3.

new2([year=-4712[, day-of-year=1[, start=ITALY]]])

Creates a date object denoting the given ordinal date.

The ordinal date is a particular day of a calendar year identified by its ordinal number within the year.

The day of year should be a negative or a positive number (reverse order when negative). It must not be zero.

See also new1 and new3.

new3([year=-4712[, month=1[, day-of-month=1[, start=ITALY]]]])
new ([year=-4712[, month=1[, day-of-month=1[, start=ITALY]]]])

Creates a date object denoting the given calendar date.

The calendar date is a particular day of a calendar year, identified by its ordinal number within a calendar month within that year.

In this class, BCE years are counted astronomically. Thus, the year before the year 1 is the year zero, and the year preceding the year zero is the year -1.

The month and the day of month should be a negative or a positive number (reverse order when negative). They must not be zero.

The optional last argument should be a Julian day number which denotes the first day of the Gregorian calendar. You can also give true instead of Big bang (the proleptic Gregorian calendar is requested), and false instead of Big crunch (the proleptic Julian calendar is requested).

See also new1.

neww([year=1582[, week=41[, day-of-week=5[, start=ITALY]]]])

Creates a date object denoting the given calendar week.

The calendar week is a seven day period within a calendar year, starting on a Monday and identified by its ordinal number within the year; the first calendar week of the year is the one that includes the first Thursday of that year. In the Gregorian calendar, this is equivalent to the week which includes January 4.

The week and the day of week should be a negative or a positive number (reverse order when negative). They must not be zero.

This method does not accept dates before the day of calendar reform.

See also new1 and new3.

today([start=ITALY])

Creates a date object denoting the present day.

Methods

self + n

Returns a date object pointing n days after self. The n should be a numeric value.

self - x

Returns the difference between the two dates if the x is a date object. If the x is a numeric value, it returns a date object pointing x days before self.

self << n

Returns a date object pointing n months before self. The n should be a numeric value.

self <=> other

Compares the two dates and returns -1, zero or 1. The other should be a date object or a numeric value as a Julian day number.

self === other

Returns true if they are the same day.

self >> n

Returns a date object pointing n months after self. The n should be a numeric value.

cwday

Returns the day of calendar week (1-7, Monday is 1).

cweek

Returns the calendar week number (1-53).

cwyear

Returns the calendar week based year.

downto(min){|date| ...}

This method is equivalent to step(min, -1){|date| ...}.

england

This method is equivalent to newsg(Date::ENGLAND).

gregorian

This method is equivalent to newsg(Date::GREGORIAN).

italy

This method is equivalent to newsg(Date::ITALY).

jd

Returns the Julian day number.

julian

This method is equivalent to newsg(Date::JULIAN).

ld

Returns the Lilian day number.

The Lilian day number is day count since October 15, 1582 CE (in the Gregorian calendar).

leap?

Returns true if the year is a leap year.

mday
day

Returns the day of month (1-31).

mjd

Returns the modified Julian day number (as noon).

the modified Julian day number is in elapsed days since midnight (Coordinated universal time) on November 17, 1858 CE (in the Gregorian calendar).

mon
month

Returns the month (1-12).

newsg([start=Date::ITALY])

Duplicates self and resets the its first day of the Gregorian calendar.

See also new3.

sg

Returns a Julian day number denoting the first day of the Gregorian calendar.

See also new3.

step(limit, step){|date| ...}

Iterates evaluation of the given block, which takes a date object. The limit should be a date object, and the step should be a nonzero value.

succ
next

Returns a date object denoting the following day.

tjd

Returns the truncated Julian day number (as noon).

In this class, the truncated Julian day number is in elapsed days since midnight (Coordinated universal time) on May 24, 1968 CE (in the Gregorian calendar).

I do not recommend you to use TJD at all.

tjd2

Returns a pair of "FLOOR(tjd/10000)" and "tjd MOD 10000". The second element is another TJD. It may be true TJD. See CCSDS 301.0-B-2.

I do not recommend you to use TJD at all.

to_s

Returns a string in an ISO 8601:1988 format (CCYY-MM-DD).

upto(max){|date| ...}

This method is equivalent to step(max, 1){|date| ...}.

wday

Returns the day of week (0-6, Sunday is zero).

yday

Returns the day of year (1-366).

year

Returns the year.

date3 - Yet another date class

Date

date3 is an alternative date class that can also handle times. This class is still experimental.

holiday - determination of secular and religious holidays

These methods work with date2 or date3.

This module also have some methods to determine Japanese national holidays. They're quite useful in the country where I live.

Date

Class Methods

gregorian_easter(year[, start=ITALY])
easter(year[, start=ITALY])

Returns a date object denoting the Easter sunday in the given Gregorian year.

julian_easter(year[, start=ITALY])

Returns a date object denoting the Easter sunday in the given Julian year.

nth_kday(n, k, year, month[, start=ITALY])

Returns a date object denoting the given Nth (-5 to 5, except zero) Kday (0-6) in the given month of year.

Methods

easter?

Returns true if the day is an Easter sunday.

nth_kday?(n, k)

Returns true if the day is an Nth (-5 to 5, except zero) Kday (0-6).

qholiday - determination of Japanese old national holidays

This module provides some methods to determine Japanese old national holidays. This module is still experimental.

parsedate[23] - parse date and time

ParseDate

This is an alternative parsedate module.

This module provides a method which parses the given representation of dates and times. It accepts ctime(3), traditional date(1), RFC 822 date, RFC 850 date, part of ISO 8601, part of JIS X0301 extensions, and etc.

strftime - format date and time

Date

This method works with date2 or date3.

This method formats the date with the given template. It supports the following conversion specifications:

%A, %a, %B, %b, %C, %c, %D, %d, %e, %F, %G, %g, %H, %h, %I, %j, %k, %l, %M, %m, %n, %P, %p, %R, %r, %S, %s, %T, %t, %U, %u, %V, %v, %W, %w, %X, %x, %Y, %y, %Z, %z, %%, %+, %1, %2, %3

See strftime(3).

strptime - parse date and time

Date

This class method works with/without date2 or date3.

This method parses the given representation of dates and times with the given template.

See strptime(3).