Compare commits

..

3 Commits

Author SHA1 Message Date
Andrew Herron
3bddd49364 Add "Week" grouping option to reporting 2026-08-19 16:28:59 +10:00
Andrew Herron
ab5dbfef36 Format date group labels in all aggregate exports 2026-07-30 11:56:27 +00:00
Andrew Herron
2eb9ae699c Add "Date" grouping option to reporting 2026-07-30 10:49:45 +00:00
7 changed files with 9 additions and 76 deletions

View File

@@ -33,8 +33,8 @@ class RouteServiceProvider extends ServiceProvider
} }
return $request->user() return $request->user()
? Limit::perMinute(config('app.api_rate_limit_authenticated_per_minute'))->by($request->user()->id) ? Limit::perMinute(200)->by($request->user()->id)
: Limit::perMinute(config('app.api_rate_limit_guest_per_minute'))->by($request->ip()); : Limit::perMinute(60)->by($request->ip());
}); });
$this->routes(function (): void { $this->routes(function (): void {

View File

@@ -155,10 +155,9 @@ class LocalizationService
} }
/** /**
* Time group types have no server-side descriptor; their keys are ISO dates and are * Time group types have no server-side descriptor; Day and Week keys are ISO dates and
* formatted here instead. A Week key is the first day of that week, so it renders as the * formatted here instead. A Week key is the first day of that week, so it renders as the
* range it covers. A Year key is already a bare year, so it is returned unchanged - it must * range it covers.
* not be parsed, Carbon reads a four digit string as a time of day.
*/ */
public function formatTimeGroupKey(?string $key, TimeEntryAggregationType $groupType): ?string public function formatTimeGroupKey(?string $key, TimeEntryAggregationType $groupType): ?string
{ {
@@ -176,13 +175,6 @@ class LocalizationService
return $this->formatDate($weekStart).' - '.$this->formatDate($weekStart->copy()->addDays(6)); return $this->formatDate($weekStart).' - '.$this->formatDate($weekStart->copy()->addDays(6));
} }
if ($groupType === TimeEntryAggregationType::Month) {
// Note: the leading "!" resets all fields the format does not name. Without it the
// day of the month is taken from today, and a day that the parsed month does not
// have overflows the date into the next month.
return Carbon::createFromFormat('!Y-m', $key)->format('F Y');
}
return $key; return $key;
} }

View File

@@ -158,21 +158,6 @@ return [
'pagination_per_page_default' => (int) env('PAGINATION_PER_PAGE_DEFAULT', 15), 'pagination_per_page_default' => (int) env('PAGINATION_PER_PAGE_DEFAULT', 15),
/*
|--------------------------------------------------------------------------
| API Rate Limiting
|--------------------------------------------------------------------------
|
| The number of API requests allowed per minute, counted per user for
| authenticated requests and per IP address for guest requests. These
| limits are only enforced when the application runs in production.
|
*/
'api_rate_limit_authenticated_per_minute' => (int) (env('API_RATE_LIMIT_AUTH_PER_MINUTE') ?: 200),
'api_rate_limit_guest_per_minute' => (int) (env('API_RATE_LIMIT_GUEST_PER_MINUTE') ?: 60),
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
| Encryption Key | Encryption Key

View File

@@ -1,10 +1,5 @@
import { describe, expect, test } from 'vitest'; import { describe, expect, test } from 'vitest';
import { import { formatHumanReadableDuration, formatReportingDuration, formatWeekRange } from './time';
formatHumanReadableDuration,
formatMonth,
formatReportingDuration,
formatWeekRange,
} from './time';
const seconds = 14 * 3600 + 45 * 60 + 6; // 14h 45m 06s const seconds = 14 * 3600 + 45 * 60 + 6; // 14h 45m 06s
@@ -65,9 +60,3 @@ describe('formatWeekRange', () => {
); );
}); });
}); });
describe('formatMonth', () => {
test('renders the name of the month that the key covers', () => {
expect(formatMonth('2001-02')).toBe('February 2001');
});
});

View File

@@ -245,15 +245,6 @@ export function formatWeekRange(date: string, format?: DateFormat): string {
return `${formatDate(date, format)} - ${formatDate(end, format)}`; return `${formatDate(date, format)} - ${formatDate(end, format)}`;
} }
/*
* Returns the month that the given key falls in. There is no `DateFormat` variant for a
* month, so this is not affected by the organization date format.
* @param date - a month, in the format of 'YYYY-MM'
*/
export function formatMonth(date: string): string {
return getDayJsInstance()(date).format('MMMM YYYY');
}
/* /*
* Returns a human readable date format. * Returns a human readable date format.
* @param date - date in the format of 'YYYY-MM-DD' * @param date - date in the format of 'YYYY-MM-DD'

View File

@@ -15,12 +15,7 @@ import {
} from '@heroicons/vue/16/solid'; } from '@heroicons/vue/16/solid';
import { Coffee } from '@lucide/vue'; import { Coffee } from '@lucide/vue';
import BillableIcon from '@/packages/ui/src/Icons/BillableIcon.vue'; import BillableIcon from '@/packages/ui/src/Icons/BillableIcon.vue';
import { import { type DateFormat, formatDate, formatWeekRange } from '@/packages/ui/src/utils/time';
type DateFormat,
formatDate,
formatMonth,
formatWeekRange,
} from '@/packages/ui/src/utils/time';
export type GroupingOption = export type GroupingOption =
| 'project' | 'project'
@@ -32,9 +27,7 @@ export type GroupingOption =
| 'tag' | 'tag'
| 'type' | 'type'
| 'day' | 'day'
| 'week' | 'week';
| 'month'
| 'year';
export const useReportingStore = defineStore('reporting', () => { export const useReportingStore = defineStore('reporting', () => {
// Cache query composables to avoid creating new subscriptions on every call // Cache query composables to avoid creating new subscriptions on every call
@@ -101,10 +94,6 @@ export const useReportingStore = defineStore('reporting', () => {
if (type === 'week') { if (type === 'week') {
return formatWeekRange(key, dateFormat); return formatWeekRange(key, dateFormat);
} }
if (type === 'month') {
return formatMonth(key);
}
// A `year` key is already a bare year, so it falls through unchanged.
return key; return key;
} }

View File

@@ -364,27 +364,14 @@ class LocalizationServiceTest extends TestCaseWithDatabase
$this->assertSame('29/12/2025 - 04/01/2026', $formatted); $this->assertSame('29/12/2025 - 04/01/2026', $formatted);
} }
public function test_format_time_group_key_formats_a_month_key_and_does_not_change_year_and_entity_group_types(): void public function test_format_time_group_key_does_not_change_month_year_and_entity_group_types(): void
{ {
// Arrange // Arrange
$this->localizationService->setDateFormat(DateFormat::SlashSeparatedDDMMYYYY); $this->localizationService->setDateFormat(DateFormat::SlashSeparatedDDMMYYYY);
// Act & Assert // Act & Assert
$this->assertSame('February 2001', $this->localizationService->formatTimeGroupKey('2001-02', TimeEntryAggregationType::Month)); $this->assertSame('2001-02', $this->localizationService->formatTimeGroupKey('2001-02', TimeEntryAggregationType::Month));
$this->assertSame('2001', $this->localizationService->formatTimeGroupKey('2001', TimeEntryAggregationType::Year)); $this->assertSame('2001', $this->localizationService->formatTimeGroupKey('2001', TimeEntryAggregationType::Year));
$this->assertSame('some-uuid', $this->localizationService->formatTimeGroupKey('some-uuid', TimeEntryAggregationType::Project)); $this->assertSame('some-uuid', $this->localizationService->formatTimeGroupKey('some-uuid', TimeEntryAggregationType::Project));
} }
public function test_format_time_group_key_formats_a_month_key_independently_of_the_current_day_of_month(): void
{
// Arrange
// Note: the current day of the month must not leak into the parsed month. The 31st does
// not exist in April, so a leaked day overflows the date into the following month.
$this->travelTo(Carbon::create(2026, 8, 31, 12, 0, 0, 'UTC'));
// Act & Assert
$this->assertSame('February 2001', $this->localizationService->formatTimeGroupKey('2001-02', TimeEntryAggregationType::Month));
$this->assertSame('April 2026', $this->localizationService->formatTimeGroupKey('2026-04', TimeEntryAggregationType::Month));
$this->assertSame('December 2026', $this->localizationService->formatTimeGroupKey('2026-12', TimeEntryAggregationType::Month));
}
} }