• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSTimeStamp
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTimeStamp


  • Subject: Re: NSTimeStamp
  • From: Art Isbell <email@hidden>
  • Date: Fri, 14 Feb 2003 10:26:17 -1000

On Thursday, February 13, 2003, at 08:33  PM, Dan wrote:

What's a good replacement for the deprecated method
gregorianUnitsSinceTimestamp?  I need to calculate the number of years,
months, days, hours, minutes, and seconds between 2 dates.

I haven't found one. Date operation conversion when moving to WO 5 from an earlier version was the most challenging aspect of the conversion process for me. First, the Java date classes are a mess. Second, JDBC doesn't support timestamp with time zone data, so all timestamps are in GMT (UTC).


The initial Java implementation was poorly-designed, but to maintain backward compatibility, it must remain but with much of it deprecated. Apple has overlain this mess with NSTimestamp and NSTimeZone to support WO better. The NSTimestamp JavaDoc has a few examples of common date operations, but not calculating the difference between 2 timestamps broken down in date components. Because Java doesn't support pointers and because Apple's pointer hack (IntRef) is no longer supported, it's not easy to write a single Java method that returns years, months, days, hours, minutes, and seconds between 2 timestamps. I think date differences must be calculated starting with the difference between 2 timestamps in milliseconds and then calculating how many years are in those milliseconds, how many months are in the remainder of milliseconds, etc. Pretty ugly. Maybe this is where you write a TimestampContainer class and a static utility method, gregorianUnitsSinceTimestamp(NSTimestamp aFromTimestamp, NSTimestamp aToTimestamp, TimestampContainer aTimeInterval), that populates the TimestampContainer with the years, months, days, hours, minutes, and seconds between the 2 timestamps. Anyone got another suggestion?

If you depend on time zone info being in your dates, you'll need to manage those manually, frequently by creating a separate database column that stores the time zone description (e.g., "America/Los Angeles") of the timestamp being stored. Trying to make all of this work correctly makes my head spin. This stuff worked so seamlessly using the old Objective-C NSCalendarDate and its bridged Java equivalent, NSGregorianDate, but those days are gone :-(

Art
http://homepage.mac.com/aisbell/
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >NSTimeStamp (From: "Dan" <email@hidden>)

  • Prev by Date: Re: How to get Java 1.3 JDK for WO Development?
  • Next by Date: Re: WebObjects 5.1.4 on Mac OSX 10.2.3
  • Previous by thread: NSTimeStamp
  • Next by thread: Re: NSTimeStamp
  • Index(es):
    • Date
    • Thread