Assembling Dates From Components


The functions Hour , Minute, Second, Year, Month, and Day are used to break a date into parts . The functions DateSerial and TimeSerial are used to put the dates back together again. The function DateSerial creates a Date object from the year, month, and day. The function TimeSerial creates a Date object from the hours, minutes, and seconds.

 Print DateSerial(2003, 10, 1) '10/02/2003 Print TimeSerial(13, 4, 45)   '13:04:45 

The first argument to the DateSerial function is the year, the second argument is the month, and the final argument is the day. If the month or day aren't valid values, a run-time error occurs. Year values greater than 100 are used directly. Year values less than 100, however, have 1900 added to them. Two-digit years are mapped to the years 1900 and later (see Listing 10 ).

Listing 10: DateSerial adds 1900 to years earlier than 100.
start example
 Print DateSerial(2003, 10,  1) '10/01/2003 Print DateSerial(1899, 12, 31) '12/31/1899 Print DateSerial(1899, 12, 30) '00:00:00 Print DateSerial(1899, 12, 29) '12/29/1899 Print DateSerial(1899, 12, 28) '12/28/1899 Print DateSerial(  99, 10,  1) '10/01/1999 Print DateSerial(   3, 10,  1) '10/01/1903 Print DateSerial(   0,  1,  1) '01/01/1900 Print DateSerial(  -3, 10,  1) '10/01/1897 Print DateSerial( -99, 10,  1) '10/01/1801 Print DateSerial(-100, 10,  1) '10/01/1800 
end example
 
Compatibility  

Visual Basic maps years from 0 through 23 to 2000. VB also allows for out-of-range values to the DateSerial function with unusual results.

Bug  

OOo Basic adds 1900 to years earlier than 100, including negative years. An error is generated if the resulting year is still lower than 100. This allows years from -1801 through -1, which should probably be an error. The Date type is able to handle dates prior to 1/1/00, but obviously, DateSerial cannot.

Various calendar systems have been used at different times and places around the world. The Gregorian calendar, on which OOo Basic is based, is used almost universally . The predecessor to the Gregorian calendar is the Julian calendar. The two calendars are almost identical, differing only in how they handle leap years. The Julian calendar has a leap year every fourth year, while the Gregorian calendar has a leap year every fourth year except century years that aren't exactly divisible by 400.

The change from the Julian calendar to the Gregorian calendar occurred in October of 1582, based on a scheme instituted by Pope Gregory XIII. The Julian calendar was used through October 4, 1582, at which point 10 days were skipped and it became October 15, 1582. Typically, for dates on or before 4 October 1582, the Julian calendar is used; for dates on or after 15 October 1582, the Gregorian calendar is used. Thus, there is a 10-day gap in calendar dates, but no discontinuity in Julian dates or days of the week. Astronomers, however, typically use Julian dates because they don't have a 10-day gap; discontinuous dates do not typically work well in numerical calculations. As seen in Listing 11 , Dates are printed based on the Gregorian calendar, but when the component parts are extracted, they are based on the Julian date.

Listing 11: DateSerial accepts Gregorian dates before 10/15/1582.
start example
 Print DateSerial(1582, 10, 15)      '10/15/1582 Print DateSerial(1582, 10, 14)      '10/04/1582 Print Day(DateSerial(1582, 10, 14)) '14 
end example
 



OpenOffice.org Macros Explained
OpenOffice.org Macros Explained
ISBN: 1930919514
EAN: 2147483647
Year: 2004
Pages: 203

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net