| Class | Date |
| In: |
lib/vpim/date.rb
|
| Parent: | Object |
Extensions to the standard library Date.
| TIME_START | = | Date.new(1970, 1, 1) |
| SECS_PER_DAY | = | 24 * 60 * 60 |
Create a new Date object for the date specified by year year, month mon, and day-of-the-week wday.
The nth, n, occurrence of wday within the period will be generated (n defaults to 1). If n is positive, the nth occurrence from the beginning of the period will be returned, if negative, the nth occurrence from the end of the period will be returned.
The period is a year, unless month is non-nil, in which case it is just that month.
Examples:
Compare this to Date.new, which allows a Date to be created by day-of-the-month, mday, to Date.ordinal, which allows a Date to be created by day-of-the-year, yday, and to Date.commercial, which allows a Date to be created by day-of-the-week, but within a specific week.
If wday responds to to_str, convert it to the wday number by searching for a wday that matches, using as many characters as are in wday to do the comparison. wday must be 2 or more characters long in order to be a unique match, other than that, "mo", "Mon", and "MonDay" are all valid strings for wday 1.
This method can be called on a valid wday, and it will return it. Perhaps it should be called by default inside the Date#new*() methods so that non-integer wday arguments can be used? Perhaps a similar method should exist for months? But with months, we all know January is 1, who can remember where Date chooses to start its wday count!
Examples:
Date.bywday(2004, 2, Date.str2wday('TU')) => the first Tuesday in
February
Date.bywday(2004, 2, Date.str2wday(2)) => the same day, but notice
that a valid wday integer can be passed right through.
Return the first day of the week for the specified date. Commercial weeks start on Monday, but the weekstart can be specified (as 0-6, where 0 is sunday, or in formate of Date.str2day).
Converts this object to a Time object, or throws an ArgumentError if conversion is not possible because it is before the start of epoch.