Changeset 13478


Ignore:
Timestamp:
18 Nov 2015, 15:55:26 (9 years ago)
Author:
uli
Message:

More concise fix of the TZ problem.

  • There is no need for try-except. Instead we can properly query the circumstances that lead to TypeError?.
  • There is no need to get the utils tzinfo. In case we get a timezone-aware datetime, there is already a timezone available. We should use this timezone then, to ease calculations. Beside this we must take into account the possibility, that local timezone is None.

The new implementaion addresses these problems.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/interswitch/browser.py

    r13472 r13478  
    169169            return _("Payment ticket can't be re-sent to CollegePAY.")
    170170        tz = getUtility(IKofaUtils).tzinfo
    171         try:
    172             time_delta = datetime.utcnow() - self.context.creation_date
    173         except TypeError:
    174             # when importing datetimes we are storing offset-aware datetimes
    175             # which causes a TypeError
    176             now = datetime.now(tz)
    177             time_delta = datetime.now(tz) - self.context.creation_date
     171        now = datetime.utcnow()
     172        if self.context.creation_date.tzinfo is not None:
     173            # That's bad. Please store timezone-naive datetimes only!
     174            now = self.context.creation_date.tzinfo.localize(now)
     175        time_delta = now - self.context.creation_date
    178176        if time_delta.days > 7:
    179177            return _("This payment ticket is too old. Please create a new ticket.")
Note: See TracChangeset for help on using the changeset viewer.