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

EntrustName
  • 421
  • 6
  • 19

1 Answers1

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");
user2357112
  • 260,549
  • 28
  • 431
  • 505
  • I already got it by doing `auto o = ((PyDateTime_DateTime*)src.ptr())->tzinfo;` but then I don't know what to do – EntrustName Oct 14 '18 at 12:53
  • @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. – user2357112 Oct 14 '18 at 18:04