Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/Http/Controllers/Settings/GeneralController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use App\Http\Requests\UpdateGeneralSettingsRequest;
use App\Http\Requests\UpdateLocaleRequest;
use App\Jobs\CalculateWeekBalance;
use App\Services\TimeFormatService;
use App\Settings\GeneralSettings;
use App\Settings\ProjectSettings;
use DateTimeZone;
Expand Down Expand Up @@ -38,6 +39,7 @@ public function edit(GeneralSettings $settings)
'timezones' => DateTimeZone::listIdentifiers(),
'timezone' => $settings->timezone,
'defaultOverview' => $settings->default_overview,
'timeDisplayFormat' => $settings->time_display_format ?? TimeFormatService::CLOCK,
]);
}

Expand All @@ -53,6 +55,7 @@ public function update(UpdateGeneralSettingsRequest $request, GeneralSettings $s
$settings->appActivityTracking = $data['appActivityTracking'];
$settings->timezone = $data['timezone'];
$settings->default_overview = $data['default_overview'] ?? 'week';
$settings->time_display_format = $data['time_display_format'] ?? TimeFormatService::CLOCK;

if ($data['theme'] !== $settings->theme ?? SystemThemesEnum::SYSTEM->value) {
$settings->theme = $data['theme'];
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Middleware/HandleInertiaRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Http\Middleware;

use App\Services\TimeFormatService;
use App\Services\TimestampService;
use App\Settings\GeneralSettings;
use Illuminate\Http\Request;
Expand Down Expand Up @@ -42,6 +43,7 @@ public function share(Request $request): array
'js_locale' => str_replace('_', '-', $settings->locale ?? config('app.fallback_locale')),
'locale' => $settings->locale ?? config('app.fallback_locale'),
'timezone' => $settings->timezone ?? config('app.timezone'),
'time_display_format' => $settings->time_display_format ?? TimeFormatService::CLOCK,
'app_version' => config('nativephp.version'),
'date' => now()->format('Y-m-d'),
'recording' => (bool) TimestampService::getCurrentType(),
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Requests/UpdateGeneralSettingsRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Http\Requests;

use App\Services\TimeFormatService;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
Expand Down Expand Up @@ -35,6 +36,7 @@ public function rules(): array
'appActivityTracking' => ['required', 'boolean'],
'timezone' => ['required', 'string', 'timezone'],
'default_overview' => ['required', Rule::in(['day', 'week', 'month', 'year'])],
'time_display_format' => ['required', Rule::in([TimeFormatService::CLOCK, TimeFormatService::DECIMAL])],
];
}
}
9 changes: 7 additions & 2 deletions app/Jobs/MenubarRefresh.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

use App\Enums\TimestampTypeEnum;
use App\Services\LocaleService;
use App\Services\TimeFormatService;
use App\Services\TimestampService;
use App\Services\TrayIconService;
use App\Settings\GeneralSettings;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;
use Native\Desktop\Facades\MenuBar;
Expand All @@ -23,6 +25,7 @@ public function handle(): void
{
try {
new LocaleService;
$settings = resolve(GeneralSettings::class);
$currentType = TimestampService::getCurrentType();

if ($currentType === TimestampTypeEnum::WORK) {
Expand All @@ -39,8 +42,10 @@ public function handle(): void
return;
}

MenuBar::tooltip(gmdate('G:i', (int) $time));
MenuBar::label(gmdate('G:i', (int) $time));
$formattedTime = TimeFormatService::formatDuration($time, $settings->time_display_format ?? TimeFormatService::CLOCK);

MenuBar::tooltip($formattedTime);
MenuBar::label($formattedTime);
} catch (\Throwable) {
return;
}
Expand Down
52 changes: 52 additions & 0 deletions app/Services/TimeFormatService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

declare(strict_types=1);

namespace App\Services;

class TimeFormatService
{
public const string CLOCK = 'clock';

public const string DECIMAL = 'decimal';

public static function formatDuration(int|float $seconds, string $format = self::CLOCK): string
{
if ($format === self::DECIMAL) {
return number_format($seconds / 3600, 2, '.', '');
}

return gmdate('G:i', (int) $seconds);
}

public static function unitTranslationKey(int|float $seconds, string $format = self::CLOCK): string
{
if ($format === self::DECIMAL) {
return 'h';
}

return abs($seconds) >= 3600 ? 'h' : 'min';
}

public static function formatDurationWithUnit(int|float $seconds, string $format = self::CLOCK): string
{
$unit = self::unitTranslationKey($seconds, $format);

if (app()->bound('translator')) {
$unit = trans('app.'.$unit);
}

$formattedDuration = self::formatDuration($seconds, $format);

if ($format === self::CLOCK && abs($seconds) < 3600) {
$minutes = (int) floor(abs($seconds) / 60);
$formattedDuration = ($seconds < 0 ? '-' : '').$minutes;
}

return sprintf(
'%s %s',
$formattedDuration,
$unit
);
}
}
2 changes: 2 additions & 0 deletions app/Settings/GeneralSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class GeneralSettings extends Settings

public string $default_overview = 'week';

public string $time_display_format = 'clock';

public static function group(): string
{
return 'general';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

use Spatie\LaravelSettings\Migrations\SettingsMigration;

return new class extends SettingsMigration
{
public function up(): void
{
$this->migrator->add('general.time_display_format', 'clock');
}

public function down(): void
{
$this->migrator->delete('general.time_display_format');
}
};
4 changes: 4 additions & 0 deletions lang/da/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@
'chinese' => 'Kinesisk',
'choose how fractional days are rounded.' => 'Vælg, hvordan brøkdelsdage rundes.',
'choose the appearance of the application.' => 'Vælg applikationens udseende.',
'choose how durations are shown' => 'Vælg, hvordan varigheder vises.',
'choose whether to show vacation steps' => 'Vælg, om ferietrin skal vises.',
'choose your mode' => 'Vælg din tilstand.',
'click "export" at the top of the table and choose "save as csv".' => 'Klik på "Eksporter" øverst i tabellen og vælg "Gem som CSV".',
'clock (7:30)' => 'Klokkeslæt (7:30)',
'close' => 'Luk',
'color' => 'Farve',
'confirm' => 'Bekræft',
Expand Down Expand Up @@ -89,6 +91,7 @@
'day' => 'Dag',
'day equivalent' => 'Dagsækvivalent',
'days' => 'Dage',
'decimal hours (7.50)' => 'Decimaltimer (7.50)',
'default annual entitlement' => 'Standard årlig tildeling',
'default overview' => 'Standardoversigt',
'default: :value days' => 'Standard: :value dage',
Expand Down Expand Up @@ -341,6 +344,7 @@
'this shortcut is not supported.' => 'Denne genvej understøttes ikke.',
'time' => 'Tid',
'time balance' => 'Tidssaldo',
'time display' => 'Tidsvisning',
'time span' => 'Tidsperiode',
'timezone' => 'Tidszone',
'to import data from clockify, you must first export it. Simply follow the step-by-step instructions below.' => 'For at importere data fra Clockify skal du først eksportere dem. Følg blot de trinvise instruktioner nedenfor.',
Expand Down
4 changes: 4 additions & 0 deletions lang/de/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@
'chinese' => 'Chinesisch',
'choose how fractional days are rounded.' => 'Legt fest, in welchen Abstufungen Urlaubstage gerundet werden.',
'choose the appearance of the application.' => 'Wähle das Erscheinungsbild der Anwendung.',
'choose how durations are shown' => 'Wähle, wie Zeitdauern angezeigt werden.',
'choose whether to show vacation steps' => 'Wähle, ob wir Urlaubsschritte zeigen sollen.',
'choose your mode' => 'Wähle deinen Modus.',
'click "export" at the top of the table and choose "save as csv".' => 'Klicken Sie oben in der Tabelle auf „Export“ und wählen Sie „Als CSV speichern“.',
'clock (7:30)' => 'Uhrzeit (7:30)',
'close' => 'Schließen',
'color' => 'Farbe',
'confirm' => 'Bestätigen',
Expand Down Expand Up @@ -89,6 +91,7 @@
'day' => 'Tag',
'day equivalent' => 'Tagesäquivalent',
'days' => 'Tage',
'decimal hours (7.50)' => 'Dezimalstunden (7.50)',
'default annual entitlement' => 'Standardjahreskontingent',
'default overview' => 'Standard-Übersicht',
'default: :value days' => 'Standardwert: :value Tage',
Expand Down Expand Up @@ -341,6 +344,7 @@
'this shortcut is not supported.' => 'Diese Tastenkombination wird nicht unterstützt.',
'time' => 'Uhrzeit',
'time balance' => 'Arbeitszeitbilanz',
'time display' => 'Zeitanzeige',
'time span' => 'Zeitspanne',
'timezone' => 'Zeitzone',
'to import data from clockify, you must first export it. Simply follow the step-by-step instructions below.' => 'Um Daten aus Clockify zu importieren, müssen Sie diese zunächst exportieren. Folgen Sie einfach der nachfolgenden Schritt-für-Schritt-Anleitung.',
Expand Down
4 changes: 4 additions & 0 deletions lang/en/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@
'chinese' => 'Chinese',
'choose how fractional days are rounded.' => 'Choose how fractional days are rounded.',
'choose the appearance of the application.' => 'Choose the appearance of the application.',
'choose how durations are shown' => 'Choose how durations are shown.',
'choose whether to show vacation steps' => 'Choose whether to show vacation steps.',
'choose your mode' => 'Choose your mode.',
'click "export" at the top of the table and choose "save as csv".' => 'Click "Export" at the top of the table and choose "Save as CSV".',
'clock (7:30)' => 'Clock (7:30)',
'close' => 'Close',
'color' => 'Color',
'confirm' => 'Confirm',
Expand Down Expand Up @@ -89,6 +91,7 @@
'day' => 'Day',
'day equivalent' => 'Day equivalent',
'days' => 'Days',
'decimal hours (7.50)' => 'Decimal hours (7.50)',
'default annual entitlement' => 'Default annual entitlement',
'default overview' => 'Default overview',
'default: :value days' => 'Default: :value days',
Expand Down Expand Up @@ -341,6 +344,7 @@
'this shortcut is not supported.' => 'This shortcut is not supported.',
'time' => 'Time',
'time balance' => 'Time Balance',
'time display' => 'Time display',
'time span' => 'Time span',
'timezone' => 'Timezone',
'to import data from clockify, you must first export it. Simply follow the step-by-step instructions below.' => 'To import data from Clockify, you must first export it. Simply follow the step-by-step instructions below.',
Expand Down
4 changes: 4 additions & 0 deletions lang/fr/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@
'chinese' => 'Chinois',
'choose how fractional days are rounded.' => 'Détermine comment les fractions de journée sont arrondies.',
'choose the appearance of the application.' => 'Choisissez l\'apparence de l\'application.',
'choose how durations are shown' => 'Choisissez comment les durées sont affichées.',
'choose whether to show vacation steps' => 'Choisissez si nous devons afficher les étapes de congés.',
'choose your mode' => 'Choisissez votre mode.',
'click "export" at the top of the table and choose "save as csv".' => 'Cliquez sur "Exporter" en haut du tableau et choisissez "Enregistrer en CSV".',
'clock (7:30)' => 'Horloge (7:30)',
'close' => 'Fermer',
'color' => 'Couleur',
'confirm' => 'Confirmer',
Expand Down Expand Up @@ -89,6 +91,7 @@
'day' => 'Jour',
'day equivalent' => 'Équivalent jour',
'days' => 'Jours',
'decimal hours (7.50)' => 'Heures décimales (7.50)',
'default annual entitlement' => 'Quota annuel par défaut',
'default overview' => 'Vue par défaut',
'default: :value days' => 'Valeur par défaut : :value jours',
Expand Down Expand Up @@ -341,6 +344,7 @@
'this shortcut is not supported.' => 'Ce raccourci n’est pas pris en charge.',
'time' => 'Temps',
'time balance' => 'Solde du temps',
'time display' => 'Affichage du temps',
'time span' => 'Plage horaire',
'timezone' => 'Fuseau horaire',
'to import data from clockify, you must first export it. Simply follow the step-by-step instructions below.' => 'Pour importer des données depuis Clockify, vous devez d\'abord les exporter. Suivez simplement les instructions ci-dessous.',
Expand Down
4 changes: 4 additions & 0 deletions lang/it/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@
'chinese' => 'Cinese',
'choose how fractional days are rounded.' => 'Scegli come arrotondare i giorni frazionari.',
'choose the appearance of the application.' => 'Scegli l\'aspetto dell\'applicazione.',
'choose how durations are shown' => 'Scegli come vengono mostrate le durate.',
'choose whether to show vacation steps' => 'Scegli se mostrare i passaggi per le ferie.',
'choose your mode' => 'Scegli la tua modalità.',
'click "export" at the top of the table and choose "save as csv".' => 'Clicca "Esporta" in cima alla tabella e scegli "Salva come CSV".',
'clock (7:30)' => 'Orario (7:30)',
'close' => 'Chiudi',
'color' => 'Colore',
'confirm' => 'Conferma',
Expand Down Expand Up @@ -89,6 +91,7 @@
'day' => 'Giorno',
'day equivalent' => 'Equivalente giorno',
'days' => 'Giorni',
'decimal hours (7.50)' => 'Ore decimali (7.50)',
'default annual entitlement' => 'Maturazione annuale predefinita',
'default overview' => 'Panoramica predefinita',
'default: :value days' => 'Predefinito: :value giorni',
Expand Down Expand Up @@ -341,6 +344,7 @@
'this shortcut is not supported.' => 'Questa scorciatoia non è supportata.',
'time' => 'Tempo',
'time balance' => 'Saldo ore',
'time display' => 'Formato orario',
'time span' => 'Intervallo di tempo',
'timezone' => 'Fuso orario',
'to import data from clockify, you must first export it. Simply follow the step-by-step instructions below.' => 'Per importare dati da Clockify, devi prima esportarli. Segui semplicemente le istruzioni passo-passo qui sotto.',
Expand Down
4 changes: 4 additions & 0 deletions lang/pt_BR/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@
'chinese' => 'Chinês',
'choose how fractional days are rounded.' => 'Escolha como os dias fracionados são arredondados.',
'choose the appearance of the application.' => 'Escolha a aparência do aplicativo.',
'choose how durations are shown' => 'Escolha como as durações são exibidas.',
'choose whether to show vacation steps' => 'Escolha se deseja mostrar as etapas de férias.',
'choose your mode' => 'Escolha seu modo.',
'click "export" at the top of the table and choose "save as csv".' => 'Clique em "Exportar" no topo da tabela e escolha "Salvar como CSV".',
'clock (7:30)' => 'Relógio (7:30)',
'close' => 'Fechar',
'color' => 'Cor',
'confirm' => 'Confirmar',
Expand Down Expand Up @@ -89,6 +91,7 @@
'day' => 'Dia',
'day equivalent' => 'Equivalente em dias',
'days' => 'Dias',
'decimal hours (7.50)' => 'Horas decimais (7.50)',
'default annual entitlement' => 'Direito anual padrão',
'default overview' => 'Visão geral padrão',
'default: :value days' => 'Padrão: :value dias',
Expand Down Expand Up @@ -341,6 +344,7 @@
'this shortcut is not supported.' => 'Este atalho não é suportado.',
'time' => 'Tempo',
'time balance' => 'Saldo de Horas',
'time display' => 'Formato de tempo',
'time span' => 'Período de tempo',
'timezone' => 'Fuso Horário',
'to import data from clockify, you must first export it. Simply follow the step-by-step instructions below.' => 'Para importar dados do Clockify, você deve primeiro exportá-los. Basta seguir as instruções passo a passo abaixo.',
Expand Down
4 changes: 4 additions & 0 deletions lang/zh_CN/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@
'chinese' => '中文',
'choose how fractional days are rounded.' => '控制休假日的小数步长。',
'choose the appearance of the application.' => '选择应用程序的外观。',
'choose how durations are shown' => '选择时长的显示方式。',
'choose whether to show vacation steps' => '选择是否显示休假步骤。',
'choose your mode' => '选择你的模式。',
'click "export" at the top of the table and choose "save as csv".' => '点击表格上方的“导出”,然后选择“另存为 CSV”。',
'clock (7:30)' => '时钟格式 (7:30)',
'close' => '关闭',
'color' => '颜色',
'confirm' => '确认',
Expand Down Expand Up @@ -89,6 +91,7 @@
'day' => '天',
'day equivalent' => '折算天数',
'days' => '天',
'decimal hours (7.50)' => '十进制小时 (7.50)',
'default annual entitlement' => '默认年假配额',
'default overview' => '默认概览',
'default: :value days' => '默认值::value 天',
Expand Down Expand Up @@ -341,6 +344,7 @@
'this shortcut is not supported.' => '该快捷键不受支持。',
'time' => '时间',
'time balance' => '时间结余',
'time display' => '时间显示',
'time span' => '时间段',
'timezone' => '时区',
'to import data from clockify, you must first export it. Simply follow the step-by-step instructions below.' => '若要从 Clockify 导入数据,您必须先导出数据。只需遵循以下逐步指示即可。',
Expand Down
Loading