Valid a TOTP code.

        :param code: A number that is less than 6 characters.
        :param period: A period that a TOTP code is valid in seconds
        :param timestamp: Validate TOTP at this given timestamp
428323
def valid_totp(self, code, period=30, timestamp=None):
        
        if not valid_code(code):
            return False
        return compare_digest(
            bytes(self.totp(period, timestamp)),
            bytes(int(code))
        )
418522
function Timestamp(message, code_id) {
    Error.call(this);
    this.message = message || "timestamp out of date";
    this.code_id = code_id || null;
    this.statusCode = 409;
}
1228975
def make_us_postal_code(s, allowed_lengths=(), allowed_digits=()):
    
    allowed_lengths = allowed_lengths or tuple(N if N < 6 else N + 1 for N in allowed_digits)
    allowed_lengths = allowed_lengths or (2, 3, 5, 10)
    ints = int_pair(s)
    z = str(ints[0]) if ints[0] else ''
    z4 = '-' + str(ints[1]) if ints[1] else ''
    if len(z) == 4:
        z = '0' + z
    if len(z + z4) in allowed_lengths:
        return z + z4
    elif len(z) in (min(l, 5) for l in allowed_lengths):
        return z
    return ''
1173479
def get_min_from_t(self, timestamp):
        
        if self.is_time_valid(timestamp):
            return timestamp
        t_day_epoch = get_day(timestamp)
        tr_mins = self.get_min_sec_from_morning()
        return t_day_epoch + tr_mins
711911
def validity_duration(self):
        
        if self._proto.HasField('expireMillis'):
            return timedelta(milliseconds=self._proto.expireMillis)
        return None
579784
def QA_util_stamp2datetime(timestamp):
    
    try:
        return datetime.datetime.fromtimestamp(timestamp)
    except Exception as e:
        # it won't work ??
        try:
            return datetime.datetime.fromtimestamp(timestamp / 1000)
        except:
            try:
                return datetime.datetime.fromtimestamp(timestamp / 1000000)
            except:
                return datetime.datetime.fromtimestamp(timestamp / 1000000000)
387951
function validTimestamp(timestamp) {
    // ^year-month-day(Thour:min:secms?timezone)?$
    var year = /((?:[1-9][0-9]*)?[0-9]{4})/,
        month = /(1[0-2]|0[1-9])/,
        day = /(3[01]|0[1-9]|[12][0-9])/,
        hour = /(2[0-3]|[01][0-9])/,
        minute = /([0-5][0-9])/,
        second = /([0-5][0-9])/,
        ms = /(\.[0-9]+)/,
        timezone = /(Z|[+\-](?:2[0-3]|[01][0-9]):[0-5][0-9])/,
        date = [year.source, month.source, day.source].join('-'),
        time = [hour.source, minute.source, second.source].join(':'),
        timestampRegex,
        result;

    timestampRegex = new RegExp(
        '^' + date + '(T' + time + ms.source + '?' + timezone.source + ')?$'
    );

    result = timestampRegex.exec(timestamp);

    return result !== null;
}
848235
private void validateTimestampProtocol(String protocolString, String timestampFormat, String shape2) {
        if (!StringUtils.isNullOrEmpty(timestampFormat) && isNonJsonProtocol(protocolString)) {
            throw new IllegalArgumentException(String.format(
                "Shape %s has timestamp format provided. Timestamp format for requests is not supported for xml, query or ec2 "
                + "protocol",
                shape2));

        }
    }
463883
def expireat(self, key, timestamp):
        
        if isinstance(timestamp, float):
            return self.pexpireat(key, int(timestamp * 1000))
        if not isinstance(timestamp, int):
            raise TypeError("timestamp argument must be int, not {!r}"
                            .format(timestamp))
        fut = self.execute(b'EXPIREAT', key, timestamp)
        return wait_convert(fut, bool)
1233178
def period(self, value: float):
        
        if value < 0:
            raise ValueError("Period must be greater or equal than zero.")
        self._period = timedelta(seconds=value)
633831
def datetime2utsec(t: Union[str, datetime.date, datetime.datetime, np.datetime64]) -> float:
    
    if isinstance(t, (tuple, list, np.ndarray)):
        return np.asarray([datetime2utsec(T) for T in t])
    elif isinstance(t, datetime.date) and not isinstance(t, datetime.datetime):
        return 0.
    elif isinstance(t, np.datetime64):
        t = t.astype(datetime.datetime)
    elif isinstance(t, str):
        t = parse(t)

    return datetime.timedelta.total_seconds(t - datetime.datetime.combine(t.date(),
                                                                          datetime.datetime.min.time()))
782472
public void setCode(String timecode) throws Timecode.TimecodeException {
    clear();
    setHours(getToken(timecode, 0));
    setMinutes(getToken(timecode, 1));
    setSeconds(getToken(timecode, 2));
    setFrames(getToken(timecode, 3));
    if (useSamples()) {
      try {
        setSamples(getToken(timecode, 4));
        // If we got here, we're parsing a AES31-formatted string... Set our
        // frames per sec to 30 instead of 75
        setFramesPerSecond(30);
      } catch (Timecode.TimecodeException ignored) {
      } // If this fails, it just means the code didn't have samples appended
    }
    // fix badly formed values : 00:00:60:00 will become 00:01:00:00, etc.
    normalize();
  }
241665
def validate(self):
        
        for timeperiod, child in self.root.children.items():
            child.validate()
        self.validation_timestamp = datetime.utcnow()
1055542
public static String validate(String code) {
        try {
            toCurrency(code);
        } catch (IllegalArgumentException ex) {
            throw new InvalidValueException(code, "currency");
        }
        return code;
    }
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)
466857
def certify_time(value, required=True):
    
    if certify_required(
        value=value,
        required=required,
    ):
        return

    if not isinstance(value, time):
        raise CertifierTypeError(
            message="expected timestamp (time), but value is of type {cls!r}".format(
                cls=value.__class__.__name__),
            value=value,
            required=required,
        )
1249157
def _is_valid_duration(self, inpt, metadata):
        """"""
        # NEED TO ADD CHECKS FOR OTHER METADATA, LIKE MINIMUM, MAXIMUM, ETC.
        from dlkit.abstract_osid.calendaring.primitives import Duration as abc_duration
        if isinstance(inpt, abc_duration):
            return True
        else:
            return False