Author belopolsky
Recipients belopolsky
Date 2010-08-06.03:48:16
SpamBayes Score 1.04265e-10
Marked as misclassified No
Message-id <1281066500.35.0.441616276688.issue9527@psf.upfronthosting.co.za>
In-reply-to
Content
See python-dev post for motivation.

http://mail.python.org/pipermail/python-dev/2010-August/102842.html


I am attaching a patch implementing the proposed method in datetime.py.  I will also paste the code below.  Note that this is only prototype.  Real implementation will use tm_zone and tm_gmtoff components of tm structure on platforms that supply them.

    @classmethod
    def localtime(cls, t=None, isdst=-1):
        """Return local time as an aware datetime object.                                                                                                          
                                                                                                                                                                   
        If called without arguments, return current time.  Otherwise                                                                                               
        *t* is converted to local time zone according to the system                                                                                                
        time zone database.  If *t* is naive (i.e. t.tzinfo is None),                                                                                              
        it is assumed to be in local time.  In this case, a positive or                                                                                            
        zero value for *isdst* causes localtime to presume initially                                                                                               
        that summer time (for example, Daylight Saving Time) is or is                                                                                              
        not (respectively) in effect for the specified time.  A                                                                                                    
        negative value for *isdst* causes the localtime() function to                                                                                              
        attempt to divine whether summer time is in effect for the                                                                                                 
        specified time.                                                                                                                                            
        """
        if t is None:
            t = _time.time()
        else:
            if t.tzinfo is None:
                tm = t.timetuple()[:-1] + (isdst,)
                t = _time.mktime(tm)
            else:
                delta = t - datetime(1970, 1, 1, tzinfo=timezone.utc)
                t = delta.total_seconds()
        tm = _time.localtime(t)
        if _time.daylight:
            if tm.tm_isdst:
                offset = _time.altzone
                tzname = _time.tzname[1]
            else:
                offset = _time.timezone
                tzname = _time.tzname[0]
        tz = timezone(timedelta(seconds=-offset), tzname)
        return cls.fromtimestamp(t, tz)
History
Date User Action Args
2010-08-06 03:48:20belopolskysetrecipients: + belopolsky
2010-08-06 03:48:20belopolskysetmessageid: <1281066500.35.0.441616276688.issue9527@psf.upfronthosting.co.za>
2010-08-06 03:48:18belopolskylinkissue9527 messages
2010-08-06 03:48:17belopolskycreate