View Source Machete.DateTimeMatcher (Machete v0.3.1)

Defines a matcher that matches DateTime values

Summary

Types

Describes the arguments that can be passed to this matcher

t()

Describes an instance of this matcher

Functions

Matches against DateTime values

Types

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

Describes the arguments that can be passed to this matcher

@opaque t()

Describes an instance of this matcher

Functions

@spec datetime(opts()) :: t()

Matches against DateTime values

Takes the following arguments:

  • precision: Requires the matched DateTime to have the specified microsecond precision
  • time_zone: Requires the matched DateTime to have the specified time zone. The atom :utc can be used to specify the "Etc/UTC" time zone
  • exactly: Requires the matched DateTime to be exactly equal to the specified DateTime
  • roughly: Requires the matched DateTime to be within +/- 10 seconds of the specified DateTime. The atom :now can be used to use the current time as the specified DateTime
  • before: Requires the matched DateTime to be before or equal to the specified DateTime. The atom :now can be used to use the current time as the specified DateTime
  • after: Requires the matched DateTime to be after or equal to the specified DateTime. The atom :now can be used to use the current time as the specified DateTime

Examples:

iex> assert DateTime.utc_now() ~> datetime()
true

iex> assert DateTime.utc_now() ~> datetime(precision: 6)
true

iex> assert DateTime.utc_now() ~> datetime(time_zone: :utc)
true

iex> assert DateTime.utc_now() ~> datetime(time_zone: "Etc/UTC")
true

iex> assert ~U[2020-01-01 00:00:00.000000Z] ~> datetime(exactly: ~U[2020-01-01 00:00:00.000000Z])
true

iex> assert DateTime.utc_now() ~> datetime(roughly: :now)
true

iex> assert ~U[2020-01-01 00:00:00.000000Z] ~> datetime(roughly: ~U[2020-01-01 00:00:05.000000Z])
true

iex> assert ~U[2020-01-01 00:00:00.000000Z] ~> datetime(before: :now)
true

iex> assert ~U[2020-01-01 00:00:00.000000Z] ~> datetime(before: ~U[3000-01-01 00:00:00.000000Z])
true

iex> assert ~U[3000-01-01 00:00:00.000000Z] ~> datetime(after: :now)
true

iex> assert ~U[3000-01-01 00:00:00.000000Z] ~> datetime(after: ~U[2020-01-01 00:00:00.000000Z])
true