# `Machete.TimeMatcher`
[🔗](https://github.com/mtrudel/machete/blob/main/lib/machete/matchers/time_matcher.ex#L1)

Defines a matcher that matches Time values

# `opts`

```elixir
@type opts() :: [
  precision: 0..6,
  exactly: Time.t(),
  roughly: Time.t() | :now,
  epsilon: integer() | {integer(), integer()},
  before: Time.t() | :now,
  after: Time.t() | :now
]
```

Describes the arguments that can be passed to this matcher

# `t`

```elixir
@opaque t()
```

Describes an instance of this matcher

# `time`

```elixir
@spec time(opts()) :: t()
```

Matches against Time values

Takes the following arguments:

* `precision`: Requires the matched Time to have the specified microsecond precision
* `exactly`: Requires the matched Time to be exactly equal to the specified Time
* `roughly`: Requires the matched Time to be within `epsilon` seconds of the specified Time. The
  atom `:now` can be used to use the current time as the specified Time
* `epsilon`: The bound(s) to use when determining how close (in microseconds) the matched
  Time time needs to be to `roughly`. Can be specified as a single integer that is used for both lower
  and upper bounds, or a tuple consisting of distinct lower and upper bounds. If not specified,
  defaults to 10_000_000 microseconds (10 seconds)
* `before`: Requires the matched Time to be before or equal to the specified Time. The atom
  `:now` can be used to use the current time as the specified Time
* `after`: Requires the matched Time to be after or equal to the specified Time. The atom `:now`
  can be used to use the current time as the specified Time

Examples:

    iex> assert Time.utc_now() ~> time()
    true

    iex> assert Time.utc_now() ~> time(precision: 6)
    true

    iex> assert ~T[00:00:00.000000] ~> time(exactly: ~T[00:00:00.000000])
    true

    iex> assert Time.utc_now() ~> time(roughly: :now)
    true

    iex> assert ~T[00:00:00.000000] ~> time(roughly: ~T[00:00:05.000000])
    true

    iex> assert ~T[00:00:00.000000] ~> time(roughly: ~T[00:00:10.000000], epsilon: 10000000)
    true

    iex> assert ~T[00:00:00.000000] ~> time(roughly: ~T[00:00:10.000000], epsilon: {10000000, 5000000})
    true

    iex> refute ~T[00:00:00.000000] ~> time(roughly: ~T[00:00:10.000001], epsilon: 10000000)
    false

    iex> refute ~T[00:00:00.000000] ~> time(roughly: ~T[00:00:10.000001], epsilon: {10000000, 5000000})
    false

    iex> assert ~T[00:00:00.000000] ~> time(before: :now)
    true

    iex> assert ~T[00:00:00.000000] ~> time(before: ~T[00:00:01.000000])
    true

    iex> assert ~T[23:59:59.999999] ~> time(after: :now)
    true

    iex> assert ~T[00:00:01.000000] ~> time(after: ~T[00:00:00.000000])
    true

---

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