Return the time in seconds of a step. If a begin and end timestamp,
    return the time in seconds between them after adjusting for what buckets
    they alias to. If t1 and t0 resolve to the same bucket,
17849
def step_size(self, t0=None, t1=None):
    '''
    
    '''
    if t0!=None and t1!=None:
      tb0 = self.to_bucket( t0 )
      tb1 = self.to_bucket( t1, steps=1 ) # NOTE: "end" of second bucket
      if tb0==tb1:
        return self._step
      return self.from_bucket( tb1 ) - self.from_bucket( tb0 )
    return self._step
839222
def elapsed(t0=0.0):
    
    now = time()
    dt = now - t0
    dt_sec = Decimal(str(dt)).quantize(Decimal('.0001'), rounding=ROUND_DOWN)
    if dt_sec <= 1:
        dt_str = str(dt_sec) + ' second'
    else:
        dt_str = str(dt_sec) + ' seconds'
    return now, dt_str
408303
def get_last_an_time(self, utc_time):
        

        # Propagate backwards to ascending node
        dt = np.timedelta64(10, 'm')
        t_old = utc_time
        t_new = t_old - dt
        pos0, vel0 = self.get_position(t_old, normalize=False)
        pos1, vel1 = self.get_position(t_new, normalize=False)
        while not (pos0[2] > 0 and pos1[2] < 0):
            pos0 = pos1
            t_old = t_new
            t_new = t_old - dt
            pos1, vel1 = self.get_position(t_new, normalize=False)

        # Return if z within 1 km of an
        if np.abs(pos0[2]) < 1:
            return t_old
        elif np.abs(pos1[2]) < 1:
            return t_new

        # Bisect to z within 1 km
        while np.abs(pos1[2]) > 1:
            # pos0, vel0 = pos1, vel1
            dt = (t_old - t_new) / 2
            t_mid = t_old - dt
            pos1, vel1 = self.get_position(t_mid, normalize=False)
            if pos1[2] > 0:
                t_old = t_mid
            else:
                t_new = t_mid

        return t_mid
829719
def timestamp(dt):
	
	if dt.tzinfo is None:
		return time.mktime((
			dt.year, dt.month, dt.day,
			dt.hour, dt.minute, dt.second,
			-1, -1, -1)) + dt.microsecond / 1e6
	else:
		return (dt - _EPOCH).total_seconds()
218966
def _check_start_timestamp(self):
        """"""
        if self.descriptor.type in (
                metric_descriptor.MetricDescriptorType.CUMULATIVE_INT64,
                metric_descriptor.MetricDescriptorType.CUMULATIVE_DOUBLE,
                metric_descriptor.MetricDescriptorType.CUMULATIVE_DISTRIBUTION,
        ):
            for ts in self.time_series:
                if ts.start_timestamp is None:
                    raise ValueError("time_series.start_timestamp must exist "
                                     "for cumulative metrics")
390707
function microTimestampAdjusted () {
    // get time in seconds and microseconds
    var time = microtime.nowStruct()
    // zero pad micro seconds
    var micro = ('000000' + time[1]).slice(-6)
    // create mysql format timestamp from seconds and append micro seconds
    return moment.utc(moment.unix(time[0])).format('YYYY-MM-DD HH:mm:ss') + '.' + micro
}
552858
def seconds_to_time(seconds):
    
    minutes, seconds = divmod(int(seconds), 60)
    hours, m = divmod(minutes, 60)
    if hours:
        return _HOURS_OF_ELAPSED % (hours, m, seconds)
    else:
        return _MINUTES_OF_ELAPSED % (m, seconds)
294860
def date_plus_seconds(init_date, seconds, caltype):
    

    end_date = init_date + datetime.timedelta(seconds=seconds)

    if caltype == NOLEAP:
        end_date += get_leapdays(init_date, end_date)
        if end_date.month == 2 and end_date.day == 29:
            end_date += datetime.timedelta(days=1)

    return end_date
334989
function getScale(start, end) {
    // need two fingers...
    if (start.length >= 2 && end.length >= 2) {
      return this.getDistance(end[0], end[1]) / this.getDistance(start[0], start[1]);
    }
    return 1;
  }
1125402
def fast_forward(self, start_dt):
        
        if self.from_stdin:
            # skip lines until start_dt is reached
            return

        else:
            # fast bisection path
            max_mark = self.filesize
            step_size = max_mark

            # check if start_dt is already smaller than first datetime
            self.filehandle.seek(0)
            le = self.next()
            if le.datetime and le.datetime >= start_dt:
                self.filehandle.seek(0)
                return

            le = None
            self.filehandle.seek(0)

            # search for lower bound
            while abs(step_size) > 100:
                step_size = ceil(step_size / 2.)

                self.filehandle.seek(step_size, 1)
                le = self._find_curr_line()
                if not le:
                    break

                if le.datetime >= start_dt:
                    step_size = -abs(step_size)
                else:
                    step_size = abs(step_size)

            if not le:
                return

            # now walk backwards until we found a truly smaller line
            while self.filehandle.tell() >= 2 and (le.datetime is None or
                                                   le.datetime >= start_dt):
                self.filehandle.seek(-2, 1)

                le = self._find_curr_line(prev=True)
1120472
public Double getNearestTime(double timePercentage) {
		//the arrays should be sorted by time so this step is probably not needed
		Double minTime = null;
		Double maxTime = null;
		for (Double t : time) {
			if (minTime == null || t < minTime) {
				minTime = t;
			}
			if (maxTime == null || t > maxTime) {
				maxTime = t;
			}
		}
		Double timeRange = maxTime - minTime;
		Double targetTime = minTime + timePercentage * timeRange;
		Double previousTime = null;
		for (Double t : time) {
			if (previousTime == null || t <= targetTime) {
				previousTime = t;
			} else {
				return previousTime;
			}
		}
		return previousTime;
	}
1308835
function calculateTimeIntervals(timeColumn) {
  // First we find the last time for all of the data (this is an optomisation for the calculateAvailability operation.
  const endTime = timeColumn.values.reduce(function(latest, value, index) {
    const current = finishFromIndex(timeColumn, index);
    if (
      !defined(latest) ||
      (defined(current) && JulianDate.greaterThan(current, latest))
    ) {
      return current;
    }
    return latest;
  }, finishFromIndex(timeColumn, 0));

  return timeColumn.values.map(function(value, index) {
    return calculateAvailability(timeColumn, index, endTime);
  });
}
303361
def step(self, step, total, label='STEP', speed_label='STEPS/S', size=1):
        

        self.lock.acquire()
        try:
            time_diff = time.time() - self.last_step_time

            if self.last_step > step:
                # it restarted
                self.last_step = 0

            made_steps_since_last_call = step - self.last_step
            self.last_step = step

            self.made_steps_since_last_sync += made_steps_since_last_call
            self.made_steps_size_since_last_sync += made_steps_since_last_call * size

            if time_diff >= 1 or step == total:  # only each second or last batch
                self.set_system_info('step', step, True)
                self.set_system_info('steps', total, True)

                steps_per_second = self.made_steps_since_last_sync / time_diff
                samples_per_second = self.made_steps_size_since_last_sync / time_diff
                self.last_step_time = time.time()

                if size:
                    self.report_speed(samples_per_second)

                epochs_per_second = steps_per_second / total  # all batches
                self.set_system_info('epochsPerSecond', epochs_per_second, True)

                current_epochs = self.current_epoch if self.current_epoch else 1
                total_epochs = self.total_epochs if self.total_epochs else 1

                self.made_steps_since_last_sync = 0
                self.made_steps_size_since_last_sync = 0

                eta = 0
                if step < total:
                    # time to end this epoch
                    if steps_per_second != 0:
                        eta = (total - step) / steps_per_second

                # time until all epochs are done
                if total_epochs - current_epochs > 0:
                    if epochs_per_second != 0:
                        eta += (total_epochs - (current_epochs)) / epochs_per_second

                self.git.store_file('aetros/job/times/eta.json', simplejson.dumps(eta))

            if label and self.step_label != label:
                self.set_system_info('stepLabel', label, True)
                self.step_label = label

            if speed_label and self.step_speed_label != speed_label:
                self.set_system_info('stepSpeedLabel', speed_label, True)
                self.step_speed_label = speed_label
        finally:
            self.lock.release()
1172166
function getTime(ts) {
		function pad2(n) {
			return n < 10 ? '0' + n : n;
		}

		function pad3(n) {
			return n < 10 ? '00' + n : (n < 100 ? '0' + n : n);
		}

		return pad2(ts.getHours()) + ':' +
			pad2(ts.getMinutes()) + ':' +
			pad2(ts.getSeconds()) + '.' +
			pad3(ts.getMilliseconds());
	}
1104414
def compare_timestamp(src, dst):
  

  try:
    dst_time = os.path.getmtime(dst)
  except OSError as exc:
    if exc.errno == errno.ENOENT:
      return True  # dst does not exist

  src_time = os.path.getmtime(src)
  return src_time > dst_time
223394
def duration(self):
        
        if self.end_datetime is None or self.start_datetime is None:
            return 0
        return (self.end_datetime - self.start_datetime).total_seconds()
244906
def duration(self):
        
        duration = 0.0
        if len(self.events) > 0:
            first = datetime.fromtimestamp(self.events[0]['timestamp'])
            last = datetime.fromtimestamp(self.events[-1]['timestamp'])
            duration = (last - first).total_seconds()
        return duration