root/imapclient/fixed_offset.py

Revision 204:ea3eff2a866a, 1.0 KB (checked in by Menno Smits <menno@…>, 12 months ago)

Updated copyright dates to 2011 and fixed a number of incorrect and missing file headers.

Line 
1# Copyright (c) 2011, Menno Smits
2# Released subject to the New BSD License
3# Please see http://en.wikipedia.org/wiki/BSD_licenses
4
5import time
6from datetime import tzinfo, timedelta
7
8ZERO = timedelta(0)
9
10class FixedOffset(tzinfo):
11    """
12    This class describes fixed timezone offsets in hours and minutes
13    east from UTC
14    """
15
16    def __init__(self, minutes):
17        self.__offset = timedelta(minutes=minutes)
18
19        sign = '+'
20        if minutes < 0:
21            sign = '-'
22        hours, remaining_mins = divmod(abs(minutes), 60)
23        self.__name = '%s%02d%02d' % (sign, hours, remaining_mins)
24
25    def utcoffset(self, _):
26        return self.__offset
27
28    def tzname(self, _):
29        return self.__name
30
31    def dst(self, _):
32        return ZERO
33
34    @classmethod
35    def for_system(klass):
36        """Return a FixedOffset instance for the current working timezone and
37        DST conditions.
38        """
39        if time.daylight:
40            offset = time.altzone
41        else:
42            offset = time.timezone
43        return klass(-offset // 60)
Note: See TracBrowser for help on using the browser.