Converts the given UTC timestamp (defaults to the current time) to
    a two-tuple, (GPS week number, GPS seconds within the week).
337153
def toGPSWeekAndSecs(timestamp=None):
    
    if timestamp is None:
        timestamp = datetime.datetime.utcnow()

    leap = LeapSeconds.get_GPS_offset_for_date(timestamp)

    secsInWeek = 604800
    delta      = totalSeconds(timestamp - GPS_Epoch) + leap
    seconds    = delta % secsInWeek
    week       = int( math.floor(delta / secsInWeek) )

    return (week, seconds)
1122674
def utcoffset(self, dt):
        """"""
        tt = _localtime(_mktime((dt.year, dt.month, dt.day,
                 dt.hour, dt.minute, dt.second, dt.weekday(), 0, -1)))
        if tt.tm_isdst > 0: return _dstoffset
        return _stdoffset
538572
def convert_to_utc(time):
        

        # time is already in UTC
        if 'Z' in time:
            return time
        else:
            time_formatted = time[:-3] + time[-2:]
            dt = datetime.strptime(time_formatted, '%Y-%m-%dT%H:%M:%S%z')
            dt = dt.astimezone(timezone('UTC'))
            return dt.strftime('%Y-%m-%dT%H:%M:%SZ')
367745
def utc_mktime(utc_tuple):
  
  if len(utc_tuple) == 6:
      utc_tuple += (0, 0, 0)
  return time.mktime(utc_tuple) - time.mktime((1970, 1, 1, 0, 0, 0, 0, 0, 0))
1199861
def utcfromtimestamp(cls, timestamp):
    """"""
    obj = datetime.datetime.utcfromtimestamp(timestamp)
    obj = pytz.utc.localize(obj)
    return cls(obj)
587188
def _utc_float(self):
        """"""
        tai = self.tai
        leap_dates = self.ts.leap_dates
        leap_offsets = self.ts.leap_offsets
        leap_reverse_dates = leap_dates + leap_offsets / DAY_S
        i = searchsorted(leap_reverse_dates, tai, 'right')
        return tai - leap_offsets[i] / DAY_S
1223539
def T(t, step=30):
    
    if hasattr(t, 'timestamp'):
        timestamp = t.timestamp()
    else:
        # python 2
        if t.tzinfo is None:
            timestamp = time.mktime(t.timetuple())
        else:
            utc_naive  = t.replace(tzinfo=None) - t.utcoffset()
            timestamp = (utc_naive - datetime.datetime(1970, 1, 1)).total_seconds()

    return int(timestamp) // step
937719
def ulocalized_gmt0_time(self, time, context, request):
        
        value = get_date(context, time)
        if not value:
            return ""
        # DateTime is stored with TimeZone, but DateTimeWidget omits TZ
        value = value.toZone("GMT+0")
        return self.ulocalized_time(value, context, request)
412377
def datetime_to_timestamp(dt):
    

    epoch = datetime.utcfromtimestamp(0).replace(tzinfo=UTC)
    return (dt - epoch).total_seconds()
194205
def int_gps_time_to_str(t):
    """"""

    if isinstance(t, int):
        return str(t)
    elif isinstance(t, float):
        # Wouldn't this just work generically?
        int_t = int(t)
        if abs(t - int_t) > 0.:
            raise ValueError('Need an integer GPS time, got %s' % str(t))
        return str(int_t)
    elif isinstance(t, lal.LIGOTimeGPS):
        if t.gpsNanoSeconds == 0:
            return str(t.gpsSeconds)
        else:
            raise ValueError('Need an integer GPS time, got %s' % str(t))
    else:
        err_msg = "Didn't understand input type {}".format(type(t))
        raise ValueError(err_msg)
454035
def convert_to_timestamp(time):
    """"""
    if time == -1:
        return None
    time = int(time*1000)
    hour = time//1000//3600
    minute = (time//1000//60) % 60
    second = (time//1000) % 60
    return str(hour).zfill(2)+":"+str(minute).zfill(2)+":"+str(second).zfill(2)
20274
def utc_iso(self, delimiter='T', places=0):
        
        # "places" used to be the 1st argument, so continue to allow an
        # integer in that spot.  TODO: deprecate this in Skyfield 2.0
        # and remove it in 3.0.
        if isinstance(delimiter, int):
            places = delimiter
            delimiter = 'T'

        if places:
            power_of_ten = 10 ** places
            offset = _half_second / power_of_ten
            year, month, day, hour, minute, second = self._utc_tuple(offset)
            second, fraction = divmod(second, 1.0)
            fraction *= power_of_ten
            format = '%04d-%02d-%02d{0}%02d:%02d:%02d.%0{1}dZ'.format(
                delimiter, places)
            args = (year, month, day, hour, minute, second, fraction)
        else:
            format = '%04d-%02d-%02d{0}%02d:%02d:%02dZ'.format(delimiter)
            args = self._utc_tuple(_half_second)

        if self.shape:
            return [format % tup for tup in zip(*args)]
        else:
            return format % args
621163
def SecondsToZuluTS(secs=None):
	

	if not secs:  secs = int(time.time())

	return(datetime.utcfromtimestamp(secs).strftime("%Y-%m-%dT%H:%M:%SZ"))
941030
def set_timestamp(self, timestamp=str(datetime.datetime.utcfromtimestamp(time.time()))):
        
        self.timestamp = timestamp
567605
def utctimetuple(self):
        ""
        offset = self.utcoffset()
        if offset:
            self -= offset
        y, m, d = self.year, self.month, self.day
        hh, mm, ss = self.hour, self.minute, self.second
        return _build_struct_time(y, m, d, hh, mm, ss, 0)
635483
def convert_rtc(cls, timestamp):
        """"""

        if timestamp & (1  << 31):
            timestamp &= ~(1 << 31)

        delta = datetime.timedelta(seconds=timestamp)
        return cls._Y2KReference + delta
20626
@Override
    public UtcInstant convertToUtc(TaiInstant taiInstant) {
        Data data = dataRef.get();
        long[] mjds = data.dates;
        long[] tais = data.taiSeconds;
        int pos = Arrays.binarySearch(tais, taiInstant.getTaiSeconds());
        pos = (pos >= 0 ? pos : ~pos - 1);
        int taiOffset = (pos >= 0 ? data.offsets[pos] : 10);
        long adjustedTaiSecs = taiInstant.getTaiSeconds() - taiOffset;
        long mjd = Math.floorDiv(adjustedTaiSecs, SECS_PER_DAY) + OFFSET_MJD_TAI;
        long nod = Math.floorMod(adjustedTaiSecs, SECS_PER_DAY) * NANOS_PER_SECOND + taiInstant.getNano();
        long mjdNextRegionStart = (pos + 1 < mjds.length ? mjds[pos + 1] + 1 : Long.MAX_VALUE);
        if (mjd == mjdNextRegionStart) {  // in leap second
            mjd--;
            nod = SECS_PER_DAY * NANOS_PER_SECOND + (nod / NANOS_PER_SECOND) * NANOS_PER_SECOND + nod % NANOS_PER_SECOND;
        }
        return UtcInstant.ofModifiedJulianDay(mjd, nod);
    }