{"record":{"id":"2487d487d774088c","repo":"TheAlgorithms/JavaScript","slug":"argument-is-not-a-string","errorCode":null,"errorMessage":"Argument is not a string.","messagePattern":"Argument is not a string\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"Conversions/RailwayTimeConversion.js","lineNumber":21,"sourceCode":"    because we know that if the time is in 'AM' value it means they only want\n    some changes on hours and minutes and if the time in 'PM' it means the only\n    want some changes in hour value.\n\n    Input Format -> 07:05:45PM\n    Output Format -> 19:05:45\n\n    Problem & Explanation Source : https://www.mathsisfun.com/time.html\n*/\n\n/**\n * RailwayTimeConversion method converts normalized time string to Railway time string.\n * @param {String} timeString Normalized time string.\n * @returns {String} Railway time string.\n */\nconst RailwayTimeConversion = (timeString) => {\n  // firstly, check that input is a string or not.\n  if (typeof timeString !== 'string') {\n    throw new TypeError('Argument is not a string.')\n  }\n  // split the string by ':' character.\n  const [hour, minute, secondWithShift] = timeString.split(':')\n  // split second and shift value.\n  const [second, shift] = [\n    secondWithShift.substring(0, 2),\n    secondWithShift.substring(2)\n  ]\n  // convert shifted time to not-shift time(Railway time) by using the above explanation.\n  if (shift === 'PM') {\n    if (parseInt(hour) === 12) {\n      return `${hour}:${minute}:${second}`\n    } else {\n      return `${parseInt(hour) + 12}:${minute}:${second}`\n    }\n  } else {\n    if (parseInt(hour) === 12) {\n      return `00:${minute}:${second}`","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/TheAlgorithms/JavaScript/blob/5c39e87a9a31f279c60f830ad74a845e4788a517/Conversions/RailwayTimeConversion.js#L3-L39","documentation":"Thrown by RailwayTimeConversion when timeString is not of type 'string'. It is the first and only type guard; once it passes the function immediately calls timeString.split(':') and .substring, which would otherwise throw a less clear error. TypeError.","triggerScenarios":"Calling RailwayTimeConversion(70545), RailwayTimeConversion(null), or RailwayTimeConversion(['07','05','45']). After this guard, malformed-but-string inputs like '7:5' will not throw here — they will produce odd output instead, so the guard only covers the type.","commonSituations":"Passing a Date object instead of a formatted string; numeric time from a picker; undefined from an optional field; an array from a split done upstream.","solutions":["Format the input as a string in 'hh:mm:ssAM|PM' shape before calling (e.g. '07:05:45PM').","If you have a Date, format it yourself rather than passing the Date object.","Type-check with typeof timeString === 'string' upstream."],"exampleFix":"// before\nRailwayTimeConversion(someDateObject)\n// after\nconst d = someDateObject\nconst fmt = `${String(d.getHours() % 12 || 12).padStart(2, '0')}:${String(d.getMinutes()).padStart(2, '0')}:${String(d.getSeconds()).padStart(2, '0')}${d.getHours() >= 12 ? 'PM' : 'AM'}`\nRailwayTimeConversion(fmt)","handlingStrategy":"type-guard","validationCode":"if (typeof timeString !== 'string') {\n  throw new TypeError('timeString must be a string like 07:05:45PM')\n}\nRailwayTimeConversion(timeString)","typeGuard":"const isString = (x) => typeof x === 'string'","tryCatchPattern":"try {\n  RailwayTimeConversion(timeString)\n} catch (e) {\n  if (e instanceof TypeError && /not a string/.test(e.message)) {\n    return RailwayTimeConversion(String(timeString))\n  }\n  throw e\n}","preventionTips":["Format Date objects into 'hh:mm:ssAM|PM' yourself instead of passing them.","Type-check at the boundary where input is least controlled.","Validate the shape (three colon-separated parts, AM/PM suffix) before calling."],"tags":["type-validation","string","time","typeof","conversions"],"backgroundTag":null,"analyzedSha":"5c39e87a9a31f279c60f830ad74a845e4788a517","analyzedAt":"2026-08-13T04:54:54.474Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}