Re: NSTimestamp calculations?
On Jul 27, 2006, at 10:17 AM, [EMAIL PROTECTED] wrote: From: [EMAIL PROTECTED] Subject: NSTimestamp calculations? Whats the easiest way to subtract NSTimestamps from each other? The methods getMinutes() etc both from NSTimestamp and Date are unfortunately deprecated :-( The getTime() method is your friend! here are a few useful methods from my NSTimestampHelper bag-o-tricks... public static int deltaDays( NSTimestamp one, NSTimestamp two ) { long diff = two.getTime() - one.getTime(); // diff is in milliseconds long roundingOffset = ( diff >= 0 ) ? 12 : -12; // if diff is positive, offset up, if negative, offset down // next, convert diff to hours, offset by .5 days to round the end result, divide by 24 and truncate. long days = ( ( diff / ( 1000 * 60 * 60 ) ) + roundingOffset ) / 24; return (int)days; } public static int deltaHours( NSTimestamp one, NSTimestamp two ) { long diff = two.getTime() - one.getTime(); // diff is in milliseconds long roundingOffset = ( diff >= 0 ) ? 30 : -30; // if diff is positive, offset up, if negative, offset down // next, convert diff to minutes, offset by .5 hour to round the end result, divide by 60 and truncate. long hours = ( ( diff / ( 1000 * 60 ) ) + roundingOffset ) / 60; return (int)hours; } public static int deltaMinutes( NSTimestamp one, NSTimestamp two ) { long diff = two.getTime() - one.getTime(); // diff is in milliseconds long roundingOffset = ( diff >= 0 ) ? 30 : -30; // if diff is positive, offset up, if negative, offset down // next, convert diff to seconds, offset by .5 minute to round the end result, divide by 60 and truncate. long minutes = ( ( diff / ( 1000 ) ) + roundingOffset ) / 60; return (int)minutes; } Enjoy!! Alex __alex cone ceo c o d e f a b inc [EMAIL PROTECTED] 212.465.8484 x101 http://www.codefab.com "The perversity of the universe tends towards a maximum." Entropy, expressed as Finagle's (Murphy's) 1st Law ___ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (Webobjects-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com This email sent to archive@mail-archive.com
Re: NSTimestamp calculations?
You can use getTime() [EMAIL PROTECTED] schrieb: Whats the easiest way to subtract NSTimestamps from each other? The methods getMinutes() etc both from NSTimestamp and Date are unfortunately deprecated :-( ___ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (Webobjects-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/webobjects-dev/stefan.klein%40kess-gmbh.de This email sent to [EMAIL PROTECTED] ___ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (Webobjects-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com This email sent to archive@mail-archive.com
Re: NSTimestamp calculations?
First off, you can not reply to another message and change the subject - it messes up people who view by thread, and also screws up the archived version of the list.To answer your question, there are a few ways. If I have minutes or hours that I want to add or subject from an existing timestamp, I use:timestampByAddingGregorianUnits(int years, int months, int days, int hours, int minutes, int seconds) If you have 2 timestamps and you want to do some manipulations, you really should convert it to GregorianCalendar - I typically do this:NSTimestamp settlementDateTime = (NSTimestamp) frame.valueForKey(Definition.settlementDate);GregorianCalendar cal = new GregorianCalendar();cal.setTime(settlementDateTime);int year = cal.get(GregorianCalendar.YEAR);int dayOfMonth = cal.get(GregorianCalendar.DAY_OF_MONTH);int month = cal.get(GregorianCalendar.MONTH);NSTimestamp settlementDate = new NSTimestamp(year, month+1, dayOfMonth, 0, 0, 0, TimeZone.getTimeZone("GMT"));KenOn Jul 27, 2006, at 10:16 AM, [EMAIL PROTECTED] wrote:Whats the easiest way to subtract NSTimestamps from each other?The methods getMinutes() etc both from NSTimestamp and Date are unfortunately deprecated :-( ___Do not post admin requests to the list. They will be ignored.Webobjects-dev mailing list (Webobjects-dev@lists.apple.com)Help/Unsubscribe/Update your Subscription:http://lists.apple.com/mailman/options/webobjects-dev/lists%40anderhome.comThis email sent to [EMAIL PROTECTED] ___ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (Webobjects-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com This email sent to archive@mail-archive.com
NSTimestamp calculations?
Whats the easiest way to subtract NSTimestamps from each other? The methods getMinutes() etc both from NSTimestamp and Date are unfortunately deprecated :-( ___ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (Webobjects-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com This email sent to archive@mail-archive.com