(Internal) Convert TZ offset in minutes east to string.
549054
def _tz_offset_string(offset):
        """"""

        s = ""
        io = int(offset)
        if io == 0:
            s += "Z"
        else:
            if -1440 < io < 1440:
                ho = abs(io) / 60
                mo = abs(io) % 60

                s += "%c%02u" % ("+" if io > 0 else "-", ho)
                if mo != 0:
                    s += ":%02u" % mo

            else:
                raise ValueError("Timezone `offset` (%u) out of range "
                                 "-1439 to +1439 minutes" % io)
        return s
615281
def ensure_timezone(dt, tz=None):
    
    if dt.tzinfo is None:
        return dt.replace(tzinfo=tz or tzlocal())
    else:
        return dt
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)
650863
def _calculate_offset(date, local_tz):
    
    if local_tz:
        #handle year before 1970 most sytem there is no timezone information before 1970.
        if date.year < 1970:
            # Use 1972 because 1970 doesn't have a leap day
            t = time.mktime(date.replace(year=1972).timetuple)
        else:
            t = time.mktime(date.timetuple())

        # handle daylightsaving, if daylightsaving use altzone, otherwise use timezone
        if time.localtime(t).tm_isdst:
            return -time.altzone
        else:
            return -time.timezone
    else:
        return 0
431047
def time2string(tstamp, micro=True):
    """"""
    tformat = TIME_FORMAT if micro else TIME_FORMAT[:-len(MICRO)]
    return tstamp.strftime(tformat)
997227
def isoformat(dt, localtime=False, *args, **kwargs):
    """"""
    if localtime and dt.tzinfo is not None:
        localized = dt
    else:
        if dt.tzinfo is None:
            localized = UTC.localize(dt)
        else:
            localized = dt.astimezone(UTC)
    return localized.isoformat(*args, **kwargs)
685135
def time_string(seconds):
    """"""
    s = int(round(seconds))  # round to nearest second
    h, s = divmod(s, 3600)  # get hours and remainder
    m, s = divmod(s, 60)  # split remainder into minutes and seconds
    return "%2i:%02i:%02i" % (h, m, s)
837911
def to_iso8601_string(self):
        
        string = self._to_string("iso8601")

        if self.tz and self.tz.name == "UTC":
            string = string.replace("+00:00", "Z")

        return string
895885
function getIso8601String(timeMs) {
  var time = new Date();
  time.setTime(timeMs);
  return '' +
      time.getUTCFullYear() + '-' +
      leftPadNumber(time.getUTCMonth() + 1, 2, '0') + '-' +
      leftPadNumber(time.getUTCDate(), 2, '0') + 'T' +
      leftPadNumber(time.getUTCHours(), 2, '0') + ':' +
      leftPadNumber(time.getUTCMinutes(), 2, '0') + ':' +
      leftPadNumber(time.getUTCSeconds(), 2, '0') + 'Z';
}
1132534
def _offset_to_min(utc_offset):
    '''
    
    '''
    match = re.match(r"^([+-])?(\d\d)(\d\d)$", utc_offset)
    if not match:
        raise SaltInvocationError("Invalid UTC offset")

    sign = -1 if match.group(1) == '-' else 1
    hours_offset = int(match.group(2))
    minutes_offset = int(match.group(3))
    total_offset = sign * (hours_offset * 60 + minutes_offset)
    return total_offset
393604
def localize(dt, tz):
    
    if not isinstance(tz, tzinfo):
        tz = pytz.timezone(tz)

    return tz.localize(dt)
210794
function parseTimezoneOffset (offset) {
  let [, sign, hours, minutes] = offset.match(/(\+|-)(\d\d)(\d\d)/)
  minutes = (sign === '+' ? 1 : -1) * (Number(hours) * 60 + Number(minutes))
  return negateExceptForZero(minutes)
}
648576
def convert_timestamp(timestamp):
    """"""
    timestamp = timestamp.strip()
    chunk, millis = timestamp.split(',')
    hours, minutes, seconds = chunk.split(':')
    hours = int(hours)
    minutes = int(minutes)
    seconds = int(seconds)
    seconds = seconds + hours * 60 * 60 + minutes * 60 + float(millis) / 1000
    return seconds
653833
def to_ts(s):
        

        # Strip TZ portion if present
        m = Nginx.DATE_FMT.match(s)
        if m:
            s = m.group(1)
            delta = timedelta(seconds=int(m.group(3)) * (-1 if m.group(2) == '-' else 1)) # Offset from GMT
        else:
            delta = timedelta(seconds=0)
        dt = datetime.strptime(s, "%d/%b/%Y:%H:%M:%S")
        dt += delta
        return dt.strftime('%Y-%m-%dT%H:%M:%SZ')
345449
def to_local(self, dt):
        """"""
        if dt.tzinfo is None:
            dt = dt.replace(tzinfo=self.utc)
        return dt.astimezone(self.local)
91093
def tzname(self, dt):
        
        # total_seconds was introduced in Python 2.7
        if hasattr(self.__offset, "total_seconds"):
            total_seconds = self.__offset.total_seconds()
        else:
            total_seconds = (self.__offset.days * 24 * 60 * 60) + \
                            (self.__offset.seconds)

        hours = total_seconds // (60 * 60)
        total_seconds -= hours * 60 * 60

        minutes = total_seconds // 60
        total_seconds -= minutes * 60

        seconds = total_seconds // 1
        total_seconds -= seconds

        if seconds:
            return "%+03d:%02d:%02d" % (hours, minutes, seconds)
        return "%+03d:%02d" % (hours, minutes)
268975
function _tz2offset( $tz ) {
    $tz          = trim( (string) $tz );
    $offset      = 0;
    if((     5  == strlen( $tz )) &&
       ( '0000' <= substr( $tz, -4 )) &&
       ( '9999' >= substr( $tz, -4 )) &&
         (( '+' == substr( $tz, 0, 1 )) ||
          ( '-' == substr( $tz, 0, 1 )))) {
      $hours2sec = substr( $tz, 1, 2 ) * 3600;
      $min2sec   = substr( $tz, -2 )   * 60;
      $sign      = substr( $tz, 0, 1 );
      $offset    = (int) ( $sign.'1' * ($hours2sec + $min2sec ));
    }
    elseif(( 7  == strlen( $tz )) &&
     ( '000000' <= substr( $tz, -6 )) &&
     ( '999999' >= substr( $tz, -6 )) &&
         (( '+' == substr( $tz, 0, 1 )) ||
          ( '-' == substr( $tz, 0, 1 )))) {
      $hours2sec = substr( $tz, 1, 2 ) * 3600;
      $min2sec   = substr( $tz, 3, 2 ) *   60;
      $sec       = substr( $tz, -2 );
      $sign      = substr( $tz, 0, 1 );
      $offset    = (int) ( $sign.'1' * ( $hours2sec + $min2sec + $sec ));
    }
    return $offset;
  }