use BookStack\Entities\Models\Page;
use BookStack\Entities\Models\PageRevision;
+use BookStack\Util\DateFormatter;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Builder;
class PageEditActivity
{
- protected Page $page;
-
- /**
- * PageEditActivity constructor.
- */
- public function __construct(Page $page)
- {
- $this->page = $page;
+ public function __construct(
+ protected Page $page
+ ) {
}
/**
/**
* Get any editor clash warning messages to show for the given draft revision.
*
- * @param PageRevision|Page $draft
- *
* @return string[]
*/
- public function getWarningMessagesForDraft($draft): array
+ public function getWarningMessagesForDraft(Page|PageRevision $draft): array
{
$warnings = [];
*/
public function getEditingActiveDraftMessage(PageRevision $draft): string
{
- $message = trans('entities.pages_editing_draft_notification', ['timeDiff' => $draft->updated_at->diffForHumans()]);
+ $formatter = resolve(DateFormatter::class);
+ $message = trans('entities.pages_editing_draft_notification', ['timeDiff' => $formatter->relative($draft->updated_at)]);
if ($draft->page->updated_at->timestamp <= $draft->updated_at->timestamp) {
return $message;
}
namespace BookStack\Util;
use Carbon\Carbon;
+use Carbon\CarbonInterface;
class DateFormatter
{
) {
}
- public function isoWithTimezone(Carbon $date): string
+ public function absolute(Carbon $date): string
{
$withDisplayTimezone = $date->clone()->setTimezone($this->displayTimezone);
return $withDisplayTimezone->format('Y-m-d H:i:s T');
}
- public function relative(Carbon $date): string
+ public function relative(Carbon $date, bool $includeSuffix = true): string
{
- return $date->diffForHumans();
+ return $date->diffForHumans(null, $includeSuffix ? null : CarbonInterface::DIFF_ABSOLUTE);
}
}
<server name="APP_THEME" value="none"/>
<server name="APP_AUTO_LANG_PUBLIC" value="true"/>
<server name="APP_URL" value="http://bookstack.dev"/>
+ <server name="APP_TIMEZONE" value="UTC"/>
+ <server name="APP_DISPLAY_TIMEZONE" value="UTC"/>
<server name="ALLOWED_IFRAME_HOSTS" value=""/>
<server name="ALLOWED_IFRAME_SOURCES" value="https://*.draw.io https://*.youtube.com https://*.youtube-nocookie.com https://*.vimeo.com"/>
<server name="ALLOWED_SSR_HOSTS" value="*"/>
<div class="flex-container-row wrap items-center gap-x-xs">
@if ($comment->createdBy)
<div>
- <img width="50" src="{{ $comment->createdBy->getAvatar(50) }}" class="avatar block mr-xs" alt="{{ $comment->createdBy->name }}">
+ <img width="50" src="{{ $comment->createdBy->getAvatar(50) }}" class="avatar block mr-xs"
+ alt="{{ $comment->createdBy->name }}">
</div>
@endif
<div class="meta text-muted flex-container-row wrap items-center flex text-small">
@else
{{ trans('common.deleted_user') }}
@endif
- <span title="{{ $comment->created_at }}"> {{ trans('entities.comment_created', ['createDiff' => $comment->created_at->diffForHumans() ]) }}</span>
+ <span title="{{ $dates->absolute($comment->created_at) }}"> {{ trans('entities.comment_created', ['createDiff' => $dates->relative($comment->created_at) ]) }}</span>
@if($comment->isUpdated())
<span class="mx-xs">•</span>
- <span title="{{ trans('entities.comment_updated', ['updateDiff' => $comment->updated_at, 'username' => $comment->updatedBy->name ?? trans('common.deleted_user')]) }}">
+ <span title="{{ trans('entities.comment_updated', ['updateDiff' => $dates->absolute($comment->updated_at), 'username' => $comment->updatedBy->name ?? trans('common.deleted_user')]) }}">
{{ trans('entities.comment_updated_indicator') }}
</span>
@endif
</div>
<div class="right-meta flex-container-row justify-flex-end items-center px-s">
@if(!$readOnly && (userCan('comment-create-all') || userCan('comment-update', $comment) || userCan('comment-delete', $comment)))
- <div class="actions mr-s">
- @if(userCan('comment-create-all'))
- <button refs="page-comment@reply-button" type="button" class="text-button text-muted hover-underline text-small p-xs">@icon('reply') {{ trans('common.reply') }}</button>
- @endif
- @if(!$comment->parent_id && (userCan('comment-update', $comment) || userCan('comment-delete', $comment)))
- <button refs="page-comment@archive-button"
- type="button"
- data-is-archived="{{ $comment->archived ? 'true' : 'false' }}"
- class="text-button text-muted hover-underline text-small p-xs">@icon('archive') {{ trans('common.' . ($comment->archived ? 'unarchive' : 'archive')) }}</button>
- @endif
- @if(userCan('comment-update', $comment))
- <button refs="page-comment@edit-button" type="button" class="text-button text-muted hover-underline text-small p-xs">@icon('edit') {{ trans('common.edit') }}</button>
- @endif
- @if(userCan('comment-delete', $comment))
- <div component="dropdown" class="dropdown-container">
- <button type="button" refs="dropdown@toggle" aria-haspopup="true" aria-expanded="false" class="text-button text-muted hover-underline text-small p-xs">@icon('delete') {{ trans('common.delete') }}</button>
- <ul refs="dropdown@menu" class="dropdown-menu" role="menu">
- <li class="px-m text-small text-muted pb-s">{{trans('entities.comment_delete_confirm')}}</li>
- <li>
- <button refs="page-comment@delete-button" type="button" class="text-button text-neg icon-item">
- @icon('delete')
- <div>{{ trans('common.delete') }}</div>
- </button>
- </li>
- </ul>
- </div>
- @endif
- <span class="text-muted">
+ <div class="actions mr-s">
+ @if(userCan('comment-create-all'))
+ <button refs="page-comment@reply-button" type="button"
+ class="text-button text-muted hover-underline text-small p-xs">@icon('reply') {{ trans('common.reply') }}</button>
+ @endif
+ @if(!$comment->parent_id && (userCan('comment-update', $comment) || userCan('comment-delete', $comment)))
+ <button refs="page-comment@archive-button"
+ type="button"
+ data-is-archived="{{ $comment->archived ? 'true' : 'false' }}"
+ class="text-button text-muted hover-underline text-small p-xs">@icon('archive') {{ trans('common.' . ($comment->archived ? 'unarchive' : 'archive')) }}</button>
+ @endif
+ @if(userCan('comment-update', $comment))
+ <button refs="page-comment@edit-button" type="button"
+ class="text-button text-muted hover-underline text-small p-xs">@icon('edit') {{ trans('common.edit') }}</button>
+ @endif
+ @if(userCan('comment-delete', $comment))
+ <div component="dropdown" class="dropdown-container">
+ <button type="button" refs="dropdown@toggle" aria-haspopup="true" aria-expanded="false"
+ class="text-button text-muted hover-underline text-small p-xs">@icon('delete') {{ trans('common.delete') }}</button>
+ <ul refs="dropdown@menu" class="dropdown-menu" role="menu">
+ <li class="px-m text-small text-muted pb-s">{{trans('entities.comment_delete_confirm')}}</li>
+ <li>
+ <button refs="page-comment@delete-button" type="button"
+ class="text-button text-neg icon-item">
+ @icon('delete')
+ <div>{{ trans('common.delete') }}</div>
+ </button>
+ </li>
+ </ul>
+ </div>
+ @endif
+ <span class="text-muted">
•
</span>
- </div>
+ </div>
@endif
<div>
- <a class="bold text-muted text-small" href="#comment{{$comment->local_id}}">#{{$comment->local_id}}</a>
+ <a class="bold text-muted text-small"
+ href="#comment{{$comment->local_id}}">#{{$comment->local_id}}</a>
</div>
</div>
</div>
<div refs="page-comment@content-container" class="content">
@if ($comment->parent_id)
<p class="comment-reply">
- <a class="text-muted text-small" href="#comment{{ $comment->parent_id }}">@icon('reply'){{ trans('entities.comment_in_reply_to', ['commentId' => '#' . $comment->parent_id]) }}</a>
+ <a class="text-muted text-small"
+ href="#comment{{ $comment->parent_id }}">@icon('reply'){{ trans('entities.comment_in_reply_to', ['commentId' => '#' . $comment->parent_id]) }}</a>
</p>
@endif
@if($comment->content_ref)
option:page-comment-reference:view-comment-text="{{ trans('entities.comment_view') }}"
option:page-comment-reference:jump-to-thread-text="{{ trans('entities.comment_jump_to_thread') }}"
option:page-comment-reference:close-text="{{ trans('common.close') }}"
- href="#">@icon('bookmark'){{ trans('entities.comment_reference') }} <span>{{ trans('entities.comment_reference_outdated') }}</span></a>
+ href="#">@icon('bookmark'){{ trans('entities.comment_reference') }}
+ <span>{{ trans('entities.comment_reference_outdated') }}</span></a>
</div>
@endif
{!! $commentHtml !!}
@if(!$readOnly && userCan('comment-update', $comment))
<form novalidate refs="page-comment@form" hidden class="content pt-s px-s block">
<div class="form-group description-input">
- <textarea refs="page-comment@input" name="html" rows="3" placeholder="{{ trans('entities.comment_placeholder') }}">{{ $commentHtml }}</textarea>
+ <textarea refs="page-comment@input" name="html" rows="3"
+ placeholder="{{ trans('entities.comment_placeholder') }}">{{ $commentHtml }}</textarea>
</div>
<div class="form-group text-right">
- <button type="button" class="button outline" refs="page-comment@form-cancel">{{ trans('common.cancel') }}</button>
+ <button type="button" class="button outline"
+ refs="page-comment@form-cancel">{{ trans('common.cancel') }}</button>
<button type="submit" class="button">{{ trans('entities.comment_save') }}</button>
</div>
</form>
<br>
- <span class="text-muted"><small>@icon('time'){{ $activity->created_at->diffForHumans() }}</small></span>
+ <span class="text-muted" title="{{ $dates->absolute($activity->created_at) }}"><small>@icon('time'){{ $dates->relative($activity->created_at) }}</small></span>
</div>
<p class="text-muted">{{ $entity->getExcerpt(130) }}</p>
</div>
<div class="grid-card-footer text-muted ">
- <p>@icon('star')<span title="{{ $entity->created_at->toDayDateTimeString() }}">{{ trans('entities.meta_created', ['timeLength' => $entity->created_at->diffForHumans()]) }}</span></p>
- <p>@icon('edit')<span title="{{ $entity->updated_at->toDayDateTimeString() }}">{{ trans('entities.meta_updated', ['timeLength' => $entity->updated_at->diffForHumans()]) }}</span></p>
+ <p>@icon('star')<span title="{{ $dates->absolute($entity->created_at) }}">{{ trans('entities.meta_created', ['timeLength' => $dates->relative($entity->created_at)]) }}</span></p>
+ <p>@icon('edit')<span title="{{ $dates->absolute($entity->updated_at) }}">{{ trans('entities.meta_updated', ['timeLength' => $dates->relative($entity->updated_at)]) }}</span></p>
</div>
</a>
\ No newline at end of file
@endif
@if(($showUpdatedBy ?? false) && $entity->relationLoaded('updatedBy') && $entity->updatedBy)
- <small title="{{ $entity->updated_at->toDayDateTimeString() }}">
+ <small title="{{ $dates->absolute($entity->updated_at) }}">
{!! trans('entities.meta_updated_name', [
- 'timeLength' => $entity->updated_at->diffForHumans(),
+ 'timeLength' => $dates->relative($entity->updated_at),
'user' => e($entity->updatedBy->name)
]) !!}
</small>
@icon('star')
<div>
{!! trans('entities.meta_created_name', [
- 'timeLength' => '<span title="'. $dates->isoWithTimezone($entity->created_at) .'">'. $dates->relative($entity->created_at) . '</span>',
+ 'timeLength' => '<span title="'. $dates->absolute($entity->created_at) .'">'. $dates->relative($entity->created_at) . '</span>',
'user' => "<a href='{$entity->createdBy->getProfileUrl()}'>".e($entity->createdBy->name). "</a>"
]) !!}
</div>
@else
<div class="entity-meta-item">
@icon('star')
- <span title="{{ $dates->isoWithTimezone($entity->created_at) }}">{{ trans('entities.meta_created', ['timeLength' => $dates->relative($entity->created_at)]) }}</span>
+ <span title="{{ $dates->absolute($entity->created_at) }}">{{ trans('entities.meta_created', ['timeLength' => $dates->relative($entity->created_at)]) }}</span>
</div>
@endif
@icon('edit')
<div>
{!! trans('entities.meta_updated_name', [
- 'timeLength' => '<span title="' . $dates->isoWithTimezone($entity->updated_at) .'">' . $dates->relative($entity->updated_at) .'</span>',
+ 'timeLength' => '<span title="' . $dates->absolute($entity->updated_at) .'">' . $dates->relative($entity->updated_at) .'</span>',
'user' => "<a href='{$entity->updatedBy->getProfileUrl()}'>".e($entity->updatedBy->name). "</a>"
]) !!}
</div>
@elseif (!$entity->isA('revision'))
<div class="entity-meta-item">
@icon('edit')
- <span title="{{ $dates->isoWithTimezone($entity->updated_at) }}">{{ trans('entities.meta_updated', ['timeLength' => $dates->relative($entity->updated_at)]) }}</span>
+ <span title="{{ $dates->absolute($entity->updated_at) }}">{{ trans('entities.meta_updated', ['timeLength' => $dates->relative($entity->updated_at)]) }}</span>
</div>
@endif
</div>
<div class="text-right text-muted">
<div>{{ trans('entities.import_size', ['size' => $import->getSizeString()]) }}</div>
- <div><span title="{{ $import->created_at->toISOString() }}">{{ trans('entities.import_uploaded_at', ['relativeTime' => $import->created_at->diffForHumans()]) }}</span></div>
+ <div><span title="{{ $dates->absolute($import->created_at) }}">{{ trans('entities.import_uploaded_at', ['relativeTime' => $dates->relative($import->created_at)]) }}</span></div>
@if($import->createdBy)
<div>
{{ trans('entities.import_uploaded_by') }}
</div>
<div class="px-m py-s flex-container-row gap-m items-center">
<div class="bold opacity-80 text-muted">{{ $import->getSizeString() }}</div>
- <div class="bold opacity-80 text-muted min-width-xs text-right" title="{{ $import->created_at->toISOString() }}">@icon('time'){{ $import->created_at->diffForHumans() }}</div>
+ <div class="bold opacity-80 text-muted min-width-xs text-right" title="{{ $dates->absolute($import->created_at) }}">@icon('time'){{ $dates->relative($import->created_at) }}</div>
</div>
</div>
\ No newline at end of file
@endif
@icon('star'){!! trans('entities.meta_created' . ($entity->createdBy ? '_name' : ''), [
- 'timeLength' => $entity->created_at->isoFormat('D MMMM Y HH:mm:ss'),
+ 'timeLength' => $dates->absolute($entity->created_at),
'user' => e($entity->createdBy->name ?? ''),
]) !!}
<br>
@icon('edit'){!! trans('entities.meta_updated' . ($entity->updatedBy ? '_name' : ''), [
- 'timeLength' => $entity->updated_at->isoFormat('D MMMM Y HH:mm:ss'),
+ 'timeLength' => $dates->absolute($entity->updated_at),
'user' => e($entity->updatedBy->name ?? '')
]) !!}
</div>
\ No newline at end of file
<div class="text-muted text-small">
<hr class="my-m">
- <div title="{{ $image->created_at->format('Y-m-d H:i:s') }}">
- @icon('star') {{ trans('components.image_uploaded', ['uploadedDate' => $image->created_at->diffForHumans()]) }}
+ <div title="{{ $dates->absolute($image->created_at) }}">
+ @icon('star') {{ trans('components.image_uploaded', ['uploadedDate' => $dates->relative($image->created_at)]) }}
</div>
@if($image->created_at->valueOf() !== $image->updated_at->valueOf())
- <div title="{{ $image->updated_at->format('Y-m-d H:i:s') }}">
- @icon('edit') {{ trans('components.image_updated', ['updateDate' => $image->updated_at->diffForHumans()]) }}
+ <div title="{{ $dates->absolute($image->updated_at) }}">
+ @icon('edit') {{ trans('components.image_updated', ['updateDate' => $dates->relative($image->updated_at)]) }}
</div>
@endif
@if($image->createdBy)
@if($revision->createdBy) {{ $revision->createdBy->name }} @else {{ trans('common.deleted_user') }} @endif
<br>
<div class="text-muted">
- <small>{{ $revision->created_at->isoFormat('D MMMM Y HH:mm:ss') }}</small>
- <small>({{ $revision->created_at->diffForHumans() }})</small>
+ <small>{{ $dates->absolute($revision->created_at) }}</small>
+ <small>({{ $dates->relative($revision->created_at) }})</small>
</div>
</div>
</div>
draggable="true" template-id="{{ $template->id }}">
<div class="template-item-content" title="{{ trans('entities.templates_replace_content') }}">
<div>{{ $template->name }}</div>
- <div class="text-muted">{{ trans('entities.meta_updated', ['timeLength' => $template->updated_at->diffForHumans()]) }}</div>
+ <div class="text-muted" title="{{ $dates->absolute($template->updated_at) }}">{{ trans('entities.meta_updated', ['timeLength' => $dates->relative($template->updated_at)]) }}</div>
</div>
<div class="template-item-actions">
<button type="button"
<div>
<label class="setting-list-label">{{ trans('settings.webhooks_status') }}</label>
<p class="mb-none">
- {{ trans('settings.webhooks_last_called') }} {{ $webhook->last_called_at ? $webhook->last_called_at->diffForHumans() : trans('common.never') }}
+ @if($webhook->last_called_at)
+ <span title="{{ $dates->absolute($webhook->last_called_at) }}">{{ trans('settings.webhooks_last_called') }} {{ $dates->relative($webhook->last_called_at) }}</span>
+ @else
+ <span>{{ trans('settings.webhooks_last_called') }} {{ trans('common.never') }}</span>
+ @endif
<br>
- {{ trans('settings.webhooks_last_errored') }} {{ $webhook->last_errored_at ? $webhook->last_errored_at->diffForHumans() : trans('common.never') }}
+ @if($webhook->last_errored_at)
+ <span title="{{ $dates->absolute($webhook->last_errored_at) }}">{{ trans('settings.webhooks_last_errored') }} {{ $dates->relative($webhook->last_errored_at) }}</span>
+ @else
+ <span>{{ trans('settings.webhooks_last_errored') }} {{ trans('common.never') }}</span>
+ @endif
</p>
</div>
<div class="text-muted">
<div class="grid half gap-xl v-center">
<div class="text-muted text-small">
- <span title="{{ $token->created_at }}">
- {{ trans('settings.user_api_token_created', ['timeAgo' => $token->created_at->diffForHumans()]) }}
+ <span title="{{ $dates->absolute($token->created_at) }}">
+ {{ trans('settings.user_api_token_created', ['timeAgo' => $dates->relative($token->created_at)]) }}
</span>
<br>
- <span title="{{ $token->updated_at }}">
- {{ trans('settings.user_api_token_updated', ['timeAgo' => $token->created_at->diffForHumans()]) }}
+ <span title="{{ $dates->absolute($token->updated_at) }}">
+ {{ trans('settings.user_api_token_updated', ['timeAgo' => $dates->relative($token->created_at)]) }}
</span>
</div>
@if($user->last_activity_at)
<small>{{ trans('settings.users_latest_activity') }}</small>
<br>
- <small title="{{ $user->last_activity_at->format('Y-m-d H:i:s') }}">{{ $user->last_activity_at->diffForHumans() }}</small>
+ <small title="{{ $dates->absolute($user->last_activity_at) }}">{{ $dates->relative($user->last_activity_at) }}</small>
@endif
</div>
</div>
<div>
<h4 class="mt-md">{{ $user->name }}</h4>
<p class="text-muted">
- {{ trans('entities.profile_user_for_x', ['time' => $user->created_at->diffForHumans(null, true)]) }}
+ {{ trans('entities.profile_user_for_x', ['time' => $dates->relative($user->created_at, false)]) }}
</p>
</div>
</div>
$page = $this->entities->page();
$resp = $this->asEditor()->get($page->getUrl('/export/html'));
- $resp->assertSee($page->created_at->isoFormat('D MMMM Y HH:mm:ss'));
+ $resp->assertSee($page->created_at->format('Y-m-d H:i:s T'));
$resp->assertDontSee($page->created_at->diffForHumans());
- $resp->assertSee($page->updated_at->isoFormat('D MMMM Y HH:mm:ss'));
+ $resp->assertSee($page->updated_at->format('Y-m-d H:i:s T'));
$resp->assertDontSee($page->updated_at->diffForHumans());
}
$formatter = new DateFormatter('Europe/London');
$dateTime = new Carbon('2020-06-01 12:00:00', 'UTC');
- $result = $formatter->isoWithTimezone($dateTime);
+ $result = $formatter->absolute($dateTime);
$this->assertEquals('2020-06-01 13:00:00 BST', $result);
}
$formatter = new DateFormatter('Asia/Shanghai');
$dateTime = new Carbon('2025-06-10 15:25:00', 'America/New_York');
- $result = $formatter->isoWithTimezone($dateTime);
+ $result = $formatter->absolute($dateTime);
$this->assertEquals('2025-06-11 03:25:00 CST', $result);
}