View Source Machete.DateMatcher (Machete v0.3.0)

Defines a matcher that matches Date values

Summary

Types

Describes the arguments that can be passed to this matcher

t()

Describes an instance of this matcher

Functions

Matches against Date values

Types

@type opts() :: [
  exactly: Date.t() | :today,
  roughly: Date.t() | :today,
  before: Date.t() | :today,
  after: Date.t() | :today
]

Describes the arguments that can be passed to this matcher

@opaque t()

Describes an instance of this matcher

Functions

@spec date(opts()) :: t()

Matches against Date values

Takes the following arguments:

  • exactly: Requires the matched Date to be exactly equal to the specified Date. The atom :today can be used to use today as the specified Date
  • roughly: Requires the matched Date to be within +/- 1 day of the specified Date. The atom :today can be used to use today as the specified Date
  • before: Requires the matched Date to be before or equal to the specified Date. The atom :today can be used to use today as the specified Date
  • after: Requires the matched Date to be after or equal to the specified Date. The atom :today can be used to use today as the specified Date

Examples:

iex> assert Date.utc_today() ~> date()
true

iex> assert Date.utc_today() ~> date(exactly: :today)
true

iex> assert ~D[2020-01-01] ~> date(exactly: ~D[2020-01-01])
true

iex> assert Date.utc_today() ~> date(roughly: :today)
true

iex> assert ~D[2020-01-01] ~> date(roughly: ~D[2020-01-02])
true

iex> assert ~D[2020-01-01] ~> date(before: :today)
true

iex> assert ~D[2020-01-01] ~> date(before: ~D[3000-01-01])
true

iex> assert ~D[3000-01-01] ~> date(after: :today)
true

iex> assert ~D[3000-01-01] ~> date(after: ~D[2020-01-01])
true