Skip to content

Commit

Permalink
fix: Display year when date is outside of current year (#567)
Browse files Browse the repository at this point in the history
  • Loading branch information
eternity1984 committed Dec 20, 2023
1 parent da63598 commit 920f9c0
Show file tree
Hide file tree
Showing 21 changed files with 60 additions and 4 deletions.
3 changes: 2 additions & 1 deletion client/src/components/CardModal/Activities/Item.jsx
Expand Up @@ -4,6 +4,7 @@ import classNames from 'classnames';
import { useTranslation, Trans } from 'react-i18next';
import { Comment } from 'semantic-ui-react';

import getDateFormat from '../../../utils/get-date-format';
import { ActivityTypes } from '../../../constants/Enums';
import ItemComment from './ItemComment';
import User from '../../User';
Expand Down Expand Up @@ -66,7 +67,7 @@ const Item = React.memo(({ type, data, createdAt, user }) => {
<div className={classNames(styles.content)}>
<div>{contentNode}</div>
<span className={styles.date}>
{t('format:longDateTime', {
{t(`format:${getDateFormat(createdAt)}`, {
postProcess: 'formatDate',
value: createdAt,
})}
Expand Down
3 changes: 2 additions & 1 deletion client/src/components/CardModal/Activities/ItemComment.jsx
Expand Up @@ -6,6 +6,7 @@ import { Comment } from 'semantic-ui-react';
import { usePopup } from '../../../lib/popup';
import { Markdown } from '../../../lib/custom-ui';

import getDateFormat from '../../../utils/get-date-format';
import CommentEdit from './CommentEdit';
import User from '../../User';
import DeleteStep from '../../DeleteStep';
Expand Down Expand Up @@ -33,7 +34,7 @@ const ItemComment = React.memo(
<div className={styles.title}>
<span className={styles.author}>{user.name}</span>
<span className={styles.date}>
{t('format:longDateTime', {
{t(`format:${getDateFormat(createdAt)}`, {
postProcess: 'formatDate',
value: createdAt,
})}
Expand Down
18 changes: 16 additions & 2 deletions client/src/components/DueDate/DueDate.jsx
Expand Up @@ -4,6 +4,8 @@ import PropTypes from 'prop-types';
import classNames from 'classnames';
import { useTranslation } from 'react-i18next';

import getDateFormat from '../../utils/get-date-format';

import styles from './DueDate.module.scss';

const SIZES = {
Expand All @@ -12,15 +14,27 @@ const SIZES = {
MEDIUM: 'medium',
};

const FORMATS = {
const LONG_DATE_FORMAT_BY_SIZE = {
tiny: 'longDate',
small: 'longDate',
medium: 'longDateTime',
};

const FULL_DATE_FORMAT_BY_SIZE = {
tiny: 'fullDate',
small: 'fullDate',
medium: 'fullDateTime',
};

const DueDate = React.memo(({ value, size, isDisabled, onClick }) => {
const [t] = useTranslation();

const dateFormat = getDateFormat(
value,
LONG_DATE_FORMAT_BY_SIZE[size],
FULL_DATE_FORMAT_BY_SIZE[size],
);

const contentNode = (
<span
className={classNames(
Expand All @@ -29,7 +43,7 @@ const DueDate = React.memo(({ value, size, isDisabled, onClick }) => {
onClick && styles.wrapperHoverable,
)}
>
{t(`format:${FORMATS[size]}`, {
{t(`format:${dateFormat}`, {
value,
postProcess: 'formatDate',
})}
Expand Down
2 changes: 2 additions & 0 deletions client/src/locales/cs/core.js
Expand Up @@ -9,6 +9,8 @@ export default {
dateTime: '$t(format:date) $t(format:time)',
longDate: 'd MMM',
longDateTime: "d MMMM 'v' p",
fullDate: 'd MMM, y',
fullDateTime: "d MMMM, y 'v' p",
},

translation: {
Expand Down
2 changes: 2 additions & 0 deletions client/src/locales/da/core.js
Expand Up @@ -9,6 +9,8 @@ export default {
dateTime: '$t(format:date) $t(format:time)',
longDate: 'MMM d',
longDateTime: "MMMM d 'at' p",
fullDate: 'MMM d, y',
fullDateTime: "MMMM d, y 'a' p",
},

translation: {
Expand Down
2 changes: 2 additions & 0 deletions client/src/locales/de/core.js
Expand Up @@ -9,6 +9,8 @@ export default {
dateTime: '$t(format:date) $t(format:time)',
longDate: 'd. MMM',
longDateTime: "d. MMMM 'um' p",
fullDate: 'd. MMM. y',
fullDateTime: "d. MMMM. y 'um' p",
},

translation: {
Expand Down
2 changes: 2 additions & 0 deletions client/src/locales/en/core.js
Expand Up @@ -5,6 +5,8 @@ export default {
dateTime: '$t(format:date) $t(format:time)',
longDate: 'MMM d',
longDateTime: "MMMM d 'at' p",
fullDate: 'MMM d, y',
fullDateTime: "MMMM d, y 'at' p",
},

translation: {
Expand Down
2 changes: 2 additions & 0 deletions client/src/locales/es/core.js
Expand Up @@ -9,6 +9,8 @@ export default {
dateTime: '$t(format:date) $t(format:time)',
longDate: 'MMM d',
longDateTime: "MMMM d 'a' p",
fullDate: 'MMM d, y',
fullDateTime: "MMMM d, y 'a' p",
},

translation: {
Expand Down
2 changes: 2 additions & 0 deletions client/src/locales/fr/core.js
Expand Up @@ -9,6 +9,8 @@ export default {
dateTime: '$t(format:date) $t(format:time)',
longDate: 'd MMM',
longDateTime: "d MMMM 'à' p",
fullDate: 'd MMM y',
fullDateTime: "d MMMM y 'à' p",
},

translation: {
Expand Down
2 changes: 2 additions & 0 deletions client/src/locales/it/core.js
Expand Up @@ -5,6 +5,8 @@ export default {
dateTime: '$t(format:date) $t(format:time)',
longDate: 'MMM d',
longDateTime: "MMMM d 'at' p",
fullDate: 'MMM d, y',
fullDateTime: "MMMM d, y 'at' p",
},

translation: {
Expand Down
2 changes: 2 additions & 0 deletions client/src/locales/ja/core.js
Expand Up @@ -9,6 +9,8 @@ export default {
dateTime: '$t(format:date) $t(format:time)',
longDate: 'MMMMd日',
longDateTime: "MMMMd'日 ' HH:mm",
fullDate: 'yyyy年M月d日',
fullDateTime: 'yyyy年M月d日 HH:mm',
},

translation: {
Expand Down
2 changes: 2 additions & 0 deletions client/src/locales/ko/core.js
Expand Up @@ -9,6 +9,8 @@ export default {
dateTime: '$t(format:date) $t(format:time)',
longDate: "MMMMd'일'",
longDateTime: "MMMMd'일 ' a hh시 mm분",
fullDate: 'yyyy년M월d일',
fullDateTime: 'yyyy년M월d일 a hh시 mm분',
},

translation: {
Expand Down
2 changes: 2 additions & 0 deletions client/src/locales/pl/core.js
Expand Up @@ -9,6 +9,8 @@ export default {
dateTime: '$t(format:date) $t(format:time)',
longDate: 'd MMM',
longDateTime: "d MMMM 'o' p",
fullDate: 'd MMM y',
fullDateTime: "d MMMM y 'o' p",
},

translation: {
Expand Down
2 changes: 2 additions & 0 deletions client/src/locales/ro/core.js
Expand Up @@ -9,6 +9,8 @@ export default {
dateTime: '$t(format:date) $t(format:time)',
longDate: 'd MMM',
longDateTime: "d MMMM 'в' p",
fullDate: 'd MMM y',
fullDateTime: "d MMMM y 'в' p",
},

translation: {
Expand Down
2 changes: 2 additions & 0 deletions client/src/locales/ru/core.js
Expand Up @@ -9,6 +9,8 @@ export default {
dateTime: '$t(format:date) $t(format:time)',
longDate: 'd MMM',
longDateTime: "d MMMM 'в' p",
fullDate: 'd MMM y',
fullDateTime: "d MMMM y 'в' p",
},

translation: {
Expand Down
2 changes: 2 additions & 0 deletions client/src/locales/sk/core.js
Expand Up @@ -9,6 +9,8 @@ export default {
dateTime: '$t(format:date) $t(format:time)',
longDate: 'd MMM',
longDateTime: "d MMMM 'v' p",
fullDate: 'd MMM y',
fullDateTime: "d MMMM y 'v' p",
},

translation: {
Expand Down
2 changes: 2 additions & 0 deletions client/src/locales/sv/core.js
Expand Up @@ -9,6 +9,8 @@ export default {
dateTime: '$t(format:date) $t(format:time)',
longDate: 'MMM d',
longDateTime: "MMMM d 'at' p",
fullDate: 'MMM d, y',
fullDateTime: "MMMM d, y 'at' p",
},

translation: {
Expand Down
2 changes: 2 additions & 0 deletions client/src/locales/tr/core.js
Expand Up @@ -9,6 +9,8 @@ export default {
dateTime: '$t(format:date) $t(format:time)',
longDate: 'd. MMM',
longDateTime: "d. MMMM 'Saat' p",
fullDate: 'd. MMM. y',
fullDateTime: "d. MMMM. y 'Saat' p",
},

translation: {
Expand Down
2 changes: 2 additions & 0 deletions client/src/locales/uz/core.js
Expand Up @@ -5,6 +5,8 @@ export default {
dateTime: '$t(format:date) $t(format:time)',
longDate: 'MMM d',
longDateTime: "MMMM d 'at' p",
fullDate: 'MMM d, y',
fullDateTime: "MMMM d, y 'at' p",
},

translation: {
Expand Down
2 changes: 2 additions & 0 deletions client/src/locales/zh/core.js
Expand Up @@ -5,6 +5,8 @@ export default {
dateTime: '$t(format:date) $t(format:time)',
longDate: 'MMM d',
longDateTime: "MMMM d 'at' p",
fullDate: 'MMM d, y',
fullDateTime: "MMMM d, y 'at' p",
},

translation: {
Expand Down
6 changes: 6 additions & 0 deletions client/src/utils/get-date-format.js
@@ -0,0 +1,6 @@
export default (value, longDateFormat = 'longDateTime', fullDateFormat = 'fullDateTime') => {
const year = value.getFullYear();
const currentYear = new Date().getFullYear();

return year === currentYear ? longDateFormat : fullDateFormat;
};

0 comments on commit 920f9c0

Please sign in to comment.