summaryrefslogtreecommitdiff
path: root/devdocs/elisp/time-calculations.html
blob: 0f11b9e101fd563d2c45af576f87d44b3776d632 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 <h3 class="section">Time Calculations</h3>    <p>These functions perform calendrical computations using time values (see <a href="time-of-day">Time of Day</a>). As with any time value, a value of <code>nil</code> for any of their time-value arguments stands for the current system time, and a single number stands for the number of seconds since the epoch. </p> <dl> <dt id="time-less-p">Function: <strong>time-less-p</strong> <em>t1 t2</em>
</dt> <dd><p>This returns <code>t</code> if time value <var>t1</var> is less than time value <var>t2</var>. The result is <code>nil</code> if either argument is a NaN. </p></dd>
</dl> <dl> <dt id="time-equal-p">Function: <strong>time-equal-p</strong> <em>t1 t2</em>
</dt> <dd><p>This returns <code>t</code> if <var>t1</var> and <var>t2</var> are equal time values. The result is <code>nil</code> if either argument is a NaN. </p></dd>
</dl> <dl> <dt id="time-subtract">Function: <strong>time-subtract</strong> <em>t1 t2</em>
</dt> <dd><p>This returns the time difference <var>t1</var> - <var>t2</var> between two time values, as a Lisp time value. The result is exact and its clock resolution is no worse than the worse of its two arguments’ resolutions. The result is floating-point only if it is infinite or a NaN. If you need the difference in units of elapsed seconds, you can convert it with <code>time-convert</code> or <code>float-time</code>. See <a href="time-conversion">Time Conversion</a>. </p></dd>
</dl> <dl> <dt id="time-add">Function: <strong>time-add</strong> <em>t1 t2</em>
</dt> <dd>
<p>This returns the sum of two time values, using the same conversion rules as <code>time-subtract</code>. One argument should represent a time difference rather than a point in time, as a time value that is often just a single number of elapsed seconds. Here is how to add a number of seconds to a time value: </p> <div class="example"> <pre class="example">(time-add <var>time</var> <var>seconds</var>)
</pre>
</div> </dd>
</dl> <dl> <dt id="time-to-days">Function: <strong>time-to-days</strong> <em>time-value</em>
</dt> <dd><p>This function returns the number of days between the beginning of year 1 and <var>time-value</var>, assuming the default time zone. The operating system limits the range of time and zone values. </p></dd>
</dl> <dl> <dt id="time-to-day-in-year">Function: <strong>time-to-day-in-year</strong> <em>time-value</em>
</dt> <dd><p>This returns the day number within the year corresponding to <var>time-value</var>, assuming the default time zone. The operating system limits the range of time and zone values. </p></dd>
</dl> <dl> <dt id="date-leap-year-p">Function: <strong>date-leap-year-p</strong> <em>year</em>
</dt> <dd><p>This function returns <code>t</code> if <var>year</var> is a leap year. </p></dd>
</dl> <dl> <dt id="date-days-in-month">Function: <strong>date-days-in-month</strong> <em>year month</em>
</dt> <dd><p>Return the number of days in <var>month</var> in <var>year</var>. For instance, February 2020 has 29 days. </p></dd>
</dl> <dl> <dt id="date-ordinal-to-time">Function: <strong>date-ordinal-to-time</strong> <em>year ordinal</em>
</dt> <dd><p>Return the date of <var>ordinal</var> in <var>year</var> as a decoded time structure. For instance, the 120th day in 2004 is April 29th. </p></dd>
</dl><div class="_attribution">
  <p class="_attribution-p">
    Copyright &copy; 1990-1996, 1998-2022 Free Software Foundation, Inc. <br>Licensed under the GNU GPL license.<br>
    <a href="https://www.gnu.org/software/emacs/manual/html_node/elisp/Time-Calculations.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Time-Calculations.html</a>
  </p>
</div>