mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-02-16 17:10:32 +03:00
Dropped register_tstz_w_secs() implementation.
The function is no-op now that the default type caster can deal with seconds in the tz offset.
This commit is contained in:
parent
305d86f38a
commit
4a78e4068b
|
@ -3,6 +3,8 @@
|
|||
* psycopg/typecast_datetime.c: Round seconds in historical timezones to
|
||||
the nearest minute.
|
||||
|
||||
* lib/extras.py: register_tstz_w_secs() is now no-op.
|
||||
|
||||
2010-05-17 Federico Di Gregorio <fog@initd.org>
|
||||
|
||||
* Release 2.2.1.
|
||||
|
|
|
@ -155,6 +155,9 @@ Fractional time zones
|
|||
|
||||
.. versionadded:: 2.0.9
|
||||
|
||||
.. versionchanged:: 2.2.0
|
||||
function is no-op: see :ref:`tz-handling`.
|
||||
|
||||
.. index::
|
||||
pair: Example; Coroutine;
|
||||
|
||||
|
|
|
@ -435,53 +435,15 @@ def register_inet(oid=None, conn_or_curs=None):
|
|||
return _ext.INET
|
||||
|
||||
|
||||
# safe management of times with a non-standard time zone
|
||||
|
||||
def _convert_tstz_w_secs(s, cursor):
|
||||
try:
|
||||
return DATETIME(s, cursor)
|
||||
|
||||
except (DataError,), exc:
|
||||
if exc.message != "unable to parse time":
|
||||
raise
|
||||
|
||||
if regex.match('(\+|-)\d\d:\d\d:\d\d', s[-9:]) is None:
|
||||
raise
|
||||
|
||||
# parsing doesn't succeed even if seconds are ":00" so truncate in
|
||||
# any case
|
||||
return DATETIME(s[:-3], cursor)
|
||||
|
||||
def register_tstz_w_secs(oids=None, conn_or_curs=None):
|
||||
"""Register alternate type caster for :sql:`TIMESTAMP WITH TIME ZONE`.
|
||||
"""The function used to register an alternate type caster for
|
||||
:sql:`TIMESTAMP WITH TIME ZONE` to deal with historical time zones with
|
||||
seconds in the UTC offset.
|
||||
|
||||
The Python datetime module cannot handle time zones with
|
||||
seconds in the UTC offset. There are, however, historical
|
||||
"time zones" which contain such offsets, eg. "Asia/Calcutta".
|
||||
In many cases those offsets represent true local time.
|
||||
|
||||
If you encounter "unable to parse time" on a perfectly valid
|
||||
timestamp you likely want to try this type caster. It truncates
|
||||
the seconds from the time zone data and retries casting
|
||||
the timestamp. Note that this will generate timestamps
|
||||
which are **inaccurate** by the number of seconds truncated
|
||||
(unless the seconds were 00).
|
||||
|
||||
:param oids:
|
||||
which OIDs to use this type caster for,
|
||||
defaults to :sql:`TIMESTAMP WITH TIME ZONE`
|
||||
:param conn_or_curs:
|
||||
a cursor or connection if you want to attach
|
||||
this type caster to that only, defaults to
|
||||
``None`` meaning all connections and cursors
|
||||
These are now correctly handled by the default type caster, so currently
|
||||
the function doesn't do anything.
|
||||
"""
|
||||
if oids is None:
|
||||
oids = (1184,) # hardcoded from PostgreSQL headers
|
||||
|
||||
_ext.TSTZ_W_SECS = _ext.new_type(oids, 'TSTZ_W_SECS', _convert_tstz_w_secs)
|
||||
_ext.register_type(_ext.TSTZ_W_SECS, conn_or_curs)
|
||||
|
||||
return _ext.TSTZ_W_SECS
|
||||
pass
|
||||
|
||||
|
||||
import select
|
||||
|
|
Loading…
Reference in New Issue
Block a user