Download these great examples that show how to parse the date and time, and return the weekday, day, month, year, and century. No Xtras required for D6 and Shockwave 6
There is an error in Example 11-7 on page 314. Hey, I wrote it a year and a half ago and I screwed up. Tim Ryan finally noticed and told me about it. (Don't blame my tech editors. This was snuck in at the last minute before Y2K was all the rage.)
I originally intended to show how to handle the case where you didn't know the century. For example, Lingo's "the date" property returns the year without the century, such as:
put the date -- "01/21/00"
A programmer relying on such a date could mistakenly create a non-compliant
application. But Example 11-7 used the getDate()
function (included
in Director 6.5's UI Helper Xtra), which returns the year since 1900. For
Example, January 21, 2000 is returned as: [100, 1, 21], such as:
put getDate() -- [100, 1, 21]
Director 7 users can use the new the sytemDate
property
or systemDate()
function which returns the year and the century.
Note that the year 1999 is returned as 1999, and the year 2000 is returned
as 2000. For example,
put the systemDate -- date( 2000, 1, 21 ) put (the systemDate).year -- 2000
There are also third-party Xtras such as the DateMaster
Xtra that includes the century when reporting the year. (The DateMaster
Xtra also has a number of fancy functions, many of which have been replaced
by D7's systemDate()
function and date()
objects)
Below is a corrected version of Example 11-7 for D6.5 users, plus a version more appropriate the Director 7, which is substantially simpler!
-- Example 11-7: Projector Expiration and Y2K -- This requires the UI Helper Xtra included with D6.5 -- Example: -- checkForExpiration 06, 09, 1999 on checkForExpiration expireMonth, expireDay, expireYear set expire = FALSE set today = getDate() set year = getAt(today, 1) -- This was wrong -- if year > 50 then -- set year = year + 1900 -- else -- set year = year + 2000 -- end if -- Use this instead: year = year + 1900 set month = getAt(today,2) set day = getAt(today,3) -- Comparing dates is non-trivial prior to Director 7! if year > expireYear then set expire = TRUE else if year = expireYear then if month > expireMonth then set expire = TRUE else if month = expireMonth and day >= expireDay then set expire = TRUE end if end if if expire = TRUE then alert "Sorry, this program expired" && expireMonth & "/" & expireDay & "/" & expireYear halt end if end checkForExpiration -- Here is a Director 7 version: -- Note that the systemDate returns a "date object" of the form: -- date (yearWithCentury, month, day) on checkForExpirationD7 expireMonth, expireDay, expireYear if the systemDate > date(expireYear, expireMonth, expireDay) then alert "Sorry, this program expired" && expireMonth & "/" & expireDay & "/" & expireYear halt end if end checkForExpirationD7
Zeus Home Page | LIAN TOC | DIAN TOC | Links | E-Mail
Place an Order | Downloads
| FAQ | GuestBook
| Glossary
Copyright © 1996-2000 Bruce A. Epstein. All Rights Reserved.
(The page last revised January 21, 2000)