// utils/dateUtils.js

// Returns date range from today to tomorrow (current date to current date + 1)
// Adjusted for IST timezone to ensure correct date in API payloads
export const getTodayDateRange = () => {
  const now = new Date();
  const year = now.getFullYear();
  const month = now.getMonth();
  const date = now.getDate();
  
  // Create dates in UTC with the current local date
  const startDate = new Date(Date.UTC(year, month, date, 0, 0, 0, 0));
  const endDate = new Date(Date.UTC(year, month, date + 1, 23, 59, 59, 999));
  
  return { startDate, endDate };
};

// Returns current month date range
// Adjusted for IST timezone to ensure correct date in API payloads
export const getDefaultDateRange = () => {
  const now = new Date();
  const year = now.getFullYear();
  const month = now.getMonth();
  
  // Create dates in UTC with the current local date
  const startDate = new Date(Date.UTC(year, month, 1, 0, 0, 0, 0));
  const endDate = new Date(Date.UTC(year, month + 1, 0, 23, 59, 59, 999));
  
  return { startDate, endDate };
};

export const formatDate = (date) =>
  new Date(date.getTime() - date.getTimezoneOffset() * 60000)
    .toISOString()
    .split('T')[0];
