1

My fetched rows from rethinkdb cluster include date objects with timezones. Here's an example of one:

ipython> dt
datetime.datetime(2015, 12, 18, 0, 22, 4, 644000, tzinfo=<rethinkdb.ast.RqlTzinfo object at 0x7f072c5d6250>)

I'm trying to stringify them into a certain format:

dt.strftime("%d-%m-%Y %H:%M:%S (%Z)")

and it leads to

*** TypeError: tzinfo.tzname() must return None or a string, not 'unicode'

How can I overcome this?

Kludge
  • 2,305
  • 4
  • 18
  • 35

1 Answers1

1

If you look at the source code for RqlTzinfo.tzname(), you can see that it simply returns its offsetstr attribute. Since that attribute is never modified or converted anywhere in that class and the class's behavior does not depend on it being either a str or unicode, the following should suffice:

dt.tzinfo.offsetstr = str(dt.tzinfo.offsetstr)
Martin Valgur
  • 4,301
  • 23
  • 35
  • WHY didn't I take a look in the source code in the first place..? The name of the attribute is offsetstr by the way, or at least in the version I'm using (v1.15 - old), but anyways, thanks, I feel so stupid now :P – Kludge Dec 20 '15 at 17:38