utils.py
author Tero Marttila <terom@fixme.fi>
Mon, 09 Feb 2009 00:24:13 +0200
changeset 50 f13cf27a360b
child 51 07ca28f3a9f2
permissions -rw-r--r--
implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
"""
    Miscellaneous things
"""

import datetime

class Date (object) :
    """
        Handle dates in URLs as datetime objects (with indeterminate time info) in some timezone
    """

    def __init__ (self, tz, date_fmt="%Y-%m-%d") :
        """
            Format/parse dates in the given timezone using the given format
        """
        
        self.tz = tz
        self.date_fmt = date_fmt
    
    __name__ = "date"

    def __call__ (self, date_str) :
        """
            Parse the given date string
        """
        
        return datetime.datetime.strptime(date_str, self.date_fmt).replace(tzinfo=self.tz)