{"record":{"id":"d237b15e4ba7cca6","repo":"instructure/canvas-lms","slug":"time-str-inspect-is-not-an-iso8601-formatted-date","errorCode":null,"errorMessage":"#{time_str.inspect} is not an iso8601 formatted date","messagePattern":"#(.+?) is not an iso8601 formatted date","errorType":"validation","errorClass":"GraphQL::CoercionError","httpStatus":null,"severity":"error","filePath":"app/graphql/types/date_time_type.rb","lineNumber":32,"sourceCode":"# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more\n# details.\n#\n# You should have received a copy of the GNU Affero General Public License along\n# with this program. If not, see <http://www.gnu.org/licenses/>.\n#\n\nclass Types::DateTimeType < Types::BaseScalar\n  graphql_name \"DateTime\"\n  description \"an ISO8601 formatted time string\"\n\n  def self.coerce_input(time_str, _)\n    if time_str.nil?\n      return nil\n    end\n\n    Time.zone.iso8601(time_str)\n  rescue ArgumentError\n    raise GraphQL::CoercionError, \"#{time_str.inspect} is not an iso8601 formatted date\"\n  end\n\n  def self.coerce_result(time, _)\n    time.iso8601\n  end\nend\n","sourceCodeStart":14,"sourceCodeEnd":39,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/app/graphql/types/date_time_type.rb#L14-L39","documentation":"Types::DateTimeType.coerce_input parses incoming date-time strings with Time.zone.iso8601; on ArgumentError it raises GraphQL::CoercionError with \"<value> is not an iso8601 formatted date\". GraphQL surfaces this as a coercion error on the argument.","triggerScenarios":"Passing a non-ISO8601 string to any DateTime-typed argument, e.g. \"01/15/2024\", \"2024-01-15\" (date only usually ok), \"yesterday\", or a localized format; also empty strings that reach coercion.","commonSituations":"UI date pickers emitting locale-formatted dates sent straight to GraphQL; JS Date.toString() output; timezone-less or malformed timestamps; version-dependent strictness of iso8601 parsing.","solutions":["Send a full ISO8601 timestamp, e.g. 2024-01-15T10:30:00Z","Serialize with date.toISOString() on the client before sending","Validate/normalize the string with a parser before the query","Check for stray empty strings — omit the argument when no date is chosen"],"exampleFix":"// before\nuntil: \"01/15/2024\"\n// after\nuntil: new Date(\"2024-01-15T10:30:00Z\").toISOString()","handlingStrategy":"validation","validationCode":"function isIso8601(s) { return !isNaN(Date.parse(s)) && /^\\d{4}-\\d{2}-\\d{2}T/.test(s) }\nif (!isIso8601(rawDate)) normalizeOrOmit(rawDate)","typeGuard":"function isValidDateTime(v) { return v == null || (typeof v === 'string' && /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(:\\d{2})?(\\.\\d+)?(Z|[+-]\\d{2}:?\\d{2})?$/.test(v)) }","tryCatchPattern":"try { await query(VAR) } catch (e) { if (e.message.includes('is not an iso8601 formatted date')) { refetchWithToISOString() } }","preventionTips":["Always serialize dates with Date.prototype.toISOString()","Never pass locale-formatted picker strings directly","Omit the argument instead of sending an empty string","Unit-test date inputs against the GraphQL schema"],"tags":["graphql","date-time","coercion"],"backgroundTag":"invalid-date-format","analyzedSha":"1c9f0bb8013ed69c4f2efe11fd483025469b7e6c","analyzedAt":"2026-09-15T20:33:18.891Z","contentChangedAt":"2026-09-15T20:33:18.891Z","schemaVersion":2},"datasetVersion":"2026-09-23T02:17:17.105Z"}