Skip to content

struct Athena::Routing::TimeConverter
inherits Athena::Routing::ParamConverterInterface #

Converts a date(time) string into a Time instance.

Optionally allows specifying the format and location to use when parsing the string. If no format is specified, defaults to Time.rfc_3339. Defaults to UTC if no location is specified with the format.

Raises an ART::Exceptions::BadRequest if the date(time) string could not be parsed.


The format can be anything supported via Time::Format.

require "athena"

class ExampleController < ART::Controller
  @[ARTA::Get(path: "/event/:start_time/:end_time")]
  @[ARTA::ParamConverter("start_time", converter: ART::TimeConverter, format: "%F", location: Time::Location.load("Europe/Berlin"))]
  @[ARTA::ParamConverter("end_time", converter: ART::TimeConverter)]
  def event(start_time : Time, end_time : Time) : Nil
    start_time # => 2020-04-07 00:00:00.0 +02:00 Europe/Berlin
    end_time   # => 2020-04-08 12:34:56.0 UTC

# GET /event/2020-04-07/2020-04-08T12:34:56Z


#apply(request : ART::Request, configuration : Configuration) : Nil #

Applies the conversion logic based on the provided request and configuration.

Most commonly this involves setting/overriding a value stored in the request's ART::Request#attributes.

View source