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 getDayRange = (date = new Date()) => {
|
||||
const start = new Date(date);
|
||||
start.setHours(0, 0, 0, 0);
|
||||
const end = new Date(date);
|
||||
end.setHours(23, 59, 59, 999);
|
||||
// Get day range in Korea Standard Time (UTC+9)
|
||||
const getDayRange = () => {
|
||||
const now = new Date();
|
||||
// Get current time in KST (UTC+9)
|
||||
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 };
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user