Machete.ISO8601DateTimeMatcher (machete v0.2.0)
Defines a matcher that matches ISO8601 formatted strings
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 ISO8601 formatted strings
Link to this section Types
Link to this type
opts()
@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
Link to this function
iso8601_datetime(opts \\ [])
Matches against ISO8601 formatted strings
Takes the following arguments:
precision
: Requires the matched ISO8601 string to have the specified microsecond precisiontime_zone
: Requires the matched ISO8601 string to have the specified time zone. The atom:utc
can be used to specify the "Etc/UTC" time zoneexactly
: Requires the matched ISO8601 string to be exactly equal to the specified DateTimeroughly
: Requires the matched ISO8601 string to be within +/- 10 seconds of the specified DateTime. This values must be specified as a DateTime. The atom:now
can be used to use the current time as the specified DateTimebefore
: Requires the matched ISO8601 string to be before or equal to the specified DateTime. This values must be specified as a DateTime. The atom:now
can be used to use the current time as the specified DateTimeafter
: Requires the matched ISO8601 string to be after or equal to the specified DateTime. This values must be specified as a DateTime. The atom:now
can be used to use the current time as the specified DateTime
Examples:
iex> assert "2020-01-01T00:00:00.000000Z" ~> iso8601_datetime()
true
iex> assert "2020-01-01T00:00:00.000000Z" ~> iso8601_datetime(precision: 6)
true
iex> assert "2020-01-01T00:00:00.000000Z" ~> iso8601_datetime(time_zone: :utc)
true
iex> assert "2020-01-01T00:00:00.000000Z" ~> iso8601_datetime(time_zone: "Etc/UTC")
true
iex> assert "2020-01-01 00:00:00.000000Z" ~> iso8601_datetime(exactly: ~U[2020-01-01 00:00:00.000000Z])
true
iex> assert DateTime.utc_now() |> DateTime.to_iso8601() ~> iso8601_datetime(roughly: :now)
true
iex> assert "2020-01-01T00:00:00.000000Z" ~> iso8601_datetime(roughly: ~U[2020-01-01 00:00:05.000000Z])
true
iex> assert "2020-01-01T00:00:00.000000Z" ~> iso8601_datetime(before: :now)
true
iex> assert "2020-01-01T00:00:00.000000Z" ~> iso8601_datetime(before: ~U[3000-01-01 00:00:00.000000Z])
true
iex> assert "3000-01-01T00:00:00.000000Z" ~> iso8601_datetime(after: :now)
true
iex> assert "3000-01-01T00:00:00.000000Z" ~> iso8601_datetime(after: ~U[2020-01-01 00:00:00.000000Z])
true