View Source Machete.TimeMatcher (Machete v0.2.3)

Defines a matcher that matches Time values

Link to this section Summary

Types

Describes the arguments that can be passed to this matcher

t()

Describes an instance of this matcher

Functions

Matches against Time values

Link to this section Types

@type opts() :: [
  precision: 0..6,
  exactly: Time.t(),
  roughly: Time.t() | :now,
  before: Time.t() | :now,
  after: Time.t() | :now
]

Describes the arguments that can be passed to this matcher

@opaque t()

Describes an instance of this matcher

Link to this section Functions

@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 +/- 10 seconds of the specified Time. The atom :now can be used to use the current time as the specified Time
  • 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(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