2018-12-05 23:21:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
module Types
|
|
|
|
class TimeType < BaseScalar
|
|
|
|
graphql_name 'Time'
|
2021-04-17 20:07:23 +05:30
|
|
|
description <<~DESC
|
|
|
|
Time represented in ISO 8601.
|
|
|
|
|
|
|
|
For example: "2021-03-09T14:58:50+00:00".
|
|
|
|
|
|
|
|
See `https://www.iso.org/iso-8601-date-and-time-format.html`.
|
|
|
|
DESC
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
def self.coerce_input(value, ctx)
|
|
|
|
Time.parse(value)
|
2020-10-24 23:57:45 +05:30
|
|
|
rescue ArgumentError, TypeError => e
|
|
|
|
raise GraphQL::CoercionError, e.message
|
2018-11-08 19:23:39 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def self.coerce_result(value, ctx)
|
|
|
|
value.iso8601
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|