Skip to content

Commit 0ee8ea1

Browse files
FE: Don't omit milliseconds in timestamps (#1266)
Co-authored-by: German Osin <german.osin@gmail.com>
1 parent 69cb9aa commit 0ee8ea1

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

frontend/src/components/Topics/Topic/Messages/Message.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,11 @@ const Message: React.FC<Props> = ({
110110
<td>{partition}</td>
111111
<td>
112112
<div>
113-
{formatTimestamp({ timestamp, timezone: currentTimezone.value })}
113+
{formatTimestamp({
114+
timestamp,
115+
timezone: currentTimezone.value,
116+
withMilliseconds: true,
117+
})}
114118
</div>
115119
</td>
116120
<S.DataCell title={key}>

frontend/src/components/Topics/Topic/Messages/MessageContent/MessageContent.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ const MessageContent: React.FC<MessageContentProps> = ({
110110
{formatTimestamp({
111111
timestamp,
112112
timezone: currentTimezone.value,
113+
withMilliseconds: true,
113114
})}
114115
</S.MetadataValue>
115116
<S.MetadataMeta>Timestamp type: {timestampType}</S.MetadataMeta>

frontend/src/components/Topics/Topic/Messages/__test__/Message.spec.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,12 @@ describe('Message component', () => {
6565
expect(screen.getByText(mockMessage.value as string)).toBeInTheDocument();
6666
expect(screen.getByText(mockMessage.key as string)).toBeInTheDocument();
6767
expect(
68-
screen.getByText(formatTimestamp({ timestamp: mockMessage.timestamp }))
68+
screen.getByText(
69+
formatTimestamp({
70+
timestamp: mockMessage.timestamp,
71+
withMilliseconds: true,
72+
})
73+
)
6974
).toBeInTheDocument();
7075
expect(screen.getByText(mockMessage.offset.toString())).toBeInTheDocument();
7176
expect(

frontend/src/lib/dateTimeHelpers.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ export const formatTimestamp = ({
44
timestamp,
55
format = { hourCycle: 'h23' },
66
timezone,
7+
withMilliseconds,
78
}: {
89
timestamp: number | string | Date | undefined;
910
format?: Intl.DateTimeFormatOptions;
1011
timezone?: string;
12+
withMilliseconds?: boolean;
1113
}): string => {
1214
if (!timestamp) {
1315
return '';
@@ -29,7 +31,13 @@ export const formatTimestamp = ({
2931
timeZone: finalTimezone,
3032
};
3133

32-
return date.toLocaleString(language || [], formatOptions);
34+
let formattedTimestamp = date.toLocaleString(language || [], formatOptions);
35+
36+
if (withMilliseconds) {
37+
formattedTimestamp += `.${date.getMilliseconds()}`;
38+
}
39+
40+
return formattedTimestamp;
3341
};
3442

3543
export const formatMilliseconds = (input = 0) => {

0 commit comments

Comments
 (0)