Work out the time zone and create a shim tzinfo.

        We return True if all is good or False if there was an issue and we
        need to re check the time zone.  see issue #1375
175902
def set_time_zone(self, item):
        
        # parse i3status date
        i3s_time = item["full_text"].encode("UTF-8", "replace")
        try:
            # python3 compatibility code
            i3s_time = i3s_time.decode()
        except:  # noqa e722
            pass

        # get datetime and time zone info
        parts = i3s_time.split()
        i3s_datetime = " ".join(parts[:2])
        # occassionally we do not get the timezone name
        if len(parts) < 3:
            return True
        else:
            i3s_time_tz = parts[2]

        date = datetime.strptime(i3s_datetime, TIME_FORMAT)
        # calculate the time delta
        utcnow = datetime.utcnow()
        delta = datetime(
            date.year, date.month, date.day, date.hour, date.minute
        ) - datetime(utcnow.year, utcnow.month, utcnow.day, utcnow.hour, utcnow.minute)
        # create our custom timezone
        try:
            self.tz = Tz(i3s_time_tz, delta)
        except ValueError:
            return False
        return True
317082
def fix_timezone(df, freq, tz=None):
    
    index_name = df.index.name

    # fix timezone
    if isinstance(df.index[0], str):
        # timezone df exists
        if ("-" in df.index[0][-6:]) | ("+" in df.index[0][-6:]):
            df.index = pd.to_datetime(df.index, utc=False)
            df.index = df.index.tz_localize('UTC').tz_convert(tz)

        # no timezone df - do some resampling
        else:
            # original range
            start_range = df.index[0]
            end_range = df.index[-1]

            # resample df
            df.index = pd.to_datetime(df.index, utc=True)
            df = resample(df, resolution=freq, ffill=False, dropna=False)

            # create date range
            new_freq = ''.join(i for i in freq if not i.isdigit())
            rng = pd.date_range(start=start_range,
                                end=end_range, tz=tz, freq=new_freq)

            # assign date range to df and drop empty rows
            df.index = rng
            df.dropna(inplace=True)

    # finalize timezone (also for timezone-aware df)
    df = set_timezone(df, tz=tz)

    df.index.name = index_name
    return df
584447
def what_time_is_it(self, message):
        """"""
        now = datetime.datetime.now()
        self.say("It's %s." % self.to_natural_day_and_time(now, with_timezone=True), message=message)
1009379
def _generate_timezone(date, local_tz):
    
    offset = _calculate_offset(date, local_tz)

    hour = abs(offset) // 3600
    minute = abs(offset) % 3600 // 60

    if offset < 0:
        return '%c%02d:%02d' % ("-", hour, minute)
    else:
        return '%c%02d:%02d' % ("+", hour, minute)
145015
def SetTimeZone(self, time_zone):
    
    try:
      self._time_zone = pytz.timezone(time_zone)
    except (AttributeError, pytz.UnknownTimeZoneError):
      raise ValueError('Unsupported timezone: {0!s}'.format(time_zone))
537401
def setup_timezone(timezone: str) -> None:
    
    if timezone and hasattr(time, 'tzset'):
        tz_root = '/usr/share/zoneinfo'
        tz_filename = os.path.join(tz_root, *(timezone.split('/')))

        if os.path.exists(tz_root) and not os.path.exists(tz_filename):
            raise ValueError('Incorrect timezone value: {0}'.format(timezone))

        os.environ['TZ'] = timezone
        time.tzset()
1118422
def timezone(calendar, vtimezones):
    
    for vtimezone in vtimezones:
        remove_x(vtimezone)  # Remove non standard lines from the block
        fake_file = StringIO()
        fake_file.write(str(vtimezone))  # Represent the block as a string
        fake_file.seek(0)
        timezones = tzical(fake_file)  # tzical does not like strings
        # timezones is a tzical object and could contain multiple timezones
        for key in timezones.keys():
            calendar._timezones[key] = timezones.get(key)
725224
def mktime_tz(data):
    """"""
    if data[9] is None:
        # No zone info, so localtime is better assumption than GMT
        return time.mktime(data[:8] + (-1,))
    else:
        t = calendar.timegm(data)
        return t - data[9]
1314685
def is_published(self):
        
        if self.published:
            now = timezone.now()
            if now >= self.published:
                return True
        return False
151562
def valid_date(date):
    ""
    # We want something that acts like a datetime. In particular,
    # strings indicate a failure to parse down to an object and ints are
    # nonstandard and ambiguous at best.
    if not hasattr(date, 'tzinfo'):
        return False
    # Relevant RFCs define UTC as 'close enough' to GMT, and the maximum
    # difference between UTC and GMT is often stated to be less than a second.
    if date.tzinfo is None or _total_seconds(date.utcoffset()) < 1.1:
        return True
    return False
178986
function compareTimeZones(a, b) {
    if (typeof a !== 'string' || typeof b !== 'string') {
      return NaN;
    }

    return normalizeIso8601TimeZone(a) - normalizeIso8601TimeZone(b);
  }
896597
async def get_timezone(self) -> Optional[tzinfo]:
        

        u = await self._get_user()
        diff = float(u.get('timezone', 0)) * 3600.0

        return tz.tzoffset('ITC', diff)
978362
public boolean isValid(TZID tzid) {

        if (tzid == null) {
            return false;
        }

        return !Timezone.of(tzid).isInvalid(this.date, this.time);

    }
1017004
def set_timezone(rollback=False):
    
    if not rollback:
        if contains(filename='/etc/timezone', text=env.TIME_ZONE, use_sudo=True):
            return False
        if env.verbosity:
            print env.host, "CHANGING TIMEZONE /etc/timezone to "+env.TIME_ZONE
        _backup_file('/etc/timezone')
        sudo('echo %s > /tmp/timezone'% env.TIME_ZONE)
        sudo('cp -f /tmp/timezone /etc/timezone')
        sudo('dpkg-reconfigure --frontend noninteractive tzdata')
    else:
        _restore_fie('/etc/timezone')
        sudo('dpkg-reconfigure --frontend noninteractive tzdata')
    return True
961639
function( format ) {

			this.setFormat(format);
			var out = '';

			// time can only be created with a full date
			if(this.tH) {
				if(this.tH > -1 && this.tH < 25) {
					out += this.tH;
					if(this.tM > -1 && this.tM < 61){
						out += this.tsep + this.tM;
						if(this.tS > -1 && this.tS < 61){
							out += this.tsep + this.tS;
							if(this.tD > -1){
								out += '.' + this.tD;
							}
						}
					}



					// time zone offset
					if(this.z) {
						out += this.tzZulu;
					} else {
						if(this.tzH && this.tzH > -1 && this.tzH < 25) {
							out += this.tzPN + this.tzH;
							if(this.tzM > -1 && this.tzM < 61){
								out += this.tzsep + this.tzM;
							}
						}
					}
				}
			}
			return out;
		}
754548
def timezone(self, tz):
        
        self.data['resolving'].update(
            timezone=tz,
            time_show_zone=True)
1347551
def normalize_time_to_netsuite_date(unix_timestamp)
      # convert to date to eliminate hr/min/sec
      time = Time.at(unix_timestamp).
        utc.
        to_date.
        to_datetime

      # tzinfo allows us to determine the dst status of the time being passed in
      # NetSuite requires that the time be passed to the API with the PDT TZ offset
      # of the time passed in (i.e. not the current TZ offset of PDT)

      if defined?(TZInfo)
        # if no version is defined, less than 2.0
        # https://github.com/tzinfo/tzinfo/blob/master/CHANGES.md#added
        if !defined?(TZInfo::VERSION)
          # https://stackoverflow.com/questions/2927111/ruby-get-time-in-given-timezone
          offset = TZInfo::Timezone.get("America/Los_Angeles").period_for_utc(time).utc_total_offset_rational
          time = time.new_offset(offset)
        else
          time = TZInfo::Timezone.get("America/Los_Angeles").utc_to_local(time)
          offset = time.offset
        end
      else
        # if tzinfo is not installed, let's give it our best guess: -7
        offset = Rational(-7, 24)
        time = time.new_offset("-07:00")
      end

      time = (time + (offset * -1))
      time.iso8601
    end