mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-20 22:22:16 +01:00
Format date group labels in all aggregate exports
This commit is contained in:
committed by
Gregor Vostrak
parent
111e12df12
commit
97fd882878
@@ -8,12 +8,14 @@ use App\Enums\CurrencyFormat;
|
||||
use App\Enums\DateFormat;
|
||||
use App\Enums\IntervalFormat;
|
||||
use App\Enums\NumberFormat;
|
||||
use App\Enums\TimeEntryAggregationType;
|
||||
use App\Enums\TimeFormat;
|
||||
use App\Models\Organization;
|
||||
use Brick\Math\BigDecimal;
|
||||
use Brick\Money\Money;
|
||||
use Carbon\CarbonInterface;
|
||||
use Carbon\CarbonInterval;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
class LocalizationService
|
||||
{
|
||||
@@ -152,6 +154,29 @@ class LocalizationService
|
||||
return $date->format($this->dateFormat->toCarbonFormat());
|
||||
}
|
||||
|
||||
/**
|
||||
* Time group types have no server-side descriptor, so reports fall back to rendering the raw
|
||||
* aggregation key. For the Day type that key is an ISO date (Y-m-d), which is formatted here
|
||||
* so exports match the rest of the UI instead of leaking the key.
|
||||
*
|
||||
* Week, month and year keys have different shapes ('Y-m-d' for the week start, 'Y-m' and 'Y'),
|
||||
* and are not offered as a grouping in the reporting UI, so they are returned unchanged.
|
||||
* Presenting those needs its own decision: a week rendered as its start date reads as a single
|
||||
* day, and a month rendered with a full date format reads as a specific day.
|
||||
*/
|
||||
public function formatTimeGroupKey(?string $key, TimeEntryAggregationType $groupType): ?string
|
||||
{
|
||||
if ($key === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($groupType !== TimeEntryAggregationType::Day) {
|
||||
return $key;
|
||||
}
|
||||
|
||||
return $this->formatDate(Carbon::parse($key));
|
||||
}
|
||||
|
||||
public function setDateFormat(DateFormat $dateFormat): void
|
||||
{
|
||||
$this->dateFormat = $dateFormat;
|
||||
|
||||
Reference in New Issue
Block a user