Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.misc > #5011

Re: The 8-Byte Two-Step

From Marko Rauhamaa <marko@pacujo.net>
Newsgroups comp.misc
Subject Re: The 8-Byte Two-Step
Date 2014-09-21 14:14 +0300
Organization A noiseless patient Spider
Message-ID <87d2ap2pjn.fsf@elektro.pacujo.net> (permalink)
References <01T8OImfoeUtayhTm1xJJ0vS@dont-email.me> <c86928Fkug2U4@mid.individual.net> <87ppeq2car.fsf@elektro.pacujo.net> <c87gfnFkjjcU1@mid.individual.net>

Show all headers | View raw


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.


Marko

Back to comp.misc | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


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