{"record":{"id":"a4f09e21f45c019e","repo":"discordjs/discord.js","slug":"timestamps-end-must-fit-into-a-unix-timestamp","errorCode":null,"errorMessage":"timestamps.end must fit into a unix timestamp","messagePattern":"timestamps\\.end must fit into a unix timestamp","errorType":"validation","errorClass":"RangeError","httpStatus":null,"severity":"error","filePath":"packages/rpc/src/client.ts","lineNumber":554,"sourceCode":"\t * @param activity - The rich presence to pass.\n\t * @param pid - The application's process ID. Defaults to the executing process' PID.\n\t * @remarks\n\t * Clients may only update their activity 5 times per 20 seconds.\n\t */\n\tpublic async setActivity(\n\t\tactivity: RPCSetActivityArgs['activity'] = {},\n\t\tpid: number | null = getPid(),\n\t\toptions?: RequestOptions,\n\t): Promise<unknown> {\n\t\tactivity.instance = Boolean(activity.instance);\n\n\t\tif (activity.timestamps) {\n\t\t\tif ('start' in activity.timestamps && isValidTimestamp(activity.timestamps.start)) {\n\t\t\t\tthrow new RangeError('timestamps.start must fit into a unix timestamp');\n\t\t\t}\n\n\t\t\tif ('end' in activity.timestamps && isValidTimestamp(activity.timestamps.end)) {\n\t\t\t\tthrow new RangeError('timestamps.end must fit into a unix timestamp');\n\t\t\t}\n\t\t}\n\n\t\treturn this.request(\n\t\t\tRPCCommands.SetActivity,\n\t\t\t{\n\t\t\t\tpid: pid ?? 0,\n\t\t\t\tactivity,\n\t\t\t},\n\t\t\toptions,\n\t\t);\n\t}\n\n\t/**\n\t * Clears the currently set presence, if any. This will hide the \"Playing X\" message\n\t * displayed below the user's name.\n\t *\n\t * @param pid - The application's process ID. Defaults to the executing process' PID.","sourceCodeStart":536,"sourceCodeEnd":572,"githubUrl":"https://github.com/discordjs/discord.js/blob/a81ed8a306d37fdc746e26a634b6a42164ba2c8c/packages/rpc/src/client.ts#L536-L572","documentation":"Same validation as timestamps.start but for activity.timestamps.end in setActivity(): the value must be a valid unix timestamp or a RangeError is thrown.","triggerScenarios":"Calling client.setActivity({ timestamps: { end: someValue } }) where someValue is in milliseconds, NaN, or otherwise outside valid epoch-seconds range.","commonSituations":"Setting an end time with Date.now() + durationInMs without converting to seconds, or leaving end as undefined-checked string input from config.","solutions":["Convert to epoch seconds: Math.floor((Date.now() + durationMs) / 1000)","Validate the number is finite and within unix range before passing","Omit timestamps.end if unknown"],"exampleFix":"// before\nclient.setActivity({ timestamps: { end: Date.now() + 60_000 } });\n// after\nclient.setActivity({ timestamps: { end: Math.floor((Date.now() + 60_000) / 1000) } });","handlingStrategy":"validation","validationCode":"const endSec = Math.floor((Date.now() + durationMs) / 1000);\nif (!Number.isFinite(endSec)) throw new Error('end out of unix range');","typeGuard":"function isValidEpochSeconds(v: unknown): v is number {\n  return typeof v === 'number' && Number.isFinite(v) && v > 0 && v < 2 ** 53 - 1;\n}","tryCatchPattern":"try {\n  await client.setActivity(activity);\n} catch (err) {\n  if (err instanceof RangeError && err.message.includes('timestamps.end')) {\n    // drop or fix timestamps.end and retry\n  }\n}","preventionTips":["Compute end times in seconds: Math.floor(ms / 1000)","Validate timestamps before each setActivity call","Omit timestamps.end when the end time is unknown"],"tags":["validation","rich-presence","unix-timestamp"],"backgroundTag":"invalid-timestamp","analyzedSha":"a81ed8a306d37fdc746e26a634b6a42164ba2c8c","analyzedAt":"2026-08-30T04:07:22.193Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}