Python datetime.tzinfo() Examples

The following are 30 code examples for showing how to use datetime.tzinfo(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module datetime , or try the search function .

Example 1
Project: razzy-spinner   Author: rafasashi   File: api.py    License: GNU General Public License v3.0 6 votes vote down vote up
def check_date_limit(self, data, verbose=False):
        """
        Validate date limits.
        """
        if self.upper_date_limit or self.lower_date_limit:
            date_fmt = '%a %b %d %H:%M:%S +0000 %Y'
            tweet_date = \
                datetime.strptime(data['created_at'],
                                  date_fmt).replace(tzinfo=UTC)
            if (self.upper_date_limit and tweet_date > self.upper_date_limit) or \
               (self.lower_date_limit and tweet_date < self.lower_date_limit):
                if self.upper_date_limit:
                    message = "earlier"
                    date_limit = self.upper_date_limit
                else:
                    message = "later"
                    date_limit = self.lower_date_limit
                if verbose:
                    print("Date limit {0} is {1} than date of current tweet {2}".\
                      format(date_limit, message, tweet_date))
                self.do_stop = True 
Example 2
Project: misp42splunk   Author: remg427   File: base.py    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
def _mock(self, context=None):
        dt = datetime.datetime(
               year=random.randrange(600) + 1900,
               month=random.randrange(12) + 1,
               day=random.randrange(28) + 1,
               hour=random.randrange(24),
               minute=random.randrange(60),
               second=random.randrange(60),
               microsecond=random.randrange(1000000))

        if self.tzd == 'reject' or \
           self.drop_tzinfo or \
           self.tzd == 'allow' and random.randrange(2):
            return dt
        elif self.convert_tz:
            return dt.replace(tzinfo=self.UTC)
        else:
            return dt.replace(tzinfo=self.offset_timezone(hours=random.randrange(-12, 15),
                                                          minutes=random.choice([0, 30, 45]))) 
Example 3
Project: asn1tools   Author: eerimoq   File: compat.py    License: MIT License 6 votes vote down vote up
def strptime(data, fmt):
        if fmt.endswith('%z'):
            date = datetime.strptime(data[:-5], fmt[:-2])

            try:
                sign = {'-': -1, '+': 1}[data[-5]]
                hours = sign * int(data[-4:-2])
                minutes = sign * int(data[-2:])
            except KeyError:
                raise ValueError(
                    "time data '{}' does not match format '{}'.".format(
                        data,
                        fmt))

            date = date.replace(tzinfo=timezone(timedelta(hours=hours,
                                                          minutes=minutes)))
        else:
            date = datetime.strptime(data, fmt)

        return date 
Example 4
Project: plugin.video.emby   Author: MediaBrowser   File: _common.py    License: GNU General Public License v3.0 6 votes vote down vote up
def _fold_status(self, dt_utc, dt_wall):
        """
        Determine the fold status of a "wall" datetime, given a representation
        of the same datetime as a (naive) UTC datetime. This is calculated based
        on the assumption that ``dt.utcoffset() - dt.dst()`` is constant for all
        datetimes, and that this offset is the actual number of hours separating
        ``dt_utc`` and ``dt_wall``.

        :param dt_utc:
            Representation of the datetime as UTC

        :param dt_wall:
            Representation of the datetime as "wall time". This parameter must
            either have a `fold` attribute or have a fold-naive
            :class:`datetime.tzinfo` attached, otherwise the calculation may
            fail.
        """
        if self.is_ambiguous(dt_wall):
            delta_wall = dt_wall - dt_utc
            _fold = int(delta_wall == (dt_utc.utcoffset() - dt_utc.dst()))
        else:
            _fold = 0

        return _fold 
Example 5
Project: plugin.video.emby   Author: MediaBrowser   File: _common.py    License: GNU General Public License v3.0 6 votes vote down vote up
def is_ambiguous(self, dt):
        """
        Whether or not the "wall time" of a given datetime is ambiguous in this
        zone.

        :param dt:
            A :py:class:`datetime.datetime`, naive or time zone aware.


        :return:
            Returns ``True`` if ambiguous, ``False`` otherwise.

        .. versionadded:: 2.6.0
        """
        if not self.hasdst:
            return False

        start, end = self.transitions(dt.year)

        dt = dt.replace(tzinfo=None)
        return (end <= dt < end + self._dst_base_offset) 
Example 6
Project: plugin.video.emby   Author: MediaBrowser   File: _common.py    License: GNU General Public License v3.0 6 votes vote down vote up
def _isdst(self, dt):
        if not self.hasdst:
            return False
        elif dt is None:
            return None

        transitions = self.transitions(dt.year)

        if transitions is None:
            return False

        dt = dt.replace(tzinfo=None)

        isdst = self._naive_isdst(dt, transitions)

        # Handle ambiguous dates
        if not isdst and self.is_ambiguous(dt):
            return not self._fold(dt)
        else:
            return isdst 
Example 7
Project: plugin.video.emby   Author: MediaBrowser   File: test_tz.py    License: GNU General Public License v3.0 6 votes vote down vote up
def testFoldPositiveUTCOffset(self):
        # Test that we can resolve ambiguous times
        tzname = self._get_tzname('Australia/Sydney')

        with self._gettz_context(tzname):
            SYD = self.gettz(tzname)

            t0_u = datetime(2012, 3, 31, 15, 30, tzinfo=tz.tzutc())  # AEST
            t1_u = datetime(2012, 3, 31, 16, 30, tzinfo=tz.tzutc())  # AEDT

            t0_syd0 = t0_u.astimezone(SYD)
            t1_syd1 = t1_u.astimezone(SYD)

            self.assertEqual(t0_syd0.replace(tzinfo=None),
                             datetime(2012, 4, 1, 2, 30))

            self.assertEqual(t1_syd1.replace(tzinfo=None),
                             datetime(2012, 4, 1, 2, 30))

            self.assertEqual(t0_syd0.utcoffset(), timedelta(hours=11))
            self.assertEqual(t1_syd1.utcoffset(), timedelta(hours=10)) 
Example 8
Project: plugin.video.emby   Author: MediaBrowser   File: test_tz.py    License: GNU General Public License v3.0 6 votes vote down vote up
def testGapPositiveUTCOffset(self):
        # Test that we don't have a problem around gaps.
        tzname = self._get_tzname('Australia/Sydney')

        with self._gettz_context(tzname):
            SYD = self.gettz(tzname)

            t0_u = datetime(2012, 10, 6, 15, 30, tzinfo=tz.tzutc())  # AEST
            t1_u = datetime(2012, 10, 6, 16, 30, tzinfo=tz.tzutc())  # AEDT

            t0 = t0_u.astimezone(SYD)
            t1 = t1_u.astimezone(SYD)

            self.assertEqual(t0.replace(tzinfo=None),
                             datetime(2012, 10, 7, 1, 30))

            self.assertEqual(t1.replace(tzinfo=None),
                             datetime(2012, 10, 7, 3, 30))

            self.assertEqual(t0.utcoffset(), timedelta(hours=10))
            self.assertEqual(t1.utcoffset(), timedelta(hours=11)) 
Example 9
Project: plugin.video.emby   Author: MediaBrowser   File: test_tz.py    License: GNU General Public License v3.0 6 votes vote down vote up
def testFoldNegativeUTCOffset(self):
            # Test that we can resolve ambiguous times
            tzname = self._get_tzname('America/Toronto')

            with self._gettz_context(tzname):
                TOR = self.gettz(tzname)

                t0_u = datetime(2011, 11, 6, 5, 30, tzinfo=tz.tzutc())
                t1_u = datetime(2011, 11, 6, 6, 30, tzinfo=tz.tzutc())

                t0_tor = t0_u.astimezone(TOR)
                t1_tor = t1_u.astimezone(TOR)

                self.assertEqual(t0_tor.replace(tzinfo=None),
                                 datetime(2011, 11, 6, 1, 30))

                self.assertEqual(t1_tor.replace(tzinfo=None),
                                 datetime(2011, 11, 6, 1, 30))

                self.assertNotEqual(t0_tor.tzname(), t1_tor.tzname())
                self.assertEqual(t0_tor.utcoffset(), timedelta(hours=-4.0))
                self.assertEqual(t1_tor.utcoffset(), timedelta(hours=-5.0)) 
Example 10
Project: plugin.video.emby   Author: MediaBrowser   File: test_tz.py    License: GNU General Public License v3.0 6 votes vote down vote up
def testFoldLondon(self):
        tzname = self._get_tzname('Europe/London')

        with self._gettz_context(tzname):
            LON = self.gettz(tzname)
            UTC = tz.tzutc()

            t0_u = datetime(2013, 10, 27, 0, 30, tzinfo=UTC)   # BST
            t1_u = datetime(2013, 10, 27, 1, 30, tzinfo=UTC)   # GMT

            t0 = t0_u.astimezone(LON)
            t1 = t1_u.astimezone(LON)

            self.assertEqual(t0.replace(tzinfo=None),
                             datetime(2013, 10, 27, 1, 30))

            self.assertEqual(t1.replace(tzinfo=None),
                             datetime(2013, 10, 27, 1, 30))

            self.assertEqual(t0.utcoffset(), timedelta(hours=1))
            self.assertEqual(t1.utcoffset(), timedelta(hours=0)) 
Example 11
Project: plugin.video.emby   Author: MediaBrowser   File: test_tz.py    License: GNU General Public License v3.0 6 votes vote down vote up
def testInZoneFoldEquality(self):
        # Two datetimes in the same zone are considered to be equal if their
        # wall times are equal, even if they have different absolute times.

        tzname = self._get_tzname('America/New_York')

        with self._gettz_context(tzname):
            NYC = self.gettz(tzname)
            UTC = tz.tzutc()

            dt0 = datetime(2011, 11, 6, 1, 30, tzinfo=NYC)
            dt1 = tz.enfold(dt0, fold=1)

            # Make sure these actually represent different times
            self.assertNotEqual(dt0.astimezone(UTC), dt1.astimezone(UTC))

            # Test that they compare equal
            self.assertEqual(dt0, dt1) 
Example 12
Project: plugin.video.emby   Author: MediaBrowser   File: test_tz.py    License: GNU General Public License v3.0 6 votes vote down vote up
def get_utc_transitions(self, tzi, year, gap):
        dston, dstoff = tzi.transitions(year)
        if gap:
            t_n = dston - timedelta(minutes=30)

            t0_u = t_n.replace(tzinfo=tzi).astimezone(tz.tzutc())
            t1_u = t0_u + timedelta(hours=1)
        else:
            # Get 1 hour before the first ambiguous date
            t_n = dstoff - timedelta(minutes=30)

            t0_u = t_n.replace(tzinfo=tzi).astimezone(tz.tzutc())
            t_n += timedelta(hours=1)                   # Naive ambiguous date
            t0_u = t0_u + timedelta(hours=1)            # First ambiguous date
            t1_u = t0_u + timedelta(hours=1)            # Second ambiguous date

        return t_n, t0_u, t1_u 
Example 13
Project: plugin.video.emby   Author: MediaBrowser   File: test_tz.py    License: GNU General Public License v3.0 6 votes vote down vote up
def testGapPositiveUTCOffset(self):
        # Test that we don't have a problem around gaps.
        tzname = 'AUS Eastern Standard Time'
        args = self.get_args(tzname)

        with self.context(tzname):
            SYD = self.tzclass(*args)

            t_n, t0_u, t1_u = self.get_utc_transitions(SYD, 2012, True)

            t0 = t0_u.astimezone(SYD)
            t1 = t1_u.astimezone(SYD)

            self.assertEqual(t0.replace(tzinfo=None), t_n)

            self.assertEqual(t1.replace(tzinfo=None), t_n + timedelta(hours=2))

            self.assertEqual(t0.utcoffset(), timedelta(hours=10))
            self.assertEqual(t1.utcoffset(), timedelta(hours=11)) 
Example 14
Project: plugin.video.emby   Author: MediaBrowser   File: test_tz.py    License: GNU General Public License v3.0 6 votes vote down vote up
def testFoldNegativeUTCOffset(self):
        # Test that we can resolve ambiguous times
        tzname = 'Eastern Standard Time'
        args = self.get_args(tzname)

        with self.context(tzname):
            TOR = self.tzclass(*args)

            t_n, t0_u, t1_u = self.get_utc_transitions(TOR, 2011, False)

            t0_tor = t0_u.astimezone(TOR)
            t1_tor = t1_u.astimezone(TOR)

            self.assertEqual(t0_tor.replace(tzinfo=None), t_n)
            self.assertEqual(t1_tor.replace(tzinfo=None), t_n)

            self.assertNotEqual(t0_tor.tzname(), t1_tor.tzname())
            self.assertEqual(t0_tor.utcoffset(), timedelta(hours=-4.0))
            self.assertEqual(t1_tor.utcoffset(), timedelta(hours=-5.0)) 
Example 15
Project: plugin.video.emby   Author: MediaBrowser   File: test_tz.py    License: GNU General Public License v3.0 6 votes vote down vote up
def testGapNegativeUTCOffset(self):
        # Test that we don't have a problem around gaps.
        tzname = 'Eastern Standard Time'
        args = self.get_args(tzname)

        with self.context(tzname):
            TOR = self.tzclass(*args)

            t_n, t0_u, t1_u = self.get_utc_transitions(TOR, 2011, True)

            t0 = t0_u.astimezone(TOR)
            t1 = t1_u.astimezone(TOR)

            self.assertEqual(t0.replace(tzinfo=None),
                             t_n)

            self.assertEqual(t1.replace(tzinfo=None),
                             t_n + timedelta(hours=2))

            self.assertNotEqual(t0.tzname(), t1.tzname())
            self.assertEqual(t0.utcoffset(), timedelta(hours=-5.0))
            self.assertEqual(t1.utcoffset(), timedelta(hours=-4.0)) 
Example 16
Project: plugin.video.emby   Author: MediaBrowser   File: test_tz.py    License: GNU General Public License v3.0 6 votes vote down vote up
def testInZoneFoldEquality(self):
        # Two datetimes in the same zone are considered to be equal if their
        # wall times are equal, even if they have different absolute times.
        tzname = 'Eastern Standard Time'
        args = self.get_args(tzname)

        with self.context(tzname):
            NYC = self.tzclass(*args)
            UTC = tz.tzutc()

            t_n, t0_u, t1_u = self.get_utc_transitions(NYC, 2011, False)

            dt0 = t_n.replace(tzinfo=NYC)
            dt1 = tz.enfold(dt0, fold=1)

            # Make sure these actually represent different times
            self.assertNotEqual(dt0.astimezone(UTC), dt1.astimezone(UTC))

            # Test that they compare equal
            self.assertEqual(dt0, dt1)

###
# Test Cases 
Example 17
Project: plugin.video.emby   Author: MediaBrowser   File: test_tz.py    License: GNU General Public License v3.0 6 votes vote down vote up
def testTzwinName(self):
        # https://github.com/dateutil/dateutil/issues/143
        tw = tz.tzwin('Eastern Standard Time')

        # Cover the transitions for at least two years.
        ESTs = 'Eastern Standard Time'
        EDTs = 'Eastern Daylight Time'
        transition_dates = [(datetime(2015, 3, 8, 0, 59), ESTs),
                            (datetime(2015, 3, 8, 3, 1), EDTs),
                            (datetime(2015, 11, 1, 0, 59), EDTs),
                            (datetime(2015, 11, 1, 3, 1), ESTs),
                            (datetime(2016, 3, 13, 0, 59), ESTs),
                            (datetime(2016, 3, 13, 3, 1), EDTs),
                            (datetime(2016, 11, 6, 0, 59), EDTs),
                            (datetime(2016, 11, 6, 3, 1), ESTs)]

        for t_date, expected in transition_dates:
            self.assertEqual(t_date.replace(tzinfo=tw).tzname(), expected) 
Example 18
Project: aws-ops-automator   Author: awslabs   File: cron_expression.py    License: Apache License 2.0 5 votes vote down vote up
def _localized_time(self, dt=None):
        """
        Checks if timezone information must be added to tz. If the dt parameter is not set then the default dt set in the parameter
        if used if it was set otherwise the  localized current time is used
        :param dt: Tested datetime or None for current datetime
        :return: Localized datetime
        """
        if dt:
            return dt.replace(tzinfo=self._timezone) if dt.tzinfo is None else dt
        return datetime.now(tz=self._timezone) 
Example 19
Project: aws-ops-automator   Author: awslabs   File: cron_expression.py    License: Apache License 2.0 5 votes vote down vote up
def _move_to_previous_month(self, dt):
        """
        Move to end of previous month
        :param dt: Tested datetime
        :return: Last day for expression in previous month
        """
        # is the current month is the list
        if dt.month in self._month:
            # get the index -1, note that if the index is -1  the last item in the list is used so no special
            # handling required if it is the first one in the list and we have to move back to previous month
            index = self._month.index(dt.month) - 1
        else:
            # find a matching index in the list that is <= current month
            index = len(self._month) - 1
            while index >= 0:
                if self._month[index] <= dt.month:
                    break
                index -= 1

        # get the month from the list
        previous_month = self._month[index]

        # year - 1 if the new month is later than the current month
        year = dt.year if previous_month < dt.month else dt.year - 1

        previous_month_builder = MonthdaySetBuilder(year=year, month=previous_month)
        month_days_previous = sorted(previous_month_builder.build(self._day_of_month_str))
        day = max(month_days_previous) if month_days_previous != [] else previous_month_builder.last

        # return the last event for the last day of the previous month
        return datetime(year=year, month=previous_month, day=day, hour=max(self._hours), minute=max(self._minutes),
                        tzinfo=dt.tzinfo) 
Example 20
Project: aws-ops-automator   Author: awslabs   File: cron_expression.py    License: Apache License 2.0 5 votes vote down vote up
def _move_to_next_month(self, dt):
        """
        Move to first day in next month
        :param dt: Tested datetime
        :return: First day in next month for expression
        """
        # is the current month is the set
        if dt.month in self._month:
            # get the index + 1, wrap to first in list if last entry
            index = (self._month.index(dt.month) + 1) % len(self._month)
        else:
            # find a matching index in the list that is >= current month
            index = 0
            while index < len(self._month) - 1:
                if self._month[index] >= dt.month:
                    break
                index += 1
        # get the month
        next_month = self._month[index]

        # year + 1 if the new month is earlier than the next month
        year = dt.year if next_month > dt.month else dt.year + 1

        next_month_builder = MonthdaySetBuilder(year=year, month=next_month)
        month_days_next = sorted(next_month_builder.build(self._day_of_month_str))
        day = min(month_days_next) if month_days_next != [] else next_month_builder.first

        return datetime(year=year, month=next_month, day=day, hour=min(self._hours), minute=min(self._minutes), tzinfo=dt.tzinfo) 
Example 21
Project: pyspark-cassandra   Author: TargetHolding   File: types.py    License: Apache License 2.0 5 votes vote down vote up
def _decode_primitives(ctype, cvalue):
    fmt = _numpy_to_struct_formats.get(ctype)

    # if unsupported, return as the list if bytes it was
    if not fmt:
        return cvalue

    primitives = _unpack(fmt, cvalue)

    if ctype == '>M8[ms]':
        return [datetime.utcfromtimestamp(l).replace(tzinfo=UTC) for l in primitives]
    else:
        return primitives 
Example 22
Project: razzy-spinner   Author: rafasashi   File: api.py    License: GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, limit=20, upper_date_limit=None, lower_date_limit=None):
        """
        :param int limit: The number of data items to process in the current\
        round of processing.

        :param tuple upper_date_limit: The date at which to stop collecting\
        new data. This should be entered as a tuple which can serve as the\
        argument to `datetime.datetime`.\
        E.g. `date_limit=(2015, 4, 1, 12, 40)` for 12:30 pm on April 1 2015.

        :param tuple lower_date_limit: The date at which to stop collecting\
        new data. See `upper_data_limit` for formatting.
        """
        BasicTweetHandler.__init__(self, limit)

        self.upper_date_limit = None
        self.lower_date_limit = None
        if upper_date_limit:
            self.upper_date_limit = datetime(*upper_date_limit, tzinfo=LOCAL)
        if lower_date_limit:
            self.lower_date_limit = datetime(*lower_date_limit, tzinfo=LOCAL)

        self.startingup = True 
Example 23
Project: misp42splunk   Author: remg427   File: base.py    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
def from_timestamp(self, value):
        try:
            return datetime.datetime(1970, 1, 1, tzinfo=self.UTC) + datetime.timedelta(seconds=value)
        except (ValueError, TypeError):
            return None 
Example 24
Project: misp42splunk   Author: remg427   File: base.py    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
def validate_tz(self, value, context=None):
        if value.tzinfo is None:
            if not self.drop_tzinfo:
                if self.tzd == 'require':
                    raise ValidationError(self.messages['validate_tzd_require'])
                if self.tzd == 'utc':
                    raise ValidationError(self.messages['validate_utc_none'])
        else:
            if self.drop_tzinfo:
                raise ValidationError(self.messages['validate_tzd_reject'])
            if self.tzd == 'reject':
                raise ValidationError(self.messages['validate_tzd_reject'])
            if self.convert_tz \
              and value.tzinfo.utcoffset(value) != self.TIMEDELTA_ZERO:
                raise ValidationError(self.messages['validate_utc_wrong']) 
Example 25
Project: misp42splunk   Author: remg427   File: base.py    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
def to_primitive(self, value, context=None):
        if value.tzinfo is None:
            value = value.replace(tzinfo=self.UTC)
        else:
            value = value.astimezone(self.UTC)
        delta = value - self.EPOCH
        return delta.total_seconds() 
Example 26
Project: misp42splunk   Author: remg427   File: base.py    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
def from_timestamp(self, value):
        try:
            return datetime.datetime(1970, 1, 1, tzinfo=self.UTC) + datetime.timedelta(seconds=value)
        except (ValueError, TypeError):
            return None 
Example 27
Project: misp42splunk   Author: remg427   File: base.py    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
def validate_tz(self, value, context=None):
        if value.tzinfo is None:
            if not self.drop_tzinfo:
                if self.tzd == 'require':
                    raise ValidationError(self.messages['validate_tzd_require'])
                if self.tzd == 'utc':
                    raise ValidationError(self.messages['validate_utc_none'])
        else:
            if self.drop_tzinfo:
                raise ValidationError(self.messages['validate_tzd_reject'])
            if self.tzd == 'reject':
                raise ValidationError(self.messages['validate_tzd_reject'])
            if self.convert_tz \
              and value.tzinfo.utcoffset(value) != self.TIMEDELTA_ZERO:
                raise ValidationError(self.messages['validate_utc_wrong']) 
Example 28
Project: misp42splunk   Author: remg427   File: base.py    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
def to_primitive(self, value, context=None):
        if value.tzinfo is None:
            value = value.replace(tzinfo=self.UTC)
        else:
            value = value.astimezone(self.UTC)
        delta = value - self.EPOCH
        return delta.total_seconds() 
Example 29
Project: plugin.video.emby   Author: MediaBrowser   File: _parser.py    License: GNU General Public License v3.0 5 votes vote down vote up
def _build_tzinfo(self, tzinfos, tzname, tzoffset):
        if callable(tzinfos):
            tzdata = tzinfos(tzname, tzoffset)
        else:
            tzdata = tzinfos.get(tzname)
        # handle case where tzinfo is paased an options that returns None
        # eg tzinfos = {'BRST' : None}
        if isinstance(tzdata, datetime.tzinfo) or tzdata is None:
            tzinfo = tzdata
        elif isinstance(tzdata, text_type):
            tzinfo = tz.tzstr(tzdata)
        elif isinstance(tzdata, integer_types):
            tzinfo = tz.tzoffset(tzname, tzdata)
        return tzinfo 
Example 30
Project: plugin.video.emby   Author: MediaBrowser   File: _parser.py    License: GNU General Public License v3.0 5 votes vote down vote up
def _build_tzaware(self, naive, res, tzinfos):
        if (callable(tzinfos) or (tzinfos and res.tzname in tzinfos)):
            tzinfo = self._build_tzinfo(tzinfos, res.tzname, res.tzoffset)
            aware = naive.replace(tzinfo=tzinfo)
            aware = self._assign_tzname(aware, res.tzname)

        elif res.tzname and res.tzname in time.tzname:
            aware = naive.replace(tzinfo=tz.tzlocal())

            # Handle ambiguous local datetime
            aware = self._assign_tzname(aware, res.tzname)

            # This is mostly relevant for winter GMT zones parsed in the UK
            if (aware.tzname() != res.tzname and
                    res.tzname in self.info.UTCZONE):
                aware = aware.replace(tzinfo=tz.tzutc())

        elif res.tzoffset == 0:
            aware = naive.replace(tzinfo=tz.tzutc())

        elif res.tzoffset:
            aware = naive.replace(tzinfo=tz.tzoffset(res.tzname, res.tzoffset))

        elif not res.tzname and not res.tzoffset:
            # i.e. no timezone information was found.
            aware = naive

        elif res.tzname:
            # tz-like string was parsed but we don't know what to do
            # with it
            warnings.warn("tzname {tzname} identified but not understood.  "
                          "Pass `tzinfos` argument in order to correctly "
                          "return a timezone-aware datetime.  In a future "
                          "version, this will raise an "
                          "exception.".format(tzname=res.tzname),
                          category=UnknownTimezoneWarning)
            aware = naive

        return aware