Skip to main content

README.md

# fixdate

[![Package Version](https://img.shields.io/hexpm/v/fixdate)](https://hex.pm/packages/fixdate)
[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://fixdate.hexdocs.pm/)

Format and parse HTTP-date timestamps, the date format used in HTTP headers
such as `Date`, `Last-Modified`, and `Expires` ([RFC 9110 5.6.7](https://datatracker.ietf.org/doc/html/rfc9110#section-5.6.7)).

```sh
gleam add fixdate
```

```gleam
import fixdate
import gleam/time/calendar
import gleam/time/timestamp

pub fn main() -> Nil {
  let date = timestamp.from_unix_seconds(1_782_697_748)
  echo fixdate.to_string(date)
  // -> "Mon, 29 Jun 2026 01:49:08 GMT"

  // Parse an HTTP date back into a timestamp.
  let assert Ok(ts) = fixdate.parse("Mon, 29 Jun 2026 01:49:08 GMT")
  echo timestamp.to_rfc3339(ts, calendar.utc_offset)
  // -> "2026-06-29T01:49:08Z"

  Nil
}
```