import moment from 'moment-timezone';
import { isWeekDay } from './timeFrames';
// from 0 (Monday) to 6 (Sunday) to 0 (Sunday) to 6 (Saturday)
export const convertWeekDayToMomentWeekDay = (weekDay) => {
    const converted = weekDay + 1;
    return converted <= 6 ? converted : 0;
};
const createMomentLocaleForWeekStart = (name, startOfWeek) => {
    if (!moment.locales().includes(name)) {
        moment.locale(name, {
            week: {
                dow: convertWeekDayToMomentWeekDay(startOfWeek),
            },
        });
    }
};
export const getMomentDateWithCustomStartOfWeek = (startOfWeek, inp) => {
    if (isWeekDay(startOfWeek)) {
        const localeName = `lightdash-start-of-week-${startOfWeek}`;
        createMomentLocaleForWeekStart(localeName, startOfWeek);
        return moment(inp).locale(localeName);
    }
    return moment(inp);
};
export const formatMilliseconds = (ms, fractionDigits = 2) => ms.toFixed(fractionDigits).replace(/\.?0+$/, '');
//# sourceMappingURL=time.js.map