Skip to content

struct Athena::Framework::Controller::ValueResolvers::Time
inherits Struct #

Attempts to parse a date(time) string into a ::Time instance.

Optionally allows specifying the format and location to use when parsing the string via the ATHR::Time::Format annotation. If no format is specified, defaults to RFC 3339. Defaults to UTC if no location is specified with the annotation.

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


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

require "athena"

class ExampleController < ATH::Controller
  @[ARTA::Get(path: "/event/{start_time}/{end_time}")]
  def event(
    @[ATHR::Time::Format("%F", location: Time::Location.load("Europe/Berlin"))]
    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

Included modules





View source

#resolve(request : ATH::Request, parameter : ATH::Controller::ParameterMetadata) : ::Time | Nil#

Returns a value resolved from the provided request and parameter if possible, otherwise returns nil if no parameter could be resolved.

View source