Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 183dabc

Browse files
committed
SF patch 986010: add missing doc for datetime C API, from
Anthony Tuininga. This is a derived patch, taking the opportunity to add some organization to the now-large pile of datetime-related macros, and to factor out tedious repeated text. Also improved some clumsy wording in NEWS.
1 parent dfa5d95 commit 183dabc

2 files changed

Lines changed: 97 additions & 24 deletions

File tree

Doc/api/concrete.tex

Lines changed: 85 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2656,73 +2656,77 @@ \subsection{DateTime Objects \label{datetime-objects}}
26562656
not include by \file{Python.h}), and macro \cfunction{PyDateTime_IMPORT()}
26572657
must be invoked. The macro arranges to put a pointer to a C structure
26582658
in a static variable \code{PyDateTimeAPI}, which is used by the following
2659-
macros:
2659+
macros.
26602660

2661-
\begin{cfuncdesc}{int}{PyDate_Check}{ob}
2661+
Type-check macros:
2662+
2663+
\begin{cfuncdesc}{int}{PyDate_Check}{PyObject *ob}
26622664
Return true if \var{ob} is of type \cdata{PyDateTime_DateType} or
26632665
a subtype of \cdata{PyDateTime_DateType}. \var{ob} must not be
26642666
\NULL{}.
26652667
\versionadded{2.4}
26662668
\end{cfuncdesc}
26672669

2668-
\begin{cfuncdesc}{int}{PyDate_CheckExact}{ob}
2670+
\begin{cfuncdesc}{int}{PyDate_CheckExact}{PyObject *ob}
26692671
Return true if \var{ob} is of type \cdata{PyDateTime_DateType}.
26702672
\var{ob} must not be \NULL{}.
26712673
\versionadded{2.4}
26722674
\end{cfuncdesc}
26732675

2674-
\begin{cfuncdesc}{int}{PyDateTime_Check}{ob}
2676+
\begin{cfuncdesc}{int}{PyDateTime_Check}{PyObject *ob}
26752677
Return true if \var{ob} is of type \cdata{PyDateTime_DateTimeType} or
26762678
a subtype of \cdata{PyDateTime_DateTimeType}. \var{ob} must not be
26772679
\NULL{}.
26782680
\versionadded{2.4}
26792681
\end{cfuncdesc}
26802682

2681-
\begin{cfuncdesc}{int}{PyDateTime_CheckExact}{ob}
2683+
\begin{cfuncdesc}{int}{PyDateTime_CheckExact}{PyObject *ob}
26822684
Return true if \var{ob} is of type \cdata{PyDateTime_DateTimeType}.
26832685
\var{ob} must not be \NULL{}.
26842686
\versionadded{2.4}
26852687
\end{cfuncdesc}
26862688

2687-
\begin{cfuncdesc}{int}{PyTime_Check}{ob}
2689+
\begin{cfuncdesc}{int}{PyTime_Check}{PyObject *ob}
26882690
Return true if \var{ob} is of type \cdata{PyDateTime_TimeType} or
26892691
a subtype of \cdata{PyDateTime_TimeType}. \var{ob} must not be
26902692
\NULL{}.
26912693
\versionadded{2.4}
26922694
\end{cfuncdesc}
26932695

2694-
\begin{cfuncdesc}{int}{PyTime_CheckExact}{ob}
2696+
\begin{cfuncdesc}{int}{PyTime_CheckExact}{PyObject *ob}
26952697
Return true if \var{ob} is of type \cdata{PyDateTime_TimeType}.
26962698
\var{ob} must not be \NULL{}.
26972699
\versionadded{2.4}
26982700
\end{cfuncdesc}
26992701

2700-
\begin{cfuncdesc}{int}{PyDelta_Check}{ob}
2702+
\begin{cfuncdesc}{int}{PyDelta_Check}{PyObject *ob}
27012703
Return true if \var{ob} is of type \cdata{PyDateTime_DeltaType} or
27022704
a subtype of \cdata{PyDateTime_DeltaType}. \var{ob} must not be
27032705
\NULL{}.
27042706
\versionadded{2.4}
27052707
\end{cfuncdesc}
27062708

2707-
\begin{cfuncdesc}{int}{PyDelta_CheckExact}{ob}
2709+
\begin{cfuncdesc}{int}{PyDelta_CheckExact}{PyObject *ob}
27082710
Return true if \var{ob} is of type \cdata{PyDateTime_DeltaType}.
27092711
\var{ob} must not be \NULL{}.
27102712
\versionadded{2.4}
27112713
\end{cfuncdesc}
27122714

2713-
\begin{cfuncdesc}{int}{PyTZInfo_Check}{ob}
2715+
\begin{cfuncdesc}{int}{PyTZInfo_Check}{PyObject *ob}
27142716
Return true if \var{ob} is of type \cdata{PyDateTime_TZInfoType} or
27152717
a subtype of \cdata{PyDateTime_TZInfoType}. \var{ob} must not be
27162718
\NULL{}.
27172719
\versionadded{2.4}
27182720
\end{cfuncdesc}
27192721

2720-
\begin{cfuncdesc}{int}{PyTZInfo_CheckExact}{ob}
2722+
\begin{cfuncdesc}{int}{PyTZInfo_CheckExact}{PyObject *ob}
27212723
Return true if \var{ob} is of type \cdata{PyDateTime_TZInfoType}.
27222724
\var{ob} must not be \NULL{}.
27232725
\versionadded{2.4}
27242726
\end{cfuncdesc}
27252727

2728+
Macros to create objects:
2729+
27262730
\begin{cfuncdesc}{PyObject*}{PyDate_FromDate}{int year, int month, int day}
27272731
Return a \code{datetime.date} object with the specified year, month
27282732
and day.
@@ -2752,18 +2756,84 @@ \subsection{DateTime Objects \label{datetime-objects}}
27522756
\versionadded{2.4}
27532757
\end{cfuncdesc}
27542758

2759+
Macros to extract fields from date objects. The argument must an
2760+
instance of \cdata{PyDateTime_Date}, including subclasses (such as
2761+
\cdata{PyDateTime_DateTime}). The argument must not be \NULL{}, and
2762+
the type is not checked:
2763+
2764+
\begin{cfuncdesc}{int}{PyDateTime_GET_YEAR}{PyDateTime_Date *o}
2765+
Return the year, as a positive int.
2766+
\versionadded{2.4}
2767+
\end{cfuncdesc}
2768+
2769+
\begin{cfuncdesc}{int}{PyDateTime_GET_MONTH}{PyDateTime_Date *o}
2770+
Return the month, as an int from 1 through 12.
2771+
\versionadded{2.4}
2772+
\end{cfuncdesc}
2773+
2774+
\begin{cfuncdesc}{int}{PyDateTime_GET_DAY}{PyDateTime_Date *o}
2775+
Return the day, as an int from 1 through 31.
2776+
\versionadded{2.4}
2777+
\end{cfuncdesc}
2778+
2779+
Macros to extract fields from datetime objects. The argument must an
2780+
instance of \cdata{PyDateTime_DateTime}, including subclasses.
2781+
The argument must not be \NULL{}, and the type is not checked:
2782+
2783+
\begin{cfuncdesc}{int}{PyDateTime_DATE_GET_HOUR}{PyDateTime_DateTime *o}
2784+
Return the hour, an an int from 0 though 23.
2785+
\versionadded{2.4}
2786+
\end{cfuncdesc}
2787+
2788+
\begin{cfuncdesc}{int}{PyDateTime_DATE_GET_MINUTE}{PyDateTime_DateTime *o}
2789+
Return the minute, as an int from 0 through 59.
2790+
\versionadded{2.4}
2791+
\end{cfuncdesc}
2792+
2793+
\begin{cfuncdesc}{int}{PyDateTime_DATE_GET_SECOND}{PyDateTime_DateTime *o}
2794+
Return the second, as an int from 0 through 59.
2795+
\versionadded{2.4}
2796+
\end{cfuncdesc}
2797+
2798+
\begin{cfuncdesc}{int}{PyDateTime_DATE_GET_MICROSECOND}{PyDateTime_DateTime *o}
2799+
Return the microsecond, as an int from 0 through 999999.
2800+
\versionadded{2.4}
2801+
\end{cfuncdesc}
2802+
2803+
Macros to extract fields from time objects. The argument must an
2804+
instance of \cdata{PyDateTime_Time}, including subclasses.
2805+
The argument must not be \NULL{}, and the type is not checked:
2806+
2807+
\begin{cfuncdesc}{int}{PyDateTime_TIME_GET_HOUR}{PyDateTime_Time *o}
2808+
Return the hour, as an int from 0 though 23.
2809+
\versionadded{2.4}
2810+
\end{cfuncdesc}
2811+
2812+
\begin{cfuncdesc}{int}{PyDateTime_TIME_GET_MINUTE}{PyDateTime_Time *o}
2813+
Return the minute, as an int from 0 through 59.
2814+
\versionadded{2.4}
2815+
\end{cfuncdesc}
2816+
2817+
\begin{cfuncdesc}{int}{PyDateTime_TIME_GET_SECOND}{PyDateTime_Time *o}
2818+
Return the second, as an int from 0 through 59.
2819+
\versionadded{2.4}
2820+
\end{cfuncdesc}
2821+
2822+
\begin{cfuncdesc}{int}{PyDateTime_TIME_GET_MICROSECOND}{PyDateTime_Time *o}
2823+
Return the microsecond, as an int from 0 through 999999.
2824+
\versionadded{2.4}
2825+
\end{cfuncdesc}
2826+
2827+
Macros for the convenience of modules implementing the DB API:
2828+
27552829
\begin{cfuncdesc}{PyObject*}{PyDateTime_FromTimestamp}{PyObject *args}
27562830
Create and return a new \code{datetime.datetime} object given an argument
27572831
tuple suitable for passing to \code{datetime.datetime.fromtimestamp()}.
2758-
This macro is included for the convenience of modules implementing the
2759-
DB API.
27602832
\versionadded{2.4}
27612833
\end{cfuncdesc}
27622834

27632835
\begin{cfuncdesc}{PyObject*}{PyDate_FromTimestamp}{PyObject *args}
27642836
Create and return a new \code{datetime.date} object given an argument
27652837
tuple suitable for passing to \code{datetime.date.fromtimestamp()}.
2766-
This macro is included for the convenience of modules implementing the
2767-
DB API.
27682838
\versionadded{2.4}
27692839
\end{cfuncdesc}

Misc/NEWS

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ Core and builtins
1313
-----------------
1414

1515
- Patch #550732: Add PyArg_VaParseTupleAndKeywords(). Analogous to
16-
PyArg_VaParse(). Both are now documented. Thanks Greg Chapman.
16+
PyArg_VaParse(). Both are now documented. Thanks Greg Chapman.
1717

1818
- Allow string and unicode return types from .encode()/.decode()
19-
methods on string and unicode objects. Added unicode.decode()
19+
methods on string and unicode objects. Added unicode.decode()
2020
which was missing for no apparent reason.
2121

22-
- An attempt to fix the mess that is Python's behaviour with
22+
- An attempt to fix the mess that is Python's behaviour with
2323
signal handlers and threads, complicated by readline's behaviour.
2424
It's quite possible that there are still bugs here.
2525

@@ -29,9 +29,9 @@ Extension modules
2929
Library
3030
-------
3131

32-
- Bug #979794: difflib.get_grouped_opcodes() now handles the case of when it is
33-
comparing two empty lists. Was affecting both context_diff() and
34-
unified_diff(). Was also a duplicate of bug #980117.
32+
- Bugs #979794 and #980117: difflib.get_grouped_opcodes() now handles the
33+
case of comparing two empty lists. This affected both context_diff() and
34+
unified_diff(),
3535

3636
- Bug #980938: smtplib now prints debug output to sys.stderr.
3737

@@ -47,7 +47,7 @@ Library
4747
for file sizes (compressed and uncompressed) was being stored as signed
4848
instead of unsigned.
4949

50-
- decimal.py now only uses signals in the spec. The other conditions are
50+
- decimal.py now only uses signals in the IBM spec. The other conditions are
5151
no longer part of the public API.
5252

5353
- codecs module now has two new generic APIs: encode() and decode()
@@ -57,7 +57,7 @@ Library
5757
- asyncore's dispatcher.set_reuse_addr() now works correctly on Windows.
5858
SF patch 982681.
5959

60-
- Non-blocking SSL sockets work again; they were broken in Python 2.3.
60+
- Non-blocking SSL sockets work again; they were broken in Python 2.3.
6161
SF patch 945642.
6262

6363
Tools/Demos
@@ -69,6 +69,9 @@ Build
6969
C API
7070
-----
7171

72+
- A large pile of datetime field-extraction macros is now documented,
73+
thanks to Anthony Tuininga (patch #986010).
74+
7275
New platforms
7376
-------------
7477

@@ -438,7 +441,7 @@ Extension modules
438441

439442
Library
440443
-------
441-
444+
442445
- Bug #981530: Fix UnboundLocalError in shutil.rmtree(). This affects
443446
the documented behavior: the function passed to the onerror()
444447
handler can now also be os.listdir.

0 commit comments

Comments
 (0)