Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pybind11_abseil
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
pybind11_abseil
Commits
d2d579c2
Commit
d2d579c2
authored
Jan 24, 2024
by
pybind11_abseil authors
Committed by
Copybara-Service
Jan 24, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix deprecation warnings for DATETIME by replacing Breakdown with CivilInfo.
PiperOrigin-RevId: 601195303
parent
52f27398
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
22 deletions
+30
-22
pybind11_abseil/absl_casters.h
+30
-22
No files found.
pybind11_abseil/absl_casters.h
View file @
d2d579c2
...
...
@@ -130,11 +130,16 @@ inline int64_t GetTimestampMicrosFromDateTimeObj(PyObject* dt_obj) {
static_cast
<
int64_t
>
(
dt_microsecond
);
}
// The latest and earliest dates Python's datetime module can represent.
constexpr
absl
::
Time
::
Breakdown
kDatetimeInfiniteFuture
=
{
9999
,
12
,
31
,
23
,
59
,
59
,
absl
::
Microseconds
(
999999
)};
constexpr
absl
::
Time
::
Breakdown
kDatetimeInfinitePast
=
{
1
,
1
,
1
,
0
,
0
,
0
,
absl
::
ZeroDuration
()};
constexpr
absl
::
TimeZone
::
CivilInfo
kDatetimeInfiniteFuture
{
absl
::
CivilSecond
(
9999
,
12
,
31
,
23
,
59
,
59
),
absl
::
Microseconds
(
999999
)
};
constexpr
absl
::
TimeZone
::
CivilInfo
kDatetimeInfinitePast
{
absl
::
CivilSecond
(
1
,
1
,
1
,
0
,
0
,
0
),
absl
::
ZeroDuration
()
};
// NOTE: Python datetime tzinfo is deliberately ignored.
// Rationale:
...
...
@@ -145,13 +150,10 @@ constexpr absl::Time::Breakdown kDatetimeInfinitePast = {
// conversions here.
// * tzinfo for datetime.datetime.min,max is rather meaningless in general,
// but especially so when those are used as placeholders for infinity.
inline
bool
is_special_datetime
(
const
absl
::
Time
::
Breakdown
&
bd_py
,
const
absl
::
Time
::
Breakdown
&
bd_special
)
{
return
(
bd_py
.
year
==
bd_special
.
year
&&
bd_py
.
month
==
bd_special
.
month
&&
bd_py
.
day
==
bd_special
.
day
&&
bd_py
.
hour
==
bd_special
.
hour
&&
bd_py
.
minute
==
bd_special
.
minute
&&
bd_py
.
second
==
bd_special
.
second
&&
bd_py
.
subsecond
==
bd_special
.
subsecond
);
inline
bool
is_special_datetime
(
const
absl
::
TimeZone
::
CivilInfo
&
civil_cmp
,
const
absl
::
TimeZone
::
CivilInfo
&
civil_special
)
{
return
civil_cmp
.
cs
==
civil_special
.
cs
&&
civil_cmp
.
subsecond
==
civil_special
.
subsecond
;
}
}
// namespace internal
...
...
@@ -232,20 +234,23 @@ struct type_caster<absl::Time> {
// As early as possible to avoid mid-process surprises.
internal
::
EnsurePyDateTime_IMPORT
();
if
(
PyDateTime_Check
(
src
.
ptr
()))
{
absl
::
Time
::
Breakdown
bd_py
=
{
absl
::
TimeZone
::
CivilInfo
civil
=
{
absl
::
CivilSecond
(
PyDateTime_GET_YEAR
(
src
.
ptr
()),
PyDateTime_GET_MONTH
(
src
.
ptr
()),
PyDateTime_GET_DAY
(
src
.
ptr
()),
PyDateTime_DATE_GET_HOUR
(
src
.
ptr
()),
PyDateTime_DATE_GET_MINUTE
(
src
.
ptr
()),
PyDateTime_DATE_GET_SECOND
(
src
.
ptr
()),
absl
::
Microseconds
(
PyDateTime_DATE_GET_MICROSECOND
(
src
.
ptr
()))};
if
(
internal
::
is_special_datetime
(
bd_py
,
PyDateTime_DATE_GET_SECOND
(
src
.
ptr
())),
absl
::
Microseconds
(
PyDateTime_DATE_GET_MICROSECOND
(
src
.
ptr
()))
};
if
(
internal
::
is_special_datetime
(
civil
,
internal
::
kDatetimeInfiniteFuture
))
{
value
=
absl
::
InfiniteFuture
();
return
true
;
}
if
(
internal
::
is_special_datetime
(
bd_py
,
if
(
internal
::
is_special_datetime
(
civil
,
internal
::
kDatetimeInfinitePast
))
{
value
=
absl
::
InfinitePast
();
return
true
;
...
...
@@ -270,9 +275,11 @@ struct type_caster<absl::Time> {
}
}
if
(
PyDate_Check
(
src
.
ptr
()))
{
value
=
absl
::
FromDateTime
(
PyDateTime_GET_YEAR
(
src
.
ptr
()),
PyDateTime_GET_MONTH
(
src
.
ptr
()),
PyDateTime_GET_DAY
(
src
.
ptr
()),
0
,
0
,
0
,
absl
::
LocalTimeZone
());
value
=
absl
::
FromCivil
(
absl
::
CivilSecond
(
PyDateTime_GET_YEAR
(
src
.
ptr
()),
PyDateTime_GET_MONTH
(
src
.
ptr
()),
PyDateTime_GET_DAY
(
src
.
ptr
()),
0
,
0
,
0
),
absl
::
LocalTimeZone
());
return
true
;
}
return
false
;
...
...
@@ -294,10 +301,11 @@ struct type_caster<absl::Time> {
1
,
1
,
1
,
0
,
0
,
0
,
0
,
PyDateTimeAPI
->
TimeZone_UTC
,
PyDateTimeAPI
->
DateTimeType
);
}
absl
::
Time
::
Breakdown
t
=
src
.
In
(
absl
::
UTCTimeZone
()
);
absl
::
Time
Zone
::
CivilInfo
info
=
absl
::
UTCTimeZone
().
At
(
src
);
return
PyDateTimeAPI
->
DateTime_FromDateAndTime
(
t
.
year
,
t
.
month
,
t
.
day
,
t
.
hour
,
t
.
minute
,
t
.
second
,
static_cast
<
int
>
(
t
.
subsecond
/
absl
::
Microseconds
(
1
)),
info
.
cs
.
year
(),
info
.
cs
.
month
(),
info
.
cs
.
day
(),
info
.
cs
.
hour
(),
info
.
cs
.
minute
(),
info
.
cs
.
second
(),
static_cast
<
int
>
(
info
.
subsecond
/
absl
::
Microseconds
(
1
)),
PyDateTimeAPI
->
TimeZone_UTC
,
PyDateTimeAPI
->
DateTimeType
);
}
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment