Fix: Update getDayRange to use Korea Standard Time (KST) for correct timezone handling
This commit is contained in:
@@ -3,11 +3,26 @@ const Todo = require("../models/Todo");
|
|||||||
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
const getDayRange = (date = new Date()) => {
|
// Get day range in Korea Standard Time (UTC+9)
|
||||||
const start = new Date(date);
|
const getDayRange = () => {
|
||||||
start.setHours(0, 0, 0, 0);
|
const now = new Date();
|
||||||
const end = new Date(date);
|
// Get current time in KST (UTC+9)
|
||||||
end.setHours(23, 59, 59, 999);
|
const kstOffset = 9 * 60; // minutes
|
||||||
|
const utcTime = now.getTime() + (now.getTimezoneOffset() * 60000);
|
||||||
|
const kstTime = new Date(utcTime + (kstOffset * 60000));
|
||||||
|
|
||||||
|
// Start of day in KST
|
||||||
|
const startKst = new Date(kstTime);
|
||||||
|
startKst.setHours(0, 0, 0, 0);
|
||||||
|
|
||||||
|
// End of day in KST
|
||||||
|
const endKst = new Date(kstTime);
|
||||||
|
endKst.setHours(23, 59, 59, 999);
|
||||||
|
|
||||||
|
// Convert back to UTC for MongoDB query
|
||||||
|
const start = new Date(startKst.getTime() - (kstOffset * 60000));
|
||||||
|
const end = new Date(endKst.getTime() - (kstOffset * 60000));
|
||||||
|
|
||||||
return { start, end };
|
return { start, end };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user