source: fulltextsearchplugin/trunk/fulltextsearchplugin/dates.py

Last change on this file was 11663, checked in by Alex Willmer, 11 years ago

FullTextSearchPlugin: Initial commit

File size: 693 bytes
Line 
1from datetime import datetime
2from trac.util import datefmt
3
4def normalise_datetime(date):
5    """Return a timezone aware datetime.datetime object
6   
7    Sunburnt returns mxDateTime objects in preference to datetime.datetime.
8    Sunburnt also doesn't set the timezone info. Trac expects timezone
9    aware datetime.datetime objects, so sunburnt dates must be normalised.
10    """
11    if not date or getattr(date, 'tzinfo', None):
12        return date
13    try:
14        # datetime.datetime
15        return date.replace(tzinfo=datefmt.localtz)
16    except AttributeError:
17        # mxDateTime
18        date = datetime.fromtimestamp(date.ticks())
19        return date.replace(tzinfo=datefmt.localtz)
Note: See TracBrowser for help on using the repository browser.