Skip to content

Commit

Permalink
Improve date format in last updated field (#168)
Browse files Browse the repository at this point in the history
1. AM/PM indicator is now displayed on the same line as the time.
2. Year is now included for dates not in the current year.
3. Fixed the display of 24-hour time format to ensure proper representation.
  • Loading branch information
chacha912 authored Aug 29, 2024
1 parent 92376a5 commit fb9a8ae
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/assets/styles/components/list_document.scss
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@
.updated,
.size {
padding-left: 12px;
width: 120px;
max-width: 200px;
}

.connections {
Expand Down
9 changes: 8 additions & 1 deletion src/features/documents/DocumentDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ import React, { useEffect, useState } from 'react';
import { fromUnixTime, format } from 'date-fns';
import { Link, useParams, useNavigate } from 'react-router-dom';
import { useAppDispatch, useAppSelector } from 'app/hooks';
import { selectPreferences } from 'features/users/usersSlice';
import { selectDocumentDetail, getDocumentAsync, removeDocumentByAdminAsync } from './documentsSlice';
import { Icon, Button, CodeBlock, CopyButton, Popover, Dropdown } from 'components';

export function DocumentDetail() {
const navigate = useNavigate();
const { document } = useAppSelector(selectDocumentDetail);
const { use24HourClock } = useAppSelector(selectPreferences);
const dispatch = useAppDispatch();
const params = useParams();
const projectName = params.projectName || '';
Expand Down Expand Up @@ -55,7 +57,12 @@ export function DocumentDetail() {
</Link>
<div className="title_inner">
<strong className="title">{document?.key}</strong>
<span className="date">{format(fromUnixTime(document?.updatedAt!), 'MMM d, h:mm')}</span>
<span className="date">
{format(
fromUnixTime(document?.updatedAt!),
`MMM d${new Date().getFullYear() === fromUnixTime(document?.updatedAt!).getFullYear() ? '' : ', yyyy'}, ${use24HourClock ? 'HH:mm' : 'h:mm a'}`,
)}
</span>
</div>

<Popover opened={opened} onChange={setOpened}>
Expand Down
5 changes: 4 additions & 1 deletion src/features/documents/DocumentList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,10 @@ export function DocumentList({ isDetailOpen = false }: { isDetailOpen?: boolean
<span className="td id">{key}</span>
{!isDetailOpen && (
<span className="td updated">
{format(fromUnixTime(updatedAt), `${use24HourClock ? 'MMM d, h:mm' : 'MMM d, h:mm aa'}`)}
{format(
fromUnixTime(updatedAt),
`MMM d${new Date().getFullYear() === fromUnixTime(updatedAt).getFullYear() ? '' : ', yyyy'}, ${use24HourClock ? 'HH:mm' : 'h:mm a'}`,
)}
</span>
)}
</Link>
Expand Down

0 comments on commit fb9a8ae

Please sign in to comment.