Checks that the `max_length` attribute covers all possible pytz
        timezone lengths.
966245
def _check_timezone_max_length_attribute(self):     # pragma: no cover
        

        # Retrieve the maximum possible length for the time zone string
        possible_max_length = max(map(len, pytz.all_timezones))

        # Make sure that the max_length attribute will handle the longest time
        #   zone string
        if self.max_length < possible_max_length:   # pragma: no cover
            return [
                checks.Error(
                    msg=(
                        "'max_length' is too short to support all possible "
                        "pytz time zones."
                    ),
                    hint=(
                        "pytz {version}'s longest time zone string has a "
                        "length of {value}, although it is recommended that "
                        "you leave room for longer time zone strings to be "
                        "added in the future.".format(
                            version=pytz.VERSION,
                            value=possible_max_length
                        )
                    ),
                    obj=self,
                )
            ]

        # When no error, return an empty list
        return []
650381
def _tzinfome(tzinfo):
  
  if not isinstance(tzinfo, datetime.tzinfo):
    try:
      tzinfo = pytz.timezone(tzinfo)
      assert tzinfo.zone in pytz.all_timezones
    except AttributeError:
      raise pytz.UnknownTimeZoneError("Unknown timezone! %s" % tzinfo)
  return tzinfo
1201506
def timezones_choices():
    
    utcnow = pytz.utc.localize(datetime.utcnow())
    locale = _get_locale()
    for tz in sorted(pytz.common_timezones):
        tz = get_timezone(tz)
        now = tz.normalize(utcnow.astimezone(tz))
        label = "({}) {}".format(get_timezone_gmt(now, locale=locale), tz.zone)
        yield (tz, label)
1089464
def get_timerange(self, start, end, code=None):
        
        try:
            return self.data.loc[(slice(pd.Timestamp(start), pd.Timestamp(end)), slice(code)), :]
        except:
            return ValueError('CANNOT FOUND THIS TIME RANGE')
563980
def tz(self):
        """"""

        if self.timezone is None:
            return None

        try:
            tz = pytz.timezone(self.timezone)
            return tz
        except pytz.UnknownTimeZoneError:
            raise AstralError("Unknown timezone '%s'" % self.timezone)
808671
def ListTimeZones(self):
    """"""
    max_length = 0
    for timezone_name in pytz.all_timezones:
      if len(timezone_name) > max_length:
        max_length = len(timezone_name)

    utc_date_time = datetime.datetime.utcnow()

    table_view = views.ViewsFactory.GetTableView(
        self._views_format_type, column_names=['Timezone', 'UTC Offset'],
        title='Zones')
    for timezone_name in pytz.all_timezones:
      try:
        local_timezone = pytz.timezone(timezone_name)
      except AssertionError as exception:
        logger.error((
            'Unable to determine information about timezone: {0:s} with '
            'error: {1!s}').format(timezone_name, exception))
        continue

      local_date_string = '{0!s}'.format(
          local_timezone.localize(utc_date_time))
      if '+' in local_date_string:
        _, _, diff = local_date_string.rpartition('+')
        diff_string = '+{0:s}'.format(diff)
      else:
        _, _, diff = local_date_string.rpartition('-')
        diff_string = '-{0:s}'.format(diff)

      table_view.AddRow([timezone_name, diff_string])

    table_view.Write(self._output_writer)
1217028
def _calculate_bounds(self):
        """"""
        # get start datetime
        first = self.coll_handle.find_one(None, sort=[("ts", ASCENDING)])
        last = self.coll_handle.find_one(None, sort=[("ts", DESCENDING)])

        self._start = first['ts']
        if self._start.tzinfo is None:
            self._start = self._start.replace(tzinfo=tzutc())

        self._end = last['ts']
        if self._end.tzinfo is None:
            self._end = self._end.replace(tzinfo=tzutc())

        return True
205910
def upto(max)
      if block_given?
        super {|dt| yield dt.clear_timezone_offset }
      else
        enum = super
        enum.each {|dt| dt.clear_timezone_offset }
        enum
      end
    end
395661
def getTzid(tzid, smart=True):
    """"""
    tz = __tzidMap.get(toUnicode(tzid), None)
    if smart and tzid and not tz:
        try:
            from pytz import timezone, UnknownTimeZoneError
            try:
                tz = timezone(tzid)
                registerTzid(toUnicode(tzid), tz)
            except UnknownTimeZoneError:
                pass
        except ImportError:
            pass
    return tz
1332204
def fix_timezone_separator(cls, timestr):
        
        tz_sep = cls.TIMEZONE_SEPARATOR.match(timestr)
        if tz_sep is not None:
            return tz_sep.group(1) + tz_sep.group(2) + ':' + tz_sep.group(3)
        return timestr
470875
def _get_system_tz(self):
        '''
        
        '''
        if not HAS_PYTZ:
            return None

        def _etc_localtime():
            try:
                with open('/etc/localtime', 'rb') as fp:
                    return pytz.tzfile.build_tzinfo('system', fp)
            except OSError as exc:
                if exc.errno != errno.ENOENT:
                    self.logger.error(
                        'Unable to read from /etc/localtime: %s', exc.strerror
                    )
            except pytz.UnknownTimeZoneError:
                self.logger.error(
                    '/etc/localtime contains unrecognized tzinfo'
                )
            return None

        def _etc_timezone():
            try:
                with open('/etc/timezone', 'r') as fp:
                    tzname = fp.read().strip()
                return pytz.timezone(tzname)
            except OSError as exc:
                if exc.errno != errno.ENOENT:
                    self.logger.error(
                        'Unable to read from /etc/localtime: %s', exc.strerror
                    )
            except pytz.UnknownTimeZoneError:
                self.logger.error(
                    '/etc/timezone contains unrecognized timezone \'%s\'',
                    tzname
                )
            return None

        return _etc_localtime() or _etc_timezone()
1266031
def is_length(property_name, *, min_length=1, max_length=None, present_optional=False):
    """"""
    def check(val):
      """Checks that a value matches a scope-enclosed set of length parameters."""
      if not val:
        return present_optional
      else:
        if len(val) >= min_length:
          if max_length is None:
            return True
          else:
            return len(val) <= max_length
        else:
          return False

    if max_length:
      message = "must be at least {0} characters long".format(min_length)
    else:
      message = "must be between {0} and {1} characters long".format(min_length, max_length)

    return Validation(check, property_name, message)
228604
def get_username_max_len():
    
    fields = [field for field in USER._meta.fields if field.name == 'username']
    try:
        length = fields[0].max_length
    except IndexError:
        length = 30
    return length
853828
def max_extents(extents, zrange=False):
    
    if zrange:
        num = 6
        inds = [(0, 3), (1, 4), (2, 5)]
        extents = [e if len(e) == 6 else (e[0], e[1], None,
                                          e[2], e[3], None)
                   for e in extents]
    else:
        num = 4
        inds = [(0, 2), (1, 3)]
    arr = list(zip(*extents)) if extents else []
    extents = [np.NaN] * num
    if len(arr) == 0:
        return extents
    with warnings.catch_warnings():
        warnings.filterwarnings('ignore', r'All-NaN (slice|axis) encountered')
        for lidx, uidx in inds:
            lower = [v for v in arr[lidx] if v is not None and not is_nan(v)]
            upper = [v for v in arr[uidx] if v is not None and not is_nan(v)]
            if lower and isinstance(lower[0], datetime_types):
                extents[lidx] = np.min(lower)
            elif any(isinstance(l, basestring) for l in lower):
                extents[lidx] = np.sort(lower)[0]
            elif lower:
                extents[lidx] = np.nanmin(lower)
            if upper and isinstance(upper[0], datetime_types):
                extents[uidx] = np.max(upper)
            elif any(isinstance(u, basestring) for u in upper):
                extents[uidx] = np.sort(upper)[-1]
            elif upper:
                extents[uidx] = np.nanmax(upper)
    return tuple(extents)
304900
def length_limits(max_length_limit, length_limit_step):
    """"""
    string_len = len(str(max_length_limit))
    return [
        str(i).zfill(string_len) for i in
        xrange(
            length_limit_step,
            max_length_limit + length_limit_step - 1,
            length_limit_step
        )
    ]
260502
def _check_title_length(title, api):
    '''  '''
    if len(title) > api.MAX_LIST_TITLE_LENGTH:
        raise ValueError("Title cannot be longer than {} characters".format(api.MAX_TASK_TITLE_LENGTH))
689798
def max_input_length(self) -> int:
        
        if self.source_with_eos:
            return self._max_input_length - C.SPACE_FOR_XOS
        else:
            return self._max_input_length