commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From __matthewHawthorne <ma...@phreaker.net>
Subject Re: [lang] possible DateUtils method
Date Mon, 24 Nov 2003 23:31:46 GMT
I believe it's

cvs diff -u

And the most efficient way is to open up an enhancement entry in 
Bugzilla and attach the patch there.  That way it won't get lost in the mix.




Inger, Matthew wrote:
> If i can figure out how to do the patch.  is it
> 	
> 	diff -n
> 
> ?????
> 
> Then do i just post the diff along with the test diff
> to the newsgroup?
> 
> -----Original Message-----
> From: Stephen Colebourne [mailto:scolebourne@btopenworld.com]
> Sent: Monday, November 24, 2003 6:12 PM
> To: Jakarta Commons Developers List
> Subject: Re: [lang] possible DateUtils method
> 
> 
> I think this would make a good addition to DateUtils. Would you like to
> provide a patch and tests?
> 
> Stephen
> 
> ----- Original Message -----
> From: "Inger, Matthew" <inger@Synygy.com>
> 
>>public static final long MILLIS_IN_DAY = 1000*60*60*24;
>>
>>public long getDaysBetween(Calendar c1, Calendar c2)
>>{
>>long c1Normalized = c1.getTime().getTime() +
>>                          c1.get(Calendar.ZONE_OFFSET) +
>>                          c1.get(Calendar.DST_OFFSET);
>>
>>long c2Normalized = c2.getTime().getTime() +
>>                          c2.get(Calendar.ZONE_OFFSET) +
>>                          c2.get(Calendar.DST_OFFSET);
>>
>>long diff = c1Normalized - c2Normalized;
>>
>>long numDays = diff / MILLIS_IN_DAY;
>>
>>return numDays;
>>}
>>
>>A common mistake most people make is to ignore daylight savings
>>time when trying to compute the number of days between two Calendar
>>dates.  If you cross the DST boundary when the clock jumps forward,
>>just subtracting the date objects and dividing will end up giving you
>>an answer that is off by 1 day.  This happens because the clock jumps
>>ahead, and 00:00 EDT is actually 11:00 EST on the previous day, so the
>>number of hours is off by 1, and thus the calculation doesn't end up
> 
> working
> 
>>properly.  The other thing i'm doing here is to convert to GMT time,
>>allowing
>>for the two Calendar objects to have different timezones.
>>
>>We could have similar methods for getHoursBetween and so forth.  Months
>>would be a bit more complicated of an algorithm.
>>
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message