New submission from Alexander Belopolsky <belopol...@users.sourceforge.net>:

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)

----------
assignee: belopolsky
components: Extension Modules, Library (Lib)
files: datetime-localtime-proto.diff
keywords: patch
messages: 113067
nosy: belopolsky
priority: normal
severity: normal
status: open
title: Add aware local time support to datetime module
type: feature request
versions: Python 3.2
Added file: http://bugs.python.org/file18410/datetime-localtime-proto.diff

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue9527>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to