Add timestamp to all announcements in Web UI (#18329)
This commit is contained in:
parent
c6c8e7e6ab
commit
a8b2b474d7
1 changed files with 17 additions and 3 deletions
|
@ -335,15 +335,29 @@ class Announcement extends ImmutablePureComponent {
|
||||||
const endsAt = announcement.get('ends_at') && new Date(announcement.get('ends_at'));
|
const endsAt = announcement.get('ends_at') && new Date(announcement.get('ends_at'));
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const hasTimeRange = startsAt && endsAt;
|
const hasTimeRange = startsAt && endsAt;
|
||||||
const skipYear = hasTimeRange && startsAt.getFullYear() === endsAt.getFullYear() && endsAt.getFullYear() === now.getFullYear();
|
|
||||||
const skipEndDate = hasTimeRange && startsAt.getDate() === endsAt.getDate() && startsAt.getMonth() === endsAt.getMonth() && startsAt.getFullYear() === endsAt.getFullYear();
|
|
||||||
const skipTime = announcement.get('all_day');
|
const skipTime = announcement.get('all_day');
|
||||||
|
|
||||||
|
let timestamp = null;
|
||||||
|
if (hasTimeRange) {
|
||||||
|
const skipYear = startsAt.getFullYear() === endsAt.getFullYear() && endsAt.getFullYear() === now.getFullYear();
|
||||||
|
const skipEndDate = startsAt.getDate() === endsAt.getDate() && startsAt.getMonth() === endsAt.getMonth() && startsAt.getFullYear() === endsAt.getFullYear();
|
||||||
|
timestamp = (
|
||||||
|
<>
|
||||||
|
<FormattedDate value={startsAt} year={(skipYear || startsAt.getFullYear() === now.getFullYear()) ? undefined : 'numeric'} month='short' day='2-digit' hour={skipTime ? undefined : '2-digit'} minute={skipTime ? undefined : '2-digit'} /> - <FormattedDate value={endsAt} year={(skipYear || endsAt.getFullYear() === now.getFullYear()) ? undefined : 'numeric'} month={skipEndDate ? undefined : 'short'} day={skipEndDate ? undefined : '2-digit'} hour={skipTime ? undefined : '2-digit'} minute={skipTime ? undefined : '2-digit'} />
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
const publishedAt = new Date(announcement.get('published_at'));
|
||||||
|
timestamp = (
|
||||||
|
<FormattedDate value={publishedAt} year={publishedAt.getFullYear() === now.getFullYear() ? undefined : 'numeric'} month='short' day='2-digit' hour={skipTime ? undefined : '2-digit'} minute={skipTime ? undefined : '2-digit'} />
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='announcements__item'>
|
<div className='announcements__item'>
|
||||||
<strong className='announcements__item__range'>
|
<strong className='announcements__item__range'>
|
||||||
<FormattedMessage id='announcement.announcement' defaultMessage='Announcement' />
|
<FormattedMessage id='announcement.announcement' defaultMessage='Announcement' />
|
||||||
{hasTimeRange && <span> · <FormattedDate value={startsAt} year={(skipYear || startsAt.getFullYear() === now.getFullYear()) ? undefined : 'numeric'} month='short' day='2-digit' hour={skipTime ? undefined : '2-digit'} minute={skipTime ? undefined : '2-digit'} /> - <FormattedDate value={endsAt} year={(skipYear || endsAt.getFullYear() === now.getFullYear()) ? undefined : 'numeric'} month={skipEndDate ? undefined : 'short'} day={skipEndDate ? undefined : '2-digit'} hour={skipTime ? undefined : '2-digit'} minute={skipTime ? undefined : '2-digit'} /></span>}
|
<span> · {timestamp}</span>
|
||||||
</strong>
|
</strong>
|
||||||
|
|
||||||
<Content announcement={announcement} />
|
<Content announcement={announcement} />
|
||||||
|
|
Loading…
Reference in a new issue