Method: GraphQL::Types::ISO8601DateTime.coerce_input
- Defined in:
- lib/graphql/types/iso_8601_date_time.rb
.coerce_input(str_value, _ctx) ⇒ Time
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/graphql/types/iso_8601_date_time.rb', line 54 def self.coerce_input(str_value, _ctx) Time.iso8601(str_value) rescue ArgumentError, TypeError begin dt = Date.iso8601(str_value).to_time # For compatibility, continue accepting dates given without times # But without this, it would zero out given any time part of `str_value` (hours and/or minutes) if dt.iso8601.start_with?(str_value) dt elsif str_value.length == 8 && str_value.match?(/\A\d{8}\Z/) # Allow dates that are missing the "-". eg. "20220404" dt else nil end rescue ArgumentError, TypeError # Invalid input nil end end |