# `time`

> Look up time.interval, time.wait, and time.now, the timers and the clock of an Arc automation.

The `time` module has timers and the clock. Import it with `import time`. `interval` and `wait` are flow functions: a function body cannot call them.

The `period` and `duration` parameters have the type `i64 ns`. They take a literal, such as `500ms` or `10hz`, or a variable of type `i64 ns`. A variable declared as `hold := 5s` has the type `i64 s`, and gives error ARC3002 `expected i64 ns, got i64 s`. Declare it with the type:

```arc
import time

hold i64 ns := 5s

sequence fire {
    time.wait{duration=hold} => next
    1 -> ign_cmd
}

start_cmd == 1 => fire
```

A literal of 0 or less is a compile error, such as `period must be positive, got 0s`. A variable that becomes 0 or less stops the timer and reports an error. On the Core the error is a warning. On a Driver it stops the automation.

## `interval`

Fires again and again, once each `period`.

* [`period`](https://docs.synnaxlabs.com/reference/control/arc/standard-library/time#interval-period)`i64 ns`\* Required

  The time between two fires.

- Input -> optional. Trigger-only: the first input value starts the timer, and later values have no effect. With no input, the timer starts when its stage starts.
- Output -> `u8` value 1 on each fire, with the time of the cycle.
- Runs -> on the first timer cycle after the timer starts, then on a fixed schedule, once each `period`. A late fire does not move the next one. When a cycle takes longer than `period`, the timer fires once and does not make up the fires that it missed. At the top level, it fires when the automation starts.

```arc
import time

time.interval{period=1s} -> heartbeat
```

## `now`

Gives the current time.

* Input -> optional. Trigger-only: each new input value runs it, whatever the value. With no input, it runs once each time its stage starts.
* Output -> the time as a timestamp, type `i64 ns`. Write it to a `timestamp` channel or an `i64` channel. Another channel type, such as `f64`, is an error.
* Function form -> `time.now()`. All calls in the same cycle give the same time.

`now` has no parameters.

```arc
import time

start_cmd == 1 => time.now{} -> start_time
```

## `wait`

Fires once, after `duration`.

* [`duration`](https://docs.synnaxlabs.com/reference/control/arc/standard-library/time#wait-duration)`i64 ns`\* Required

  The time to wait.

- Input -> optional. Trigger-only: the first input value starts the timer, and later values have no effect. With no input, the timer starts when its stage starts.
- Output -> `u8` value 1, once, with the time of the cycle.
- Runs -> when `duration` has passed since the timer started. It counts from zero again each time its stage starts. As a sequence step, the sequence moves on when it fires.

```arc
import time

sequence fire {
    1 -> ign_cmd
    time.wait{duration=2s} => next
    1 -> press_vlv_cmd
}

start_cmd == 1 => fire
```

The timers follow the same rules on the Core and on a Driver. They never fire early. How soon after its deadline a timer fires depends on where the automation runs and its performance level. See [Arc timing](https://docs.synnaxlabs.com/reference/control/arc/timing).
