class Athena::Framework::TimeConverter
inherits Athena::Framework::ParamConverter
#
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 ATH::Exceptions::BadRequest
if the date(time) string could not be parsed.
Tip
The format can be anything supported via Time::Format.
require "athena"
class ExampleController < ATH::Controller
@[ARTA::Get(path: "/event/{start_time}/{end_time}")]
@[ATHA::ParamConverter("start_time", converter: ATH::TimeConverter, format: "%F", location: Time::Location.load("Europe/Berlin"))]
@[ATHA::ParamConverter("end_time", converter: ATH::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
end
end
ATH.run
# GET /event/2020-04-07/2020-04-08T12:34:56Z