{"record":{"id":"9a161907e4fd3b30","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-dates","errorCode":"error-invalid-dates","errorMessage":"From date cannot be after To date","messagePattern":"From date cannot be after To date","errorType":"exception","errorClass":"Meteor.Error","httpStatus":400,"severity":"error","filePath":"apps/meteor/server/api/v1/rooms.ts","lineNumber":1039,"sourceCode":"\t\t\tthrow new Meteor.Error('error-invalid-room');\n\t\t}\n\n\t\tconst user = await Users.findOneById(this.userId);\n\n\t\tif (!user || !(await canAccessRoomAsync(room, user))) {\n\t\t\tthrow new Meteor.Error('error-not-allowed', 'Not Allowed');\n\t\t}\n\n\t\tif (type === 'file') {\n\t\t\tconst { dateFrom, dateTo } = this.bodyParams;\n\t\t\tconst { format } = this.bodyParams;\n\n\t\t\tconst convertedDateFrom = dateFrom ? new Date(dateFrom) : new Date(0);\n\t\t\tconst convertedDateTo = dateTo ? new Date(dateTo) : new Date();\n\t\t\tconvertedDateTo.setDate(convertedDateTo.getDate() + 1);\n\n\t\t\tif (convertedDateFrom > convertedDateTo) {\n\t\t\t\tthrow new Meteor.Error('error-invalid-dates', 'From date cannot be after To date');\n\t\t\t}\n\n\t\t\tvoid dataExport.sendFile(\n\t\t\t\t{\n\t\t\t\t\trid,\n\t\t\t\t\tformat,\n\t\t\t\t\tdateFrom: convertedDateFrom,\n\t\t\t\t\tdateTo: convertedDateTo,\n\t\t\t\t},\n\t\t\t\tuser,\n\t\t\t);\n\t\t\treturn API.v1.success();\n\t\t}\n\n\t\tif (type === 'email') {\n\t\t\tconst { toUsers, toEmails, subject, messages } = this.bodyParams;\n\n\t\t\tif ((!toUsers || toUsers.length === 0) && (!toEmails || toEmails.length === 0)) {","sourceCodeStart":1021,"sourceCodeEnd":1057,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/e4b8178b205510181a96ceefee043d0abcd13e5a/apps/meteor/server/api/v1/rooms.ts#L1021-L1057","documentation":"Thrown by POST /api/v1/rooms.export with type 'file' when convertedDateFrom is greater than convertedDateTo. dateFrom defaults to epoch 0 and dateTo defaults to now, and the server adds one day to dateTo before comparing, so the error only fires when the caller explicitly sends an inverted or overlapping range.","triggerScenarios":"POST rooms.export with dateFrom later than dateTo (e.g. from 2026-08-18, to 2026-08-01); date pickers submitting end-before-start; timezone conversion flipping the order across midnight.","commonSituations":"UIs with two independent date inputs and no ordering validation; reports where 'from' and 'to' fields are wired in reverse; DST or timezone shifts reordering same-day ranges; copy-pasted ranges from other tools.","solutions":["Validate and swap/reject the range client-side before sending","Check the field wiring: dateFrom is the older bound, dateTo the newer","Rely on defaults (omit both) when exporting the full history"],"exampleFix":"// before\nawait sdk.post('rooms.export', { rid, type: 'file', dateFrom: '2026-08-18', dateTo: '2026-08-01' }); // inverted\n\n// after\nlet [from, to] = [new Date(dateFrom), new Date(dateTo)].sort((a, b) => a - b);\nawait sdk.post('rooms.export', { rid, type: 'file', dateFrom: from.toISOString(), dateTo: to.toISOString() });","handlingStrategy":"validation","validationCode":"const from = new Date(dateFrom ?? 0);\nconst to = new Date(dateTo ?? Date.now());\nif (from > to) [dateFrom, dateTo] = [dateTo, dateFrom]; // or reject with a form error","typeGuard":null,"tryCatchPattern":"try {\n  await sdk.post('rooms.export', { rid, type: 'file', dateFrom, dateTo });\n} catch (e: any) {\n  if (e?.response?.data?.errorType === 'error-invalid-dates') {\n    throw new Error('export range inverted — fix dateFrom/dateTo order');\n  }\n  throw e;\n}","preventionTips":["Enforce from <= to in date-range pickers before submit","Double-check field wiring when porting export code","Remember the server adds one day to dateTo when reasoning about edge ranges"],"tags":["rooms","export","date-range","validation"],"backgroundTag":"invalid-date-range","analyzedSha":"e4b8178b205510181a96ceefee043d0abcd13e5a","analyzedAt":"2026-08-18T15:26:39.429Z","contentChangedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}