Ensure that the event has a valid time. Assign a random UUID based on the
  event time.
505760
def validate_event_and_assign_id(event):
  
  event_time = event.get(TIMESTAMP_FIELD)

  if event_time is None:
    event[TIMESTAMP_FIELD] = event_time = epoch_time_to_kronos_time(time.time())
  elif type(event_time) not in (int, long):
    raise InvalidEventTime(event_time)

  # Generate a uuid1-like sequence from the event time with the non-time bytes
  # set to random values.
  _id = uuid_from_kronos_time(event_time)
  event[ID_FIELD] = str(_id)
  return _id, event
34728
def is_valid_timestamp(date, unit='millis'):
    
    assert isinstance(date, int), "Input is not instance of int"

    if unit is 'millis':
        return is_positive(date) and len(str(date)) == 13
    elif unit is 'seconds':
        return is_positive(date) and len(str(date)) == 10
    else:
        raise ValueError('Unknown unit "%s"' % unit)
164501
def create_event_object(self,
                            event_type,
                            code,
                            value,
                            timeval=None):
        """"""
        if not timeval:
            self.update_timeval()
            timeval = self.timeval
        try:
            event_code = self.type_codes[event_type]
        except KeyError:
            raise UnknownEventType(
                "We don't know what kind of event a %s is." % event_type)

        event = struct.pack(EVENT_FORMAT,
                            timeval[0],
                            timeval[1],
                            event_code,
                            code,
                            value)
        return event
1007619
def random_date_between(start_date, end_date):
    """"""
    assert isinstance(start_date, datetime.date)
    delta_secs = int((end_date - start_date).total_seconds())
    delta = datetime.timedelta(seconds=random.randint(0, delta_secs))
    return (start_date + delta)
1353244
def new_uid_validity(cls) -> int:
        
        time_part = int(time.time()) % 4096
        rand_part = random.randint(0, 1048576)
        return (time_part << 20) + rand_part
1148836
function xuid () {
  var now = Date.now()
  var date = encode(now).slice(-7)
  var random = ('000' + encode(counter)).slice(-3) +
    encode(parseInt(randomBytes(6).toString('hex'), 16)).slice(-4)

  if (arguments.length > 0) {
    date = encode(arguments[0]).slice(-7)
  }

  if (arguments.length > 1) {
    random = ('0000000' + encode(arguments[1])).slice(-7)
  }

  if (now !== time && counter > max / 2) {
    counter = parseInt(randomBytes(2).toString('hex'), 16)
  } else {
    counter += 1
  }

  time = now

  return date + random
}
1296143
def check_time(value):
    """"""
    if value is None:
        return None
    if isinstance(value, (time.struct_time, tuple)):
        return value
    if isinstance(value, datetime.datetime):
        return value.timetuple()
    if isinstance(value, datetime.date):
        res = datetime.datetime.utcnow()
        res.replace(year=value.year, month=value.month, day=value.day)
        return res.timetuple()
    if isinstance(value, datetime.time):
        return datetime.datetime.combine(datetime.date.today(),
                                         value).timetuple()
    if isinteger(value):
        # Handle integer as timestamp
        return time.gmtime(value)
    if isinstance(value, basestring):
        if value.lower() == 'now':
            return time.gmtime()
        # TODO: parsinng some popular strings
    raise ValueError("Unsupported time representation:" + repr(value))
290600
def setValidTo(self, value):
        

        valid_from = self.getValidFrom()
        valid_to = DateTime(value)
        interval = self.getExpirationInterval()

        if valid_from and interval:
            valid_to = valid_from + int(interval)
            self.getField("ValidTo").set(self, valid_to)
            logger.debug("Set ValidTo Date to: %r" % valid_to)
        else:
            # just set the value
            self.getField("ValidTo").set(self, valid_to)
112969
def _jitter(self, durations, event, jitter_level, seed=None):
        
        np.random.seed(seed)

        if jitter_level <= 0:
            raise ValueError("The jitter level is less than zero, please select a jitter value greater than 0")

        event_times = durations[event != 0].copy()
        n = event_times.shape[0]

        # Determining extent to jitter event times up or down
        shift = np.random.uniform(low=-1, high=1, size=n) * jitter_level
        event_times += shift
        durations_jitter = event_times.align(durations)[0].fillna(durations)

        # Recursive call if event times are still tied after jitter
        if self._check_for_duplicates(durations=durations_jitter, events=event):
            return self._jitter(durations=durations_jitter, event=event, jitter_level=jitter_level, seed=seed)
        return durations_jitter
557613
def setcreated(self, dt=None):
        
        if dt is None:
            self.created = Token.utc()
        else:
            self.created = dt
1078420
synchronized void insert_data(Any res, TimeVal when, TimeVal needed)
	{
		ring.insert_data(res,when);
		needed_time = needed;
	}
740154
def validate_interval_lock(time, start_time)
      t0 = starting_unit(start_time)
      t1 = time.send(type)
      t0 >= t1 ? t0 - t1 : INTERVALS[type] - t1 + t0
    end
1207534
def set_time(self, time):
        '''
        
        '''
        times = num2date(time[:].squeeze(), time.units)
        self.time = pd.DatetimeIndex(pd.Series(times), tz=self.location.tz)
784803
def set_time(self, time):
        '''
        
        '''
        self.length = int(time*self.sample_rate)
        return self
1279128
function isAccessTimeValid(acceptTime){

	var isValid = true;

	if(!util.isArray(acceptTime)){
		isValid = false;
	}else{
		for(var i=0; i < acceptTime.length; i++){
			if(!(acceptTime[i] instanceof TimeInterval)){
				isValid = false;
				break;
			}
		}
	}

	return isValid;
}
427185
def timestamping_validate(data, schema):
    
    jsonschema.validate(data, schema)
    data['timestamp'] = str(time.time())
734938
def _ValidateClosedTimeRange(time_range):
  """"""
  time_range_start, time_range_end = time_range
  _ValidateTimestamp(time_range_start)
  _ValidateTimestamp(time_range_end)
  if time_range_start > time_range_end:
    raise ValueError("Invalid time-range: %d > %d." %
                     (time_range_start.AsMicrosecondsSinceEpoch(),
                      time_range_end.AsMicrosecondsSinceEpoch()))