mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-20 22:22:16 +01:00
Compare commits
3 Commits
main
...
feature/ex
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3bddd49364 | ||
|
|
ab5dbfef36 | ||
|
|
2eb9ae699c |
@@ -33,8 +33,8 @@ class RouteServiceProvider extends ServiceProvider
|
||||
}
|
||||
|
||||
return $request->user()
|
||||
? Limit::perMinute(config('app.api_rate_limit_authenticated_per_minute'))->by($request->user()->id)
|
||||
: Limit::perMinute(config('app.api_rate_limit_guest_per_minute'))->by($request->ip());
|
||||
? Limit::perMinute(200)->by($request->user()->id)
|
||||
: Limit::perMinute(60)->by($request->ip());
|
||||
});
|
||||
|
||||
$this->routes(function (): void {
|
||||
|
||||
@@ -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
|
||||
* range it covers. A Year key is already a bare year, so it is returned unchanged - it must
|
||||
* not be parsed, Carbon reads a four digit string as a time of day.
|
||||
* range it covers.
|
||||
*/
|
||||
public function formatTimeGroupKey(?string $key, TimeEntryAggregationType $groupType): ?string
|
||||
{
|
||||
@@ -176,13 +175,6 @@ class LocalizationService
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -158,21 +158,6 @@ return [
|
||||
|
||||
'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
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
import { describe, expect, test } from 'vitest';
|
||||
import {
|
||||
formatHumanReadableDuration,
|
||||
formatMonth,
|
||||
formatReportingDuration,
|
||||
formatWeekRange,
|
||||
} from './time';
|
||||
import { formatHumanReadableDuration, formatReportingDuration, formatWeekRange } from './time';
|
||||
|
||||
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');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -245,15 +245,6 @@ export function formatWeekRange(date: string, format?: DateFormat): string {
|
||||
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.
|
||||
* @param date - date in the format of 'YYYY-MM-DD'
|
||||
|
||||
@@ -15,12 +15,7 @@ import {
|
||||
} from '@heroicons/vue/16/solid';
|
||||
import { Coffee } from '@lucide/vue';
|
||||
import BillableIcon from '@/packages/ui/src/Icons/BillableIcon.vue';
|
||||
import {
|
||||
type DateFormat,
|
||||
formatDate,
|
||||
formatMonth,
|
||||
formatWeekRange,
|
||||
} from '@/packages/ui/src/utils/time';
|
||||
import { type DateFormat, formatDate, formatWeekRange } from '@/packages/ui/src/utils/time';
|
||||
|
||||
export type GroupingOption =
|
||||
| 'project'
|
||||
@@ -32,9 +27,7 @@ export type GroupingOption =
|
||||
| 'tag'
|
||||
| 'type'
|
||||
| 'day'
|
||||
| 'week'
|
||||
| 'month'
|
||||
| 'year';
|
||||
| 'week';
|
||||
|
||||
export const useReportingStore = defineStore('reporting', () => {
|
||||
// Cache query composables to avoid creating new subscriptions on every call
|
||||
@@ -101,10 +94,6 @@ export const useReportingStore = defineStore('reporting', () => {
|
||||
if (type === 'week') {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -364,27 +364,14 @@ class LocalizationServiceTest extends TestCaseWithDatabase
|
||||
$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
|
||||
$this->localizationService->setDateFormat(DateFormat::SlashSeparatedDDMMYYYY);
|
||||
|
||||
// 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('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));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user