Function: time-convert

time-convert is a function defined in timefns.c.

Signature

(time-convert TIME FORM)

Documentation

Convert TIME value to a Lisp timestamp of the given FORM.

Truncate the returned value toward minus infinity.

If FORM is a positive integer, return a pair of integers (TICKS . FORM), where TICKS is the number of clock ticks and FORM is the clock frequency in ticks per second.

If FORM is t, return (TICKS . PHZ), where PHZ is a suitable clock frequency in ticks per second.

If FORM is integer, return an integer count of seconds.

If FORM is list, return an integer list (HIGH LOW USEC PSEC), where HIGH has the most significant bits of the seconds, LOW has the least significant 16 bits, and USEC and PSEC are the microsecond and picosecond counts.

If FORM is nil, the behavior depends on current-time-list, but new code should not rely on it.

View in manual

Probably introduced at or before Emacs version 27.1.

Aliases

cperl--time-convert timeclock-seconds-to-time (obsolete since 26.1)

Source Code

// Defined in /usr/src/emacs/src/timefns.c
{
  /* FIXME: Any reason why we don't offer a `float` output format option as
     well, since we accept it as input?  */
  struct lisp_time t;
  enum timeform input_form = decode_lisp_time (time, false, &t, 0);
  if (NILP (form))
    form = current_time_list ? Qlist : Qt;
  if (symbols_with_pos_enabled && SYMBOL_WITH_POS_P (form))
    form = SYMBOL_WITH_POS_SYM (form);
  if (BASE_EQ (form, Qlist))
    return ticks_hz_list4 (t.ticks, t.hz);
  if (BASE_EQ (form, Qinteger))
    return FASTER_TIMEFNS && INTEGERP (time) ? time : lisp_time_seconds (t);
  if (BASE_EQ (form, Qt))
    form = t.hz;
  if (FASTER_TIMEFNS
      && input_form == TIMEFORM_TICKS_HZ && BASE_EQ (form, XCDR (time)))
    return time;
  return Fcons (lisp_time_hz_ticks (t, form), form);
}