3

I don't find anything to find the timezone from a PyDateTime_DateTime. I want to get either the offset or the timezone name if possible.

Do you know how to do that ?

Thx

2

1 Answer 1

1

There just isn't any C API accessor for a datetime's time zone. Your best option is to go through ordinary attribute access:

PyObject *tz_or_none = PyObject_GetAttrString(dt, "tzinfo");
Sign up to request clarification or add additional context in comments.

2 Comments

I already got it by doing auto o = ((PyDateTime_DateTime*)src.ptr())->tzinfo; but then I don't know what to do
@EntrustName: If you're willing to pull out the undocumented implementation details of implementation details, sure, you can access struct members directly (and probably segfault in short order if it's a naive timezone). tzinfo objects don't have C API accessors for any of their data either, though, so you'll have to keep making assumptions and pulling out undocumented struct members manually if you're dead-set on avoiding normal attribute access and method calls.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.