"use strict";
// Shared utility functions for workspace controllers
Object.defineProperty(exports, "__esModule", { value: true });
exports.getDateRangeData = exports.parseEndDate = exports.parseStartDate = exports.parseDateToUTC = void 0;
/**
 * Parse date string to UTC Date object
 * Handles ISO strings, Date objects, and MM/DD/YYYY format
 */
const parseDateToUTC = (dateValue, defaultDaysAgo = 7) => {
    if (dateValue) {
        const d = new Date(dateValue);
        if (!Number.isNaN(d.getTime())) {
            return d;
        }
    }
    // Fallback to default
    const fallback = new Date();
    fallback.setDate(fallback.getDate() - defaultDaysAgo);
    fallback.setUTCHours(0, 0, 0, 0);
    return fallback;
};
exports.parseDateToUTC = parseDateToUTC;
/**
 * Parse start date (beginning of day in UTC)
 */
const parseStartDate = (dateValue, defaultDaysAgo = 7) => {
    const date = (0, exports.parseDateToUTC)(dateValue, defaultDaysAgo);
    date.setUTCHours(0, 0, 0, 0);
    return date;
};
exports.parseStartDate = parseStartDate;
/**
 * Parse end date (end of day in UTC)
 */
const parseEndDate = (dateValue) => {
    const date = (0, exports.parseDateToUTC)(dateValue, 0);
    date.setUTCHours(23, 59, 59, 999);
    return date;
};
exports.parseEndDate = parseEndDate;
/**
 * Get date range data structure for chart data
 */
const getDateRangeData = (startDate, endDate) => {
    const days = [];
    const start = new Date(startDate);
    start.setUTCHours(0, 0, 0, 0);
    const end = new Date(endDate);
    end.setUTCHours(23, 59, 59, 999);
    const currentDate = new Date(start);
    while (currentDate <= end) {
        // Use UTC date string to ensure consistency
        const year = currentDate.getUTCFullYear();
        const month = String(currentDate.getUTCMonth() + 1).padStart(2, '0');
        const day = String(currentDate.getUTCDate()).padStart(2, '0');
        days.push({
            date: `${year}-${month}-${day}`,
            total: 0,
            pass: 0,
            fail: 0,
            error: 0,
        });
        currentDate.setUTCDate(currentDate.getUTCDate() + 1);
    }
    return days;
};
exports.getDateRangeData = getDateRangeData;
//# sourceMappingURL=workspaceUtils.js.map