mirror of
https://github.com/mastodon/mastodon.git
synced 2024-12-18 15:48:22 +00:00
Change last_status_at to be a date, not datetime (#12966)
* Return last_status_at as date, not datetime * Fix relative timestamp for dates when delay is inferior to 1 day * Also fix public directory * Fix error when last_status_at isn't set
This commit is contained in:
parent
401f32f9ee
commit
42d2a915e4
|
@ -3,6 +3,7 @@ import { injectIntl, defineMessages } from 'react-intl';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
const messages = defineMessages({
|
const messages = defineMessages({
|
||||||
|
today: { id: 'relative_time.today', defaultMessage: 'today' },
|
||||||
just_now: { id: 'relative_time.just_now', defaultMessage: 'now' },
|
just_now: { id: 'relative_time.just_now', defaultMessage: 'now' },
|
||||||
seconds: { id: 'relative_time.seconds', defaultMessage: '{number}s' },
|
seconds: { id: 'relative_time.seconds', defaultMessage: '{number}s' },
|
||||||
minutes: { id: 'relative_time.minutes', defaultMessage: '{number}m' },
|
minutes: { id: 'relative_time.minutes', defaultMessage: '{number}m' },
|
||||||
|
@ -65,12 +66,14 @@ const getUnitDelay = units => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const timeAgoString = (intl, date, now, year) => {
|
export const timeAgoString = (intl, date, now, year, timeGiven = true) => {
|
||||||
const delta = now - date.getTime();
|
const delta = now - date.getTime();
|
||||||
|
|
||||||
let relativeTime;
|
let relativeTime;
|
||||||
|
|
||||||
if (delta < 10 * SECOND) {
|
if (delta < DAY && !timeGiven) {
|
||||||
|
relativeTime = intl.formatMessage(messages.today);
|
||||||
|
} else if (delta < 10 * SECOND) {
|
||||||
relativeTime = intl.formatMessage(messages.just_now);
|
relativeTime = intl.formatMessage(messages.just_now);
|
||||||
} else if (delta < 7 * DAY) {
|
} else if (delta < 7 * DAY) {
|
||||||
if (delta < MINUTE) {
|
if (delta < MINUTE) {
|
||||||
|
@ -91,12 +94,14 @@ export const timeAgoString = (intl, date, now, year) => {
|
||||||
return relativeTime;
|
return relativeTime;
|
||||||
};
|
};
|
||||||
|
|
||||||
const timeRemainingString = (intl, date, now) => {
|
const timeRemainingString = (intl, date, now, timeGiven = true) => {
|
||||||
const delta = date.getTime() - now;
|
const delta = date.getTime() - now;
|
||||||
|
|
||||||
let relativeTime;
|
let relativeTime;
|
||||||
|
|
||||||
if (delta < 10 * SECOND) {
|
if (delta < DAY && !timeGiven) {
|
||||||
|
relativeTime = intl.formatMessage(messages.today);
|
||||||
|
} else if (delta < 10 * SECOND) {
|
||||||
relativeTime = intl.formatMessage(messages.moments_remaining);
|
relativeTime = intl.formatMessage(messages.moments_remaining);
|
||||||
} else if (delta < MINUTE) {
|
} else if (delta < MINUTE) {
|
||||||
relativeTime = intl.formatMessage(messages.seconds_remaining, { number: Math.floor(delta / SECOND) });
|
relativeTime = intl.formatMessage(messages.seconds_remaining, { number: Math.floor(delta / SECOND) });
|
||||||
|
@ -173,8 +178,9 @@ class RelativeTimestamp extends React.Component {
|
||||||
render () {
|
render () {
|
||||||
const { timestamp, intl, year, futureDate } = this.props;
|
const { timestamp, intl, year, futureDate } = this.props;
|
||||||
|
|
||||||
|
const timeGiven = timestamp.includes('T');
|
||||||
const date = new Date(timestamp);
|
const date = new Date(timestamp);
|
||||||
const relativeTime = futureDate ? timeRemainingString(intl, date, this.state.now) : timeAgoString(intl, date, this.state.now, year);
|
const relativeTime = futureDate ? timeRemainingString(intl, date, this.state.now, timeGiven) : timeAgoString(intl, date, this.state.now, year, timeGiven);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<time dateTime={timestamp} title={intl.formatDate(date, dateFormatOptions)}>
|
<time dateTime={timestamp} title={intl.formatDate(date, dateFormatOptions)}>
|
||||||
|
|
|
@ -55,4 +55,8 @@ class REST::AccountSerializer < ActiveModel::Serializer
|
||||||
def moved_and_not_nested?
|
def moved_and_not_nested?
|
||||||
object.moved? && object.moved_to_account.moved_to_account_id.nil?
|
object.moved? && object.moved_to_account.moved_to_account_id.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def last_status_at
|
||||||
|
object.last_status_at&.to_date&.iso8601
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -47,7 +47,7 @@
|
||||||
%small= t('accounts.followers', count: account.followers_count).downcase
|
%small= t('accounts.followers', count: account.followers_count).downcase
|
||||||
.accounts-table__count
|
.accounts-table__count
|
||||||
- if account.last_status_at.present?
|
- if account.last_status_at.present?
|
||||||
%time.time-ago{ datetime: account.last_status_at.iso8601, title: l(account.last_status_at) }= l account.last_status_at
|
%time.time-ago{ datetime: account.last_status_at.to_date.iso8601, title: l(account.last_status_at.to_date) }= l account.last_status_at.to_date
|
||||||
- else
|
- else
|
||||||
= t('accounts.never_active')
|
= t('accounts.never_active')
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
%small= t('accounts.followers', count: account.followers_count).downcase
|
%small= t('accounts.followers', count: account.followers_count).downcase
|
||||||
%td.accounts-table__count
|
%td.accounts-table__count
|
||||||
- if account.last_status_at.present?
|
- if account.last_status_at.present?
|
||||||
%time.time-ago{ datetime: account.last_status_at.iso8601, title: l(account.last_status_at) }= l account.last_status_at
|
%time.time-ago{ datetime: account.last_status_at.to_date.iso8601, title: l(account.last_status_at.to_date) }= l account.last_status_at
|
||||||
- else
|
- else
|
||||||
\-
|
\-
|
||||||
%small= t('accounts.last_active')
|
%small= t('accounts.last_active')
|
||||||
|
|
Loading…
Reference in a new issue