Re: [PATCH] date: avoid "X years, 12 months" in relative dates

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jeff King venit, vidit, dixit 20.04.2011 12:18:
> On Wed, Apr 20, 2011 at 11:12:11AM +0200, Michael J Gruber wrote:
> 
>> Implement this differently with months of size
>>
>>   onemonth = 365/12
>>
>> so that
>>
>>   totalmonths = (long)( (days + onemonth/2)/onemonth )
>>   years = totalmonths / 12
>>   months = totalmonths % 12
>>
>> In order to do this without floats, we write the first formula as
>>
>>   totalmonths = (days*12*2 + 365) / (365*2)
> 
> Well now I feel like an idiot. Algebra to the rescue.

:)

> The extra multiplications introduce the possibility of overflow, but
> since the number of days was arrived at by dividing an unsigned long
> number of seconds by 86400, we are guaranteed to have room to multiply
> by 24. :)

Also, this is inside "if (diff < 1825)", so no matter where diff comes
from, "long" is really long enough.

Cheers,
Michael
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]