fix: use exact local time string for justification dates to prevent postgres timezone shift bugs

This commit is contained in:
Sidney 2026-05-06 20:44:05 -03:00
parent b850d76ba5
commit bc9f012129
2 changed files with 27 additions and 6 deletions

25
manager/check_justif.cjs Normal file
View File

@ -0,0 +1,25 @@
const { Pool } = require('pg');
const pool = new Pool({
user: 'postgres',
host: 'localhost',
database: 'edumanager',
password: 'admin',
port: 5432,
});
async function run() {
try {
const res = await pool.query("SELECT id, aluno_id, data, tipo, justificativa, justificativa_aceita FROM frequencias WHERE justificativa IS NOT NULL LIMIT 5;");
console.log(JSON.stringify(res.rows, null, 2));
// Check all attendance for a student with justification
const res2 = await pool.query("SELECT * FROM frequencias WHERE aluno_id = (SELECT aluno_id FROM frequencias WHERE justificativa IS NOT NULL LIMIT 1) ORDER BY data DESC LIMIT 5");
console.log("Student Recent:", JSON.stringify(res2.rows, null, 2));
} catch(e) {
console.error(e);
} finally {
pool.end();
}
}
run();

View File

@ -611,9 +611,7 @@ export default function Frequencia() {
) : canJustify ? ( ) : canJustify ? (
<button <button
onClick={() => { onClick={() => {
const lMs = parseLessonDateTime(lesson.date, lesson.startTime || '00:00:00'); const timestamp = `${lesson.date}T${lesson.startTime || '00:00'}:00`;
if (isNaN(lMs)) return;
const timestamp = new Date(lMs).toISOString();
openJustifyModal(timestamp); openJustifyModal(timestamp);
}} }}
style={{ style={{
@ -719,9 +717,7 @@ export default function Frequencia() {
return (isNaN(msB) ? 0 : msB) - (isNaN(msA) ? 0 : msA); return (isNaN(msB) ? 0 : msB) - (isNaN(msA) ? 0 : msA);
}) })
.map(l => { .map(l => {
const lMs = parseLessonDateTime(l.date, l.startTime || '00:00:00'); const ts = `${l.date}T${l.startTime || '00:00'}:00`;
if (isNaN(lMs)) return null;
const ts = new Date(lMs).toISOString();
return ( return (
<option key={l.id} value={ts}> <option key={l.id} value={ts}>
{formatDateFull(l.date)}{l.startTime ? `${l.startTime.substring(0, 5)}` : ''}{l.endTime ? ` às ${l.endTime.substring(0, 5)}` : ''} {formatDateFull(l.date)}{l.startTime ? `${l.startTime.substring(0, 5)}` : ''}{l.endTime ? ` às ${l.endTime.substring(0, 5)}` : ''}