TITLE
    WebObjects Year 2000 Technical Tips
Article ID:
Created:
Modified:
70048
3/25/99
11/5/99

TOPIC

    This article discusses ways developers can avoid causing Year 2000 problems in their code, including some issues relating specifically to Apple's OPENSTEP and WebObjects frameworks and API's. This article does not discuss the Year 2000 compliance status of any Apple product; for Y2K compliance information, see the Apple Year 2000 main page at http://www.apple.com/ about/year2000 .

    The following are tips for programmers; we hope they will help you avoid some common problems in your code, and identify problems in your legacy code for remediation.


DISCUSSION

    Working with Dates in WebObjects

    A detailed overview of date handling in WebObjects is now available for download in PDF format .

    Use Consistent Date Handling

    Consistency in date hanlding makes maintaining and fixing date-handling code easier. Apple recommends that you always use the Foundation date and time API's when you need to write date-handling code for OPENSTEP or WebObjects.

    Don't Divide By an NSTimeInterval Value

    Dates are represented in the Foundation framework with NSDate and NSCalendarDate objects and NSTimeInterval values. An NSTimeInterval object is essentially a C-language double ( NSTimeInterval can represent intervals of approximately 10,000 years with sub-millisecond accuracy). NSDate and NSCalendarDate store the date that they represent with an NSTimeInterval which represents the time delta in seconds from the Foundation reference date (00:00:00 Greenwich Mean Time January 1, 2000). Since the internal time representation will transition across zero at the reference date, there will be a brief instant (on the order of microseconds in length) during which an NSDate object created to represent the current time will have an NSTimeInterval of zero. An NSTimeInterval of zero has no special significance to NSDate or NSCalendarDate , but applications that use the NSTimeInterval of a date object in division should protect against division by zero. This is unlikely to occur in real-world applications.

    Avoid Two-Digit Date Formats


    Always use four-digit years when formatting dates for input or output; a four-digit year is the only unambiguous way to refer to any date. The Foundation framework's date formatting objects may interpret two-digit year values in unexpected ways, and using the two-digit "%y" format allows no way for a user to present a date unambiguously and may cause additional problems; for example, typing "2004" into a two-digit year formatted field result in a value of "20" being used and "04" being truncated. Instead, use the four-digit "%Y" year format.


Document Information
Product Area: WebObjects
Category: Objective C; WebObjects 3.0 and 3.1; WebObjects 3.5.1; WebObjects 4
Sub Category: Development

Copyright © 2000 Apple Computer, Inc. All rights reserved.