mirror of
https://github.com/python/cpython.git
synced 2025-11-25 04:34:37 +00:00
bpo-30155: Add macros to get tzinfo from datetime instances (GH-21633)
Add PyDateTime_DATE_GET_TZINFO() and PyDateTime_TIME_GET_TZINFO() macros.
This commit is contained in:
parent
9c4eac7f02
commit
2e4dd336e5
8 changed files with 46 additions and 17 deletions
|
|
@ -115,6 +115,10 @@ typedef struct
|
|||
|
||||
|
||||
/* Apply for date and datetime instances. */
|
||||
|
||||
// o is a pointer to a time or a datetime object.
|
||||
#define _PyDateTime_HAS_TZINFO(o) (((_PyDateTime_BaseTZInfo *)(o))->hastzinfo)
|
||||
|
||||
#define PyDateTime_GET_YEAR(o) ((((PyDateTime_Date*)o)->data[0] << 8) | \
|
||||
((PyDateTime_Date*)o)->data[1])
|
||||
#define PyDateTime_GET_MONTH(o) (((PyDateTime_Date*)o)->data[2])
|
||||
|
|
@ -128,6 +132,8 @@ typedef struct
|
|||
(((PyDateTime_DateTime*)o)->data[8] << 8) | \
|
||||
((PyDateTime_DateTime*)o)->data[9])
|
||||
#define PyDateTime_DATE_GET_FOLD(o) (((PyDateTime_DateTime*)o)->fold)
|
||||
#define PyDateTime_DATE_GET_TZINFO(o) (_PyDateTime_HAS_TZINFO(o) ? \
|
||||
((PyDateTime_DateTime *)(o))->tzinfo : Py_None)
|
||||
|
||||
/* Apply for time instances. */
|
||||
#define PyDateTime_TIME_GET_HOUR(o) (((PyDateTime_Time*)o)->data[0])
|
||||
|
|
@ -138,6 +144,8 @@ typedef struct
|
|||
(((PyDateTime_Time*)o)->data[4] << 8) | \
|
||||
((PyDateTime_Time*)o)->data[5])
|
||||
#define PyDateTime_TIME_GET_FOLD(o) (((PyDateTime_Time*)o)->fold)
|
||||
#define PyDateTime_TIME_GET_TZINFO(o) (_PyDateTime_HAS_TZINFO(o) ? \
|
||||
((PyDateTime_Time *)(o))->tzinfo : Py_None)
|
||||
|
||||
/* Apply for time delta instances */
|
||||
#define PyDateTime_DELTA_GET_DAYS(o) (((PyDateTime_Delta*)o)->days)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue