Backend\Classes\Dashboard\ReportPeriodCalculator

Overview

ReportPeriodCalculator is a utility class for calculating previous time periods based on given start and end dates. The class can handle periods defined as multiples of full years, full quarters, full months, full weeks, and full days. It calculates the start and end dates of the corresponding previous period.


Public Methods

public getPreviousPeriod()

public getPreviousPeriod(
    Carbon $startDate,
    Carbon $endDate
): ?CarbonPeriod 

Get the start and end dates for the previous period based on the given period.

This method identifies if the current period represents a multiple of full years, full quarters, full months, full weeks, or full days. It then calculates the corresponding previous period, taking into account the same multiple.

public getPreviousPeriodLastYear()

public getPreviousPeriodLastYear(
    Carbon $startDate,
    Carbon $endDate
): ?CarbonPeriod 

Get the start and end dates for the previous period of the last year based on the given period.

This method identifies if the current period represents a multiple of full years, full quarters, full months, full weeks, or full days. It then calculates the corresponding previous period for the last year, taking into account the same multiple.