diff options
author | 2020-09-23 12:43:45 -0600 | |
---|---|---|
committer | 2020-09-23 14:43:45 -0400 | |
commit | 2e4dd336e5b50fd30947fdecb605ddcd71f7f6f5 (patch) | |
tree | 7b8e1b98c94d77ffcdcfc61645c6b40f5ebd44ab /Include/datetime.h | |
parent | bpo-33822: Update IDLE section of What's New 3.8 (GH-22383) (diff) | |
download | cpython-2e4dd336e5b50fd30947fdecb605ddcd71f7f6f5.tar.gz cpython-2e4dd336e5b50fd30947fdecb605ddcd71f7f6f5.tar.bz2 cpython-2e4dd336e5b50fd30947fdecb605ddcd71f7f6f5.zip |
bpo-30155: Add macros to get tzinfo from datetime instances (GH-21633)
Add PyDateTime_DATE_GET_TZINFO() and PyDateTime_TIME_GET_TZINFO()
macros.
Diffstat (limited to 'Include/datetime.h')
-rw-r--r-- | Include/datetime.h | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/Include/datetime.h b/Include/datetime.h index 5d9f2558f92..bb565201a16 100644 --- a/Include/datetime.h +++ b/Include/datetime.h @@ -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) |