src/period/generators/six-monthly.js

Summary

Maintainability
A
3 hrs
Test Coverage
import {
    validateIfValueIsInteger,
    getCurrentYear,
    getMonthNamesForLocale,
} from '../helpers'

export function generateSixMonthlyPeriodsForYear(
    year = getCurrentYear(),
    locale = 'en'
) {
    validateIfValueIsInteger(year)

    const monthNames = getMonthNamesForLocale(locale)

    return [
        {
            startDate: `${year}-01-01`,
            endDate: `${year}-06-30`,
            name: `${monthNames[0]} - ${monthNames[5]} ${year}`,
            id: `${year}S1`,
        },
        {
            startDate: `${year}-07-01`,
            endDate: `${year}-12-31`,
            name: `${monthNames[6]} - ${monthNames[11]} ${year}`,
            id: `${year}S2`,
        },
    ]
}