Machete.NaiveDateTimeMatcher (Machete v0.3.11)
View SourceDefines a matcher that matches NaiveDateTime values
Summary
Types
Describes the arguments that can be passed to this matcher
Describes an instance of this matcher
Functions
Matches against NaiveDateTime values
Types
@type opts() :: [ precision: 0..6, exactly: NaiveDateTime.t(), roughly: NaiveDateTime.t() | :now, epsilon: integer() | {integer(), integer()}, before: NaiveDateTime.t() | :now, after: NaiveDateTime.t() | :now ]
Describes the arguments that can be passed to this matcher
@opaque t()
Describes an instance of this matcher
Functions
Matches against NaiveDateTime values
Takes the following arguments:
precision
: Requires the matched NaiveDateTime to have the specified microsecond precisionexactly
: Requires the matched NaiveDateTime to be exactly equal to the specified NaiveDateTimeroughly
: Requires the matched NaiveDateTime to be withinepsilon
seconds of the specified NaiveDateTime. The atom:now
can be used to use the current time as the specified NaiveDateTimeepsilon
: The bound(s) to use when determining how close (in microseconds) the matched NaiveDateTime time needs to be toroughly
. 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 NaiveDateTime to be before or equal to the specified NaiveDateTime. The atom:now
can be used to use the current time as the specified NaiveDateTimeafter
: Requires the matched NaiveDateTime to be after or equal to the specified NaiveDateTime. The atom:now
can be used to use the current time as the specified NaiveDateTime
Examples:
iex> assert NaiveDateTime.utc_now() ~> naive_datetime()
true
iex> assert NaiveDateTime.utc_now() ~> naive_datetime(precision: 6)
true
iex> assert ~N[2020-01-01 00:00:00.000000] ~> naive_datetime(exactly: ~N[2020-01-01 00:00:00.000000])
true
iex> assert NaiveDateTime.utc_now() ~> naive_datetime(roughly: :now)
true
iex> assert ~N[2020-01-01 00:00:00.000000] ~> naive_datetime(roughly: ~N[2020-01-01 00:00:05.000000])
true
iex> assert ~N[2020-01-01 00:00:00.000000] ~> naive_datetime(roughly: ~N[2020-01-01 00:00:10.000000], epsilon: 10000000)
true
iex> assert ~N[2020-01-01 00:00:00.000000] ~> naive_datetime(roughly: ~N[2020-01-01 00:00:10.000000], epsilon: {10000000, 5000000})
true
iex> refute ~N[2020-01-01 00:00:00.000000] ~> naive_datetime(roughly: ~N[2020-01-01 00:00:10.000001], epsilon: 10000000)
false
iex> refute ~N[2020-01-01 00:00:00.000000] ~> naive_datetime(roughly: ~N[2020-01-01 00:00:10.000001], epsilon: {10000000, 5000000})
false
iex> assert ~N[2020-01-01 00:00:00.000000] ~> naive_datetime(before: :now)
true
iex> assert ~N[2020-01-01 00:00:00.000000] ~> naive_datetime(before: ~N[3000-01-01 00:00:00.000000])
true
iex> assert ~N[3000-01-01 00:00:00.000000] ~> naive_datetime(after: :now)
true
iex> assert ~N[3000-01-01 00:00:00.000000] ~> naive_datetime(after: ~N[2020-01-01 00:00:00.000000])
true