View Source Machete.DateTimeMatcher (Machete v0.2.3)
Defines a matcher that matches DateTime values
Link to this section Summary
Types
Describes the arguments that can be passed to this matcher
Describes an instance of this matcher
Functions
Matches against DateTime values
Link to this section 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
Link to this section Functions
Matches against DateTime values
Takes the following arguments:
precision
: Requires the matched DateTime to have the specified microsecond precisiontime_zone
: Requires the matched DateTime to have the specified time zone. The atom:utc
can be used to specify the "Etc/UTC" time zoneexactly
: Requires the matched DateTime to be exactly equal to the specified DateTimeroughly
: 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 DateTimebefore
: 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 DateTimeafter
: 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