import { date } from 'quasar';

const anchor_date: Date = new Date('2023-12-17');

export const getCurrentPayPeriod = (today = new Date()): number => {
    const period_length = 14; // days
    const periods_per_year = 26;

    const days_since_anchor = date.getDateDiff(today, anchor_date, 'days');
    const periods_since_anchor = Math.floor(days_since_anchor / period_length);

    const current_period = (periods_since_anchor % periods_per_year) + 1;

    return current_period;
}

export const getMinutes = (hours: number) => {
    const minutes_percent = hours - Math.floor(hours);
    const minutes = Math.round(minutes_percent * 60);
    return minutes > 1 ? minutes.toString() : '0';
}

export const getHoursMinutesStringFromHoursFloat = (hours: number): string => {
    let flat_hours = Math.floor(hours);
    let minutes = Math.round((hours - flat_hours) * 60);

    if (minutes === 60) {
        flat_hours += 1;
        minutes = 0;
    }
    
    return `${flat_hours}h${minutes > 1 ? ' ' + minutes : ''}`
}