View Source Machete.ISO8601DateTimeMatcher (Machete v0.3.1)

Defines a matcher that matches ISO8601 formatted strings

Summary

Types

Describes the arguments that can be passed to this matcher

t()

Describes an instance of this matcher

Functions

Matches against ISO8601 formatted strings

Types

@type opts() :: [
  precision: 0..6,
  time_zone: Calendar.time_zone() | :utc,
  offset_required: boolean(),
  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

Link to this function

iso8601_datetime(opts \\ [])

View Source
@spec iso8601_datetime(opts()) :: t()

Matches against ISO8601 formatted strings

Takes the following arguments:

  • precision: Requires the matched ISO8601 string to have the specified microsecond precision
  • time_zone: Requires the matched ISO8601 string to have the specified time zone. The atom :utc can be used to specify the "Etc/UTC" time zone
  • offset_required: Requires the matched ISO8601 string to have a timezone. Defaults to true
  • exactly: Requires the matched ISO8601 string to be exactly equal to the specified DateTime
  • roughly: 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 DateTime
  • before: 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 DateTime
  • after: 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 NaiveDateTime.utc_now() |> NaiveDateTime.to_iso8601() ~> iso8601_datetime(roughly: :now, offset_required: false)
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