|
February 21, 2001 Debugging Date-Based Scripts Tips: February 2001
Yehuda Shiran, Ph.D.
|
|
Debugging a script for date handling and manipulation is not trivial. Your script usually starts with today's Date object, but you want to test your script for other days as well. You can accomplish it by setting the Date object's date. You can go forward or backward in time, by using the object's setTime() method. This method expects to get the number of milliseconds since 1970. The easiest way to compute it is by adding or subtracting from the current time. The current time is computed by the object's getTime() method. To set the Date object to the day before yesterday, you would write:
Once you set the Date object to whatever date you want, you can debug your script as if the current day is two days ago. For example, you can test the function getDeliveryDateObj(), mimicking the day before yesterday as the current date:
Click here to get the delivery date in 8 business days, starting from the day before yesterday.
People who read this tip also read these tips: Look for similar tips by subject: |