SudregEx.Format (sudreg_ex v0.1.0)

Copy Markdown View Source

Display helpers for Sudski registar values.

Identifiers come back from the API as numbers without leading zeros, and timestamps carry no timezone — these helpers render them faithfully.

The padding helpers trust their input (real API values are non-negative numbers); they pad but do not validate or truncate.

Summary

Functions

Zero-pads an MBS to its canonical 9 digits.

Zero-pads an OIB to its canonical 11 digits.

Parses a timezone-less API timestamp (e.g. "2026-06-15T00:00:00") into a NaiveDateTime.

Like parse_timestamp/1, but returns the NaiveDateTime or raises.

Functions

format_mbs(mbs)

@spec format_mbs(integer() | binary()) :: String.t()

Zero-pads an MBS to its canonical 9 digits.

Pad-only: a value already wider than 9 chars is returned unchanged.

iex> SudregEx.Format.format_mbs(80_000_014)
"080000014"

format_oib(oib)

@spec format_oib(integer() | binary()) :: String.t()

Zero-pads an OIB to its canonical 11 digits.

Pad-only: a value already wider than 11 chars is returned unchanged.

iex> SudregEx.Format.format_oib(1)
"00000000001"

parse_timestamp(string)

@spec parse_timestamp(binary()) :: {:ok, NaiveDateTime.t()} | {:error, term()}

Parses a timezone-less API timestamp (e.g. "2026-06-15T00:00:00") into a NaiveDateTime.

The API does not carry a timezone, so a naive value is the honest type — do not assume UTC.

parse_timestamp!(string)

@spec parse_timestamp!(binary()) :: NaiveDateTime.t()

Like parse_timestamp/1, but returns the NaiveDateTime or raises.