# `NervesTime.RealTimeClock`
[🔗](https://github.com/nerves-time/nerves_time/blob/v0.4.11/lib/nerves_time/real_time_clock.ex#L6)

Behaviour for real-time clocks implementations.

# `state`

```elixir
@type state() :: any()
```

Internal state of the hardware clock

# `get_time`

```elixir
@callback get_time(state()) :: {:ok, NaiveDateTime.t(), state()} | {:unset, state()}
```

Get the time from the clock

This is called after `init/1` returns successfully to see if the
system clock should be updated.

If the time isn't set, the implementation should return `:unset`.
`set_time/2` will be called when the time is known.

# `init`

```elixir
@callback init(args :: any()) :: {:ok, state()} | {:error, reason :: any()}
```

Initialize the clock

This is called when `nerves_time` starts. If it fails, `nerves_time`
won't call any of the other functions.

# `set_time`

```elixir
@callback set_time(state(), NaiveDateTime.t()) :: state()
```

Set the clock

This is called if `nerves_time` determines that the implementation is out
of sync with the true time and at regular intervals (usually 11 minutes) as
updates come in from NTP.

If the time can't be set, the implementation can either wait to be called
the next time or take some other action.

# `terminate`

```elixir
@callback terminate(state()) :: :ok
```

Clean up the clock state

This is called when `nerves_time` terminates. It's not guaranteed to be
called, but if it is, it should clean up or do any final operations on
the RTC.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
