Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Christian Neukirchen <chneukirchen@gmail.com> |
|---|---|
| Newsgroups | comp.misc |
| Subject | Re: The 8-Byte Two-Step |
| Date | 2014-09-23 18:26 +0200 |
| Organization | [ posted via ] IN-Ulm |
| Message-ID | <87lhpawbe4.fsf@gmail.com> (permalink) |
| References | <01T8OImfoeUtayhTm1xJJ0vS@dont-email.me> <c86928Fkug2U4@mid.individual.net> <87ppeq2car.fsf@elektro.pacujo.net> <c87gfnFkjjcU1@mid.individual.net> <87d2ap2pjn.fsf@elektro.pacujo.net> |
Marko Rauhamaa <marko@pacujo.net> writes:
> Bob Eager <news0002@eager.cx>:
>
>> On Sun, 21 Sep 2014 00:48:44 +0300, Marko Rauhamaa wrote:
>>> def gregorian_day_count(isodate):
>>> year, month, day = map(int, isodate.split('-'))
>>> a, b = divmod(12 * year + month + 1185, 12)
>>> return int(a * 365.2425) + int(30.573 * b + 0.706) + day
>>
>> [...]
>>
>> Didn't know that one...thanks!
>
> Except, you shouldn't believe everything you read on the Internet :) --
> the above code had a bug which I noticed when I actually tested it.
>
> Here's a correction:
>
> def gregorian_day_count(isodate):
> year, month, day = map(int, isodate.split('-'))
> a, b = divmod(12 * year + month - 3, 12)
> yeardays = a * 365 + a // 4 - a // 100 + a // 400
> return yeardays + int(30.573 * b + 0.706) + day
>
> If you intend to use the code, you're well advised to test it yourself.
I found this one, which is similar in spirit but doesn't depend on
floats:
http://alcor.concordia.ca/~gpkatch/gdate-algorithm.html
function g(y,m,d)
m = (m + 9) % 12
y = y - m/10
return 365*y + y/4 - y/100 + y/400 + (m*306 + 5)/10 + ( d - 1 )
--
Christian Neukirchen <chneukirchen@gmail.com> http://chneukirchen.org
Back to comp.misc | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
The 8-Byte Two-Step Rich <rich@example.invalid> - 2014-09-20 20:41 +0000
Re: The 8-Byte Two-Step Bob Eager <news0002@eager.cx> - 2014-09-20 21:14 +0000
Re: The 8-Byte Two-Step Marko Rauhamaa <marko@pacujo.net> - 2014-09-21 00:48 +0300
Re: The 8-Byte Two-Step Bob Eager <news0002@eager.cx> - 2014-09-21 08:27 +0000
Re: The 8-Byte Two-Step Marko Rauhamaa <marko@pacujo.net> - 2014-09-21 14:14 +0300
Re: The 8-Byte Two-Step Marko Rauhamaa <marko@pacujo.net> - 2014-09-23 11:19 +0300
Re: The 8-Byte Two-Step Christian Neukirchen <chneukirchen@gmail.com> - 2014-09-23 18:26 +0200
Re: The 8-Byte Two-Step mm0fmf <none@mailinator.com> - 2014-09-21 20:45 +0100
Re: The 8-Byte Two-Step Sylvia Else <sylvia@not.at.this.address> - 2014-09-21 13:42 +1000
csiph-web