Versioning.Adapter.Date (Versioning v0.4.1) View Source

A versioning adapter for date-based versions.

Under the hood, this adapter uses the Date module. For details on the rules that are used for parsing and comparison, please see the Date module.

Example

defmodule MyApp.Versioning do
  use Versioning.Schema, adapter: Versioning.Adapter.Date

  version "2019-01-01" do
    type "Post" do
      change(MyApp.Change)
    end
  end
end

Link to this section Summary

Functions

Compares date based versions using ISO8601 formatting.

Parses date based versions using ISO8601 formatting.

Link to this section Functions

Link to this function

compare(version1, version2)

View Source

Specs

compare(binary() | Date.t(), binary() | Date.t()) :: :gt | :lt | :eq | :error

Compares date based versions using ISO8601 formatting.

Returns :gt if the first verison is greater than the second, and :lt for vice-versa. If the two versions are equal, :eq is returned. Returns :error if the version cannot be parsed.

Example

  iex> Versioning.Adapters.Date.compare("2019-01-01", "2018-12-31")
  :gt
  iex> Versioning.Adapters.Date.compare("2018-12-31", "2019-01-01")
  :lt
  iex> Versioning.Adapters.Date.compare("2019-01-01", "2019-01-01")
  :eq
  iex> Versioning.Adapters.Date.compare("foo", "bar")
  :error

Specs

parse(binary() | Date.t()) :: :error | {:ok, Date.t()}

Parses date based versions using ISO8601 formatting.

Example

  iex> Versioning.Adapters.Date.parse("2019-01-01")
  {:ok, ~D[2019-01-01]}
  iex> Versioning.Adapters.Date.parse("foo")
  :error