Calculates the next period end.  The calculation is in local time.

@param now the current time in GMT ms since the epoch

@return the time of the next period in GMT ms since the epoch
762525
public static long periodEnd(long now, long period)
  {
    QDate localCalendar = QDate.allocateLocalDate();
    
    long endTime = periodEnd(now, period, localCalendar);
    
    QDate.freeLocalDate(localCalendar);
    
    return endTime;
  }
737326
def elapsed_time(self) -> float:
        
        current_time = datetime.utcnow()
        start = self.start_time or current_time
        end = self.end_time or current_time
        return (end - start).total_seconds()
1367396
public Instant getNextExecutionTimeAfter(Instant now) {
        OffsetTime timeOfDay = OffsetTime.from(TIME_OF_DAY_FORMAT.parse(getTimeOfDay()));

        // The time of the next run is based on the time past midnight UTC relative to the current time
        Instant nextExecTime = now.atOffset(ZoneOffset.UTC).with(timeOfDay).toInstant();

        // If the first execution would have been for earlier today move to the next execution.
        while (nextExecTime.isBefore(now)) {
            nextExecTime = nextExecTime.plus(Duration.ofDays(1));
        }

        return nextExecTime;
    }
1007213
@SuppressWarnings({"unused", "WeakerAccess"})
    public int getTimeElapsed() {
        int currentSession = getCurrentSession();
        if (currentSession == 0) return -1;

        int now = (int) (System.currentTimeMillis() / 1000);
        return now - currentSession;
    }
908140
@Override
    public Date nextExecutionTime(TriggerContext triggerContext) {
        if (triggerContext.lastScheduledExecutionTime() == null) {
            return new Date(System.currentTimeMillis() + this.initialDelay);
        } else if (this.fixedRate) {
            return new Date(triggerContext.lastScheduledExecutionTime().getTime() + this.period);
        }
        return new Date(triggerContext.lastCompletionTime().getTime() + this.period);
    }
902254
public static final long currentTimeMillis ()
    {
        long stamp = System.currentTimeMillis();

        // on WinXP the time sometimes seems to leap into the past; here
        // we do what we can to work around this insanity by simply
        // stopping time rather than allowing it to go into the past
        if (stamp < _lastStamp) {
            // only warn once per time anomaly
            if (stamp > _lastWarning) {
                log.warning("Someone call Einstein! The clock is running backwards",
                            "dt", (stamp - _lastStamp));
                _lastWarning = _lastStamp;
            }
            stamp = _lastStamp;
        }
        _lastStamp = stamp;

        return stamp;
    }
729736
public Calendar getEnd() {
		Calendar cal = Calendar.getInstance();
		cal.setTimeInMillis(end);
		return cal;
	}
334337
protected long calculateSleepTime() {
        Calendar c = new GregorianCalendar();
        int currentHour = c.get(Calendar.HOUR_OF_DAY);
        int currentMin = c.get(Calendar.MINUTE);
        int currentSec = c.get(Calendar.SECOND);
        long stime = SECONDS_FOR_24_HOURS - ((currentHour * 60 + currentMin) * 60 + currentSec) + cleanupHour * 60 * 60;
        if (stime > SECONDS_FOR_24_HOURS) {
            stime = stime - SECONDS_FOR_24_HOURS;
        }
        if (stime < 10) {
            stime = 10;
        }
        stime = stime * 1000; // convert to msec
        return stime;
    }
1134697
public Integer next() {
		for(int i = currentIndex; i < t.size(); i++){
			if(i+timelag>=t.size()){
				return null;
			}
			if((t.get(i) != null) && (t.get(i+timelag) != null)){
				if(overlap){
					currentIndex = i+1;
				}
				else{
					currentIndex = i+timelag;
				}
				return i;
			}
		}
		
		return null;
	}
1310816
def now (time_t = None, slug = False):
  '''
  '''
  if not time_t:
    time_t = time ()
  time_s = strftime (
    DEFAULT_SLUGFORMAT if slug else DEFAULT_TIMEFORMAT,
    gmtime (time_t))
  return (int (time_t), time_s)
875372
def next_time(time, start_time, closing_time)
      @time = time
      unless @start_time
        @start_time = realign(time, start_time)
        @time = @start_time if @time < @start_time
      end

      return nil unless find_acceptable_time_before(closing_time)

      @uses += 1 if @time
      @time
    end
759302
public synchronized long stop() {

		stopTime = System.currentTimeMillis();
		currentTime = stopTime - startTime;
		started = false;

		return currentTime;
	}
727947
public static current_timezone get(nitro_service client) throws Exception
	{
		current_timezone resource = new current_timezone();
		resource.validate("get");
		return ((current_timezone[]) resource.get_resources(client))[0];
	}
1214970
public long getFirstTimeout()
    {
        long lastTimeout = Math.max(System.currentTimeMillis(), start); // d666295

        // If we're already past the end date, then there is no timeout.
        if (lastTimeout > end)
        {
            return -1;
        }

        return getTimeout(lastTimeout, false);
    }
1093622
public long extractAlarm(long now, boolean isTest)
  {
    long lastTime = _now.getAndSet(now);
    
    long nextTime = _nextAlarmTime.get();

    if (now < nextTime) {
      return nextTime;
    }
    
    _nextAlarmTime.set(now + CLOCK_NEXT);
    
    int delta;
    
    delta = (int) (now - lastTime) / CLOCK_INTERVAL;
    
    delta = Math.min(delta, CLOCK_PERIOD);

    Alarm alarm;
    
    int bucket = getBucket(lastTime);
    
    for (int i = 0; i <= delta; i++) {
      // long time = lastTime + i;

      while ((alarm = extractNextAlarm(bucket, now, isTest)) != null) {
        dispatch(alarm, now, isTest);
      }
      
      bucket = (bucket + 1) % CLOCK_PERIOD;
    }
    
    while ((alarm = extractNextCurrentAlarm()) != null) {
      dispatch(alarm, now, isTest);
    }
    
    long next = updateNextAlarmTime(now);
    
    _lastTime = now;
    
    return next;
  }
1369389
protected synchronized void increment(long now) {
		pointer++;
		if (pointer >= timestamps.length) {
			pointer = 0;
		}
		timestamps[pointer] = now;
		max = now;

		int next = pointer + 1;
		if (next >= timestamps.length) {
			next = 0;
		}
		min = timestamps[next];
	}
182423
def get_next_valid_day(self, timestamp):
        
        if self.get_next_future_timerange_valid(timestamp) is None:
            # this day is finish, we check for next period
            (start_time, _) = self.get_start_and_end_time(get_day(timestamp) + 86400)
        else:
            (start_time, _) = self.get_start_and_end_time(timestamp)

        if timestamp <= start_time:
            return get_day(start_time)

        if self.is_time_day_valid(timestamp):
            return get_day(timestamp)

        return None