import moment from 'moment';
// 반올림
export const roundNumber = (number, decimal = 2) => {
    const result = Math.round(number * 10 ** decimal) / 10 ** decimal;
    return isFinite(result) ? result : 0;
};
// 소수점 자르기
export const floorNumber = (number, decimal = 2) => {
    const result = Math.floor(number * 10 ** decimal) / 10 ** decimal;
    return isFinite(result) ? result : 0;
};
// 값 없을때 기본 값 반환
export const arrayToObject = (array, key, keyFn) => {
    return array.reduce((acc, item) => {
        const objKey = keyFn ? keyFn(item[key]) : item[key];
        acc[objKey] = item;
        return acc;
    }, {});
};
// 켈빈 온도를 섭씨 온도로 변환
export const kelvinToCelsius = (kelvin) => {
    return kelvin - 273.15;
};
// 부가세 전력기반기금 편익
export const getSolarSavingFeeWithTax = (solarSavingFee = 0) => {
    return solarSavingFee * 0.1 + solarSavingFee * 0.027;
};
// 오늘 날짜 format yyyy-mm-dd
export const getToday = () => {
    return Intl.DateTimeFormat('ko-KR', {
        year: 'numeric',
        month: '2-digit',
        day: '2-digit',
        timeZone: 'Asia/Seoul'
    })
        .format(new Date())
        .replace(/\. /g, '-')
        .replace('.', '');
};
export const getDailyChartXAxis = () => {
    return [
        '01',
        '02',
        '03',
        '04',
        '05',
        '06',
        '07',
        '08',
        '09',
        '10',
        '11',
        '12',
        '13',
        '14',
        '15',
        '16',
        '17',
        '18',
        '19',
        '20',
        '21',
        '22',
        '23',
        '24'
    ];
};
export const getMonthlyChartXAxis = (yearMonth) => {
    const startOfMonth = moment(yearMonth, 'YYYY-MM').startOf('month');
    const endOfMonth = moment(yearMonth, 'YYYY-MM').endOf('month');
    const dates = [];
    for (let date = startOfMonth; date <= endOfMonth; date.add(1, 'day')) {
        dates.push(date.format('YYYY-MM-DD'));
    }
    return dates;
};
export const getYearlyChartXAxis = (year) => {
    return [
        `${year}-01`,
        `${year}-02`,
        `${year}-03`,
        `${year}-04`,
        `${year}-05`,
        `${year}-06`,
        `${year}-07`,
        `${year}-08`,
        `${year}-09`,
        `${year}-10`,
        `${year}-11`,
        `${year}-12`
    ];
};
//# sourceMappingURL=common.js.map