Обсуждение: BC date getting misinterpreted?

Поиск
Список
Период
Сортировка

BC date getting misinterpreted?

От
Joe Abbate
Дата:
The test case is fairly simple:

curs.execute("SELECT '044-03-15 BC'::date")
rows = curs.fetchall()

This results in:

ValueError: year -43 is out of range

[This is Python 3.6, in 2.7, the value is missing]

This was working since last October, but the error started happening 
around the Ides of March (my actual dates are different, but I changed 
the example to fit :-)

Tested against 9.3 thru 10.

Joe


Re: BC date getting misinterpreted?

От
Christophe Pettus
Дата:
In both 2.7 and 3.6, datetime.MINYEAR is 1, so I'm a bit surprised this ever worked.

> On Mar 26, 2018, at 16:11, Joe Abbate <jma@freedomcircle.com> wrote:
>
> The test case is fairly simple:
>
> curs.execute("SELECT '044-03-15 BC'::date")
> rows = curs.fetchall()
>
> This results in:
>
> ValueError: year -43 is out of range
>
> [This is Python 3.6, in 2.7, the value is missing]
>
> This was working since last October, but the error started happening around the Ides of March (my actual dates are
different,but I changed the example to fit :-) 
>
> Tested against 9.3 thru 10.
>
> Joe
>

--
-- Christophe Pettus
   xof@thebuild.com



Re: BC date getting misinterpreted?

От
Christophe Pettus
Дата:
To be a bit more useful ( :) ), if you really need to deal with proleptic Gregorian dates that far back, you might
considerreading it out as a string and using Astropy for date arithmetic: 

    http://www.astropy.org

> On Mar 26, 2018, at 16:15, Christophe Pettus <xof@thebuild.com> wrote:
>
> In both 2.7 and 3.6, datetime.MINYEAR is 1, so I'm a bit surprised this ever worked.
>
>> On Mar 26, 2018, at 16:11, Joe Abbate <jma@freedomcircle.com> wrote:
>>
>> The test case is fairly simple:
>>
>> curs.execute("SELECT '044-03-15 BC'::date")
>> rows = curs.fetchall()
>>
>> This results in:
>>
>> ValueError: year -43 is out of range
>>
>> [This is Python 3.6, in 2.7, the value is missing]
>>
>> This was working since last October, but the error started happening around the Ides of March (my actual dates are
different,but I changed the example to fit :-) 
>>
>> Tested against 9.3 thru 10.
>>
>> Joe
>>
>
> --
> -- Christophe Pettus
>   xof@thebuild.com
>

--
-- Christophe Pettus
   xof@thebuild.com



Re: BC date getting misinterpreted?

От
Joe Abbate
Дата:
On 26/03/18 19:15, Christophe Pettus wrote:
> In both 2.7 and 3.6, datetime.MINYEAR is 1, so I'm a bit surprised this ever worked.

OK, now I see what caused my problem.  The date column was added to the 
query, so that in certain instances it could be used in the ORDER BY 
(there are more details as to why but I won't bore you with them).

No date arithmetic on those dates (yet), so to_char() and extract() are 
fine for the other uses.

Thanks.

Joe