resolved timezones

This commit is contained in:
Čarodej
2022-02-06 14:26:42 +01:00
parent 38e86b4b8b
commit 21e184f373
10 changed files with 37 additions and 54 deletions
+1 -1
View File
@@ -667,7 +667,7 @@ return [
'app_description' => 'Your self-hosted storage cloud software powered by Laravel and Vue', 'app_description' => 'Your self-hosted storage cloud software powered by Laravel and Vue',
'user_not_fount' => 'We can\'t find a user with that e-mail address.', 'user_not_fount' => 'We can\'t find a user with that e-mail address.',
'incorrect_password' => 'Sorry, your password is incorrect.', 'incorrect_password' => 'Sorry, your password is incorrect.',
'time' => '%d. %B. %Y at %H:%M', 'time' => 'd. M. Y, h:i',
'home' => 'Home', 'home' => 'Home',
'shared_link_email_subject' => '🙋 :user share some files with you. Look at it!', 'shared_link_email_subject' => '🙋 :user share some files with you. Look at it!',
'shared_link_email_greeting' => 'Hello!', 'shared_link_email_greeting' => 'Hello!',
+2 -2
View File
@@ -37,8 +37,8 @@ class UserResource extends JsonResource
'two_factor_authentication' => $this->two_factor_secret ? true : false, 'two_factor_authentication' => $this->two_factor_secret ? true : false,
'socialite_account' => $this->password ? false : true, 'socialite_account' => $this->password ? false : true,
'storage' => $this->storage, 'storage' => $this->storage,
'created_at' => format_date($this->created_at, '%d. %b. %Y'), 'created_at' => format_date($this->created_at, 'd. M. Y'),
'updated_at' => format_date($this->updated_at, '%d. %B. %Y'), 'updated_at' => format_date($this->updated_at, 'd. M. Y'),
], ],
'relationships' => [ 'relationships' => [
'settings' => new SettingsResource($this->settings), 'settings' => new SettingsResource($this->settings),
@@ -133,13 +133,13 @@ class UserStorageResource extends JsonResource
->get(); ->get();
$upload = $trafficRecords->map(fn ($record) => [ $upload = $trafficRecords->map(fn ($record) => [
'created_at' => format_date($record->created_at, '%d. %B'), 'created_at' => format_date($record->created_at, 'd. M. '),
'percentage' => $uploadMax !== 0 ? round(($record->upload / $uploadMax) * 100, 2) : 0, 'percentage' => $uploadMax !== 0 ? round(($record->upload / $uploadMax) * 100, 2) : 0,
'amount' => Metric::bytes($record->upload)->format(), 'amount' => Metric::bytes($record->upload)->format(),
]); ]);
$download = $trafficRecords->map(fn ($record) => [ $download = $trafficRecords->map(fn ($record) => [
'created_at' => format_date($record->created_at, '%d. %B'), 'created_at' => format_date($record->created_at, 'd. M. '),
'percentage' => $downloadMax !== 0 ? round(($record->download / $downloadMax) * 100, 2) : 0, 'percentage' => $downloadMax !== 0 ? round(($record->download / $downloadMax) * 100, 2) : 0,
'amount' => Metric::bytes($record->download)->format(), 'amount' => Metric::bytes($record->download)->format(),
]); ]);
+3 -3
View File
@@ -32,9 +32,9 @@ class UserSubscription extends JsonResource
'capacity' => (int) $subscription['product']['metadata']['capacity'], 'capacity' => (int) $subscription['product']['metadata']['capacity'],
'capacity_formatted' => format_gigabytes($subscription['product']['metadata']['capacity']), 'capacity_formatted' => format_gigabytes($subscription['product']['metadata']['capacity']),
'slug' => $subscription['plan']['id'], 'slug' => $subscription['plan']['id'],
'canceled_at' => format_date($active_subscription['canceled_at'], '%d. %B. %Y'), 'canceled_at' => format_date($active_subscription['canceled_at'], 'd. M. Y'),
'created_at' => format_date($active_subscription['current_period_start'], '%d. %B. %Y'), 'created_at' => format_date($active_subscription['current_period_start'], 'd. M. Y'),
'ends_at' => format_date($active_subscription['current_period_end'], '%d. %B. %Y'), 'ends_at' => format_date($active_subscription['current_period_end'], 'd. M. Y'),
], ],
], ],
]; ];
@@ -66,13 +66,13 @@ class GetDashboardDataController extends Controller
->get(); ->get();
$upload = $trafficRecords->map(fn ($record) => [ $upload = $trafficRecords->map(fn ($record) => [
'created_at' => format_date($record->created_at, '%d. %B'), 'created_at' => format_date($record->created_at, 'd. M. '),
'percentage' => intval($trafficRecords->max('upload')) !== 0 ? round(($record->upload / $trafficRecords->max('upload')) * 100, 2) : 0, 'percentage' => intval($trafficRecords->max('upload')) !== 0 ? round(($record->upload / $trafficRecords->max('upload')) * 100, 2) : 0,
'amount' => Metric::bytes($record->upload)->format(), 'amount' => Metric::bytes($record->upload)->format(),
]); ]);
$download = $trafficRecords->map(fn ($record) => [ $download = $trafficRecords->map(fn ($record) => [
'created_at' => format_date($record->created_at, '%d. %B'), 'created_at' => format_date($record->created_at, 'd. M. '),
'percentage' => intval($trafficRecords->max('download')) !== 0 ? round(($record->download / $trafficRecords->max('download')) * 100, 2) : 0, 'percentage' => intval($trafficRecords->max('download')) !== 0 ? round(($record->download / $trafficRecords->max('download')) * 100, 2) : 0,
'amount' => Metric::bytes($record->download)->format(), 'amount' => Metric::bytes($record->download)->format(),
]); ]);
+5 -9
View File
@@ -33,15 +33,11 @@ class FileResource extends JsonResource
'thumbnail' => $this->thumbnail, 'thumbnail' => $this->thumbnail,
'metadata' => $this->metadata, 'metadata' => $this->metadata,
'parent_id' => $this->parent_id, 'parent_id' => $this->parent_id,
'updated_at' => $this->updated_at, 'created_at' => set_time_by_user_timezone($this->owner, $this->created_at),
'created_at' => Carbon::parse($this->created_at)->diffForHumans(), 'updated_at' => set_time_by_user_timezone($this->owner, $this->updated_at),
'deleted_at' => $this->deleted_at ? Carbon::parse($this->deleted_at)->diffForHumans() : null, 'deleted_at' => $this->deleted_at
/*'updated_at' => format_date( ? set_time_by_user_timezone($this->owner, $this->deleted_at)
set_time_by_user_timezone($this->updated_at), __t('time') : null,
),
'created_at' => format_date(
set_time_by_user_timezone($this->created_at), __t('time')
),*/
], ],
'relationships' => [ 'relationships' => [
$this->mergeWhen($this->shared, fn () => [ $this->mergeWhen($this->shared, fn () => [
@@ -24,15 +24,11 @@ class FolderResource extends JsonResource
'isTeamFolder' => $this->team_folder, 'isTeamFolder' => $this->team_folder,
'items' => $this->items, 'items' => $this->items,
'trashed_items' => $this->trashed_items, 'trashed_items' => $this->trashed_items,
'updated_at' => $this->updated_at, 'created_at' => set_time_by_user_timezone($this->owner, $this->created_at),
'created_at' => Carbon::parse($this->created_at)->diffForHumans(), 'updated_at' => set_time_by_user_timezone($this->owner, $this->updated_at),
'deleted_at' => $this->deleted_at ? Carbon::parse($this->deleted_at)->diffForHumans() : null, 'deleted_at' => $this->deleted_at
/*'updated_at' => format_date( ? set_time_by_user_timezone($this->owner, $this->deleted_at)
set_time_by_user_timezone($this->updated_at), __t('time') : null,
),
'created_at' => format_date(
set_time_by_user_timezone($this->created_at), __t('time')
),*/
], ],
'relationships' => [ 'relationships' => [
$this->mergeWhen($this->teamMembers, fn () => [ $this->mergeWhen($this->teamMembers, fn () => [
@@ -30,7 +30,7 @@ class TransactionResource extends JsonResource
'metadata' => $this->metadata 'metadata' => $this->metadata
? resolve(FormatUsageEstimatesAction::class)($this->currency, $this->metadata) ? resolve(FormatUsageEstimatesAction::class)($this->currency, $this->metadata)
: null, : null,
'created_at' => $this->created_at->formatLocalized('%d. %b. %Y'), 'created_at' => $this->created_at->formatLocalized('d. M. Y'),
'updated_at' => $this->updated_at, 'updated_at' => $this->updated_at,
], ],
'relationships' => [ 'relationships' => [
+7 -15
View File
@@ -580,16 +580,12 @@ if (! function_exists('filter_folders_ids')) {
if (! function_exists('format_date')) { if (! function_exists('format_date')) {
/** /**
* Format localized date * Format localized date
*
* @param $date
* @param string $format
* @return string
*/ */
function format_date($date, $format = '%d. %B. %Y, %H:%M') function format_date($date, string $format = 'd. M. Y, h:i'): string
{ {
$start = Carbon::parse($date); $start = Carbon::parse($date);
return $start->formatLocalized($format); return $start->translatedFormat($format);
} }
} }
@@ -949,17 +945,13 @@ if (! function_exists('set_time_by_user_timezone')) {
/** /**
* Set time by user timezone GMT * Set time by user timezone GMT
*/ */
function set_time_by_user_timezone(string $time): string | Carbon function set_time_by_user_timezone($user, $createdAt): string | Carbon
{ {
$user = Auth::user(); $timezone = $user->settings->timezone ?? 0;
if ($user) { return Carbon::parse($createdAt)
$time_zone = $user->settings->timezone ?? 0; ->addMinutes($timezone * 60)
->translatedFormat('d. M. Y, h:i');
return Carbon::parse($time)->addMinutes($time_zone * 60);
}
return $time;
} }
} }
+9 -10
View File
@@ -35,28 +35,27 @@ class UserAccountTest extends TestCase
} }
/** /**
* todo: finish test * @test
*/ */
public function it_test_user_timezone() public function it_test_user_timezone()
{ {
$user = User::factory() $user = User::factory()
->create(['role' => 'user']); ->hasSettings([
'timezone' => '2.0',
])
->create();
Folder::factory(Folder::class) Folder::factory()
->create([ ->create([
'user_id' => $user->id, 'user_id' => $user->id,
'created_at' => now(), 'created_at' => now(),
]); ]);
$user->settings()->update([
'timezone' => '2.0',
]);
$this $this
->actingAs($user) ->actingAs($user)
->getJson('/api/browse/folders/undefined') ->getJson('/api/browse/folders/undefined')
->assertJsonFragment([ ->assertJsonFragment([
'created_at' => '01. January. 2021 at 02:00', 'created_at' => '01. Jan. 2021, 02:00',
]); ]);
} }
@@ -167,8 +166,8 @@ class UserAccountTest extends TestCase
'capacity' => '1', 'capacity' => '1',
'capacity_formatted' => '1GB', 'capacity_formatted' => '1GB',
], ],
'created_at' => format_date($user->created_at, '%d. %b. %Y'), 'created_at' => format_date($user->created_at, 'd. M. Y'),
'updated_at' => format_date($user->updated_at, '%d. %B. %Y'), 'updated_at' => format_date($user->updated_at, 'd. M. Y'),
], ],
'meta' => [ 'meta' => [
'restrictions' => [ 'restrictions' => [