Function Repository Resource:

PauseUntil

Source Notebook

Pause evaluation until a given time

Contributed by: Daniele Gregori

ResourceFunction["PauseUntil"][string]

pauses until a given time, specified as String.

ResourceFunction["PauseUntil"][time]

pauses until a given TimeObject.

ResourceFunction["PauseUntil"][date]

pauses until a given DateObject.

Details and Options

While the basic function Pause halts code execution for a certain number of seconds, ResourceFunction["PauseUntil"] halts it until a certain given time occurs.
Possible arguments of ResourceFunction["PauseUntil"] are: TimeObject, DateObject, or String, the last of which is automatically interpreted as either a "Time", "Date", or "DateTime".
ResourceFunction["PauseUntil"] accepts the following options:
TimeZoneAutomaticthe time zone used in all the internal evaluations
"PauseInformation"Falsewhether to Echo the time to be paused
"Periodicity"Noneconsider the input as a periodically repeating time
There is no output for ResourceFunction["PauseUntil"], but the time to be waited for can be echoed by setting the option "PauseInformation" to True.
The values for the option "Periodicity" can be:
Nonepause until only the specified time
npause until the next occurrence of the given time repeated in the future every n days
{n,unit}pause until the next occurrence of the given time repeated in the future every n integer units of time
The unit in the "Periodicity" option value can be one of the following: "Year", "Quarter", "Month", "Week", "Day", "Hour", "Minute", "Second", "Weekday", "Weekend", Monday through Sunday, "EndOfMonth", "BeginningOfMonth" and "BusinessDay".
Normally, entering as input past times leads to failure, unless the option "Periodicity" is set. Then a past date or time is interpreted as periodically repeating every n*unit time in the future and the evaluation pauses until the next occurrence of such periodic date.
A potential application of ResourceFunction["PauseUntil"] is for setting up scheduled tasks running at fixed times, especially on remote servers using the Wolfram Engine.
Other use cases include API rate limiting, external coordination, simulations or demonstrations.

Examples

Basic Examples (2) 

Pause evaluation until a certain time:

In[1]:=
AbsoluteTiming[
 ResourceFunction["PauseUntil"][Now + Quantity[10, "Seconds"]]]
Out[1]=

Pause until a certain date-time:

In[2]:=
ResourceFunction["PauseUntil"]["13 sep 2025 12:00:30"]
In[3]:=
DateString[]
Out[3]=

Scope (3) 

Specify the time zone:

In[4]:=
ResourceFunction["PauseUntil"]["19:01 JST"]
In[5]:=
DateString[TimeZone -> "Asia/Tokyo"]
Out[5]=

Pause until a time specified by TimeObject:

In[6]:=
timeobj = TimeObject[{12, 1, 30}]
Out[6]=
In[7]:=
ResourceFunction["PauseUntil"][timeobj]
In[8]:=
DateString[]
Out[8]=

Pause until a time specified as a DateObject:

In[9]:=
dateobj = DatePlus[Now, {10, "Second"}]
Out[9]=
In[10]:=
ResourceFunction["PauseUntil"][dateobj]
In[11]:=
DateString[]
Out[11]=

Options (4) 

TimeZone (1) 

Specify the TimeZone as an option:

In[12]:=
ResourceFunction["PauseUntil"][TimeObject[{7, 30}], TimeZone -> "America/Los_Angeles"]
In[13]:=
DateString[TimeZone -> "America/Los_Angeles"]
Out[13]=

PauseInformation (1) 

Sometimes it can be useful to get information, through Echo, on the total seconds to be waited:

In[14]:=
ResourceFunction["PauseUntil"]["16:15 pm", "PauseInformation" -> True]
In[15]:=
DateString[]
Out[15]=

Periodicity (2) 

A past date argument is interpreted as a periodic date recurring cyclically in the future.

Pause until the next occurrence of a certain time recurring every day in the future:

In[16]:=
pastdate = DateObject[Yesterday, TimeObject[{12, 4}]]
Out[16]=
In[17]:=
ResourceFunction["PauseUntil"][pastdate, "Periodicity" -> 1]
In[18]:=
DateString[]
Out[18]=

Pause until the next occurrence of a certain time recurring every n units of time:

In[19]:=
ResourceFunction["PauseUntil"][pastdate, "Periodicity" -> {1, "Minute"}]
In[20]:=
DateString[]
Out[20]=

Applications (2) 

PauseUntil[time] can be used to implement scheduled tasks.

For example, collect SunPosition data every 15 minutes from 1 pm to 2 pm:

In[21]:=
sundata = {};
In[22]:=
time = TimeObject["1 pm"]
Out[22]=
In[23]:=
ResourceFunction["PauseUntil"][time]

Do[
  AppendTo[sundata, TimeObject[] -> SunPosition[]];
  ResourceFunction["PauseUntil"][time, "Periodicity" -> {15, "Minute"}], 4];

sundata = Append[sundata, TimeObject[] -> SunPosition[]] // Association
Out[25]=

Plot the collected data points and their fit curve:

In[26]:=
ListPlot[sundata, PlotFit -> "Quadratic", PlotStyle -> PointSize[Large], ImageSize -> Large]
Out[26]=

Properties and Relations (2) 

If the specified TimeObject lies in the latter part of the day, PauseUntil[time] is equivalent to Pause[QuantityMagnitude[DateDifference[Now,time,"Seconds"]]]:

In[27]:=
timeforward = TimeObject[{12, 20}]
Out[27]=
In[28]:=
pauseforward = QuantityMagnitude@DateDifference[Now, timeforward, "Seconds"]
Out[28]=
In[29]:=
Pause[pauseforward]
In[30]:=
DateString[]
Out[30]=

If the specified TimeObject lies in the earlier part of the day PauseUntil[time] is equivalent to 86400-QuantityMagnitude[DateDifference[time,Now,"Seconds"]]:

In[31]:=
timebackword = TimeObject[{12, 10}]
Out[31]=
In[32]:=
pausebackword = 86400 - QuantityMagnitude@
   DateDifference[timebackword, Now, "Seconds"]
Out[32]=
In[33]:=
DatePlus[Now, {pausebackword, "Second"}]
Out[33]=

Possible Issues (4) 

If you use as argument a string to be interpreted, you should also specify the timezone in it (but not necessarily the option TimeZone):

In[34]:=
ResourceFunction["PauseUntil"]["19:11", TimeZone -> "Asia/Tokyo", "PauseInformation" -> True]
Out[34]=
In[35]:=
ResourceFunction["PauseUntil"]["19:11 JST", "PauseInformation" -> True]
In[36]:=
DateString[TimeZone -> "Asia/Tokyo"]
Out[36]=

Some strings cannot be correctly interpreted:

In[37]:=
ResourceFunction["PauseUntil"]["tomorrow night"]
Out[37]=

The specified date object must belong to the future:

In[38]:=
ResourceFunction["PauseUntil"][Yesterday]
Out[38]=

The DateDifference with Now must be larger than about 30 milliseconds:

In[39]:=
dateobj = DatePlus[Now, {0.03, "Second"}];
In[40]:=
ResourceFunction["PauseUntil"][dateobj]
Out[40]=

Publisher

Daniele Gregori

Requirements

Wolfram Language 13.0 (December 2021) or above

Version History

  • 1.0.1 – 16 January 2026
  • 1.0.0 – 15 September 2025

Related Resources

Author Notes

Version 1.0.1

Correction of a bug and simplified implementation for the option "Periodicity".

License Information