Machete.TimeMatcher (Machete v0.3.11)
View SourceDefines a matcher that matches Time values
Summary
Types
Describes the arguments that can be passed to this matcher
Describes an instance of this matcher
Functions
Matches against Time values
Types
Functions
Matches against Time values
Takes the following arguments:
precision
: Requires the matched Time to have the specified microsecond precisionexactly
: Requires the matched Time to be exactly equal to the specified Timeroughly
: Requires the matched Time to be withinepsilon
seconds of the specified Time. The atom:now
can be used to use the current time as the specified Timeepsilon
: The bound(s) to use when determining how close (in microseconds) the matched Time 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 Time to be before or equal to the specified Time. The atom:now
can be used to use the current time as the specified Timeafter
: 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(roughly: ~T[00:00:10.000000], epsilon: 10000000)
true
iex> assert ~T[00:00:00.000000] ~> time(roughly: ~T[00:00:10.000000], epsilon: {10000000, 5000000})
true
iex> refute ~T[00:00:00.000000] ~> time(roughly: ~T[00:00:10.000001], epsilon: 10000000)
false
iex> refute ~T[00:00:00.000000] ~> time(roughly: ~T[00:00:10.000001], epsilon: {10000000, 5000000})
false
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