Skip to content

Commit

Permalink
Fix the display of 0 seconds remaining lifetime
Browse files Browse the repository at this point in the history
  • Loading branch information
MytsV committed Sep 15, 2024
1 parent 7a6e864 commit 22c5538
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/component-library/features/utils/text-formatters.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const DEFAULT_VALUE = 'NaN';

export const formatDate = (isoString: string): string => {
const date = new Date(isoString);
if (isNaN(date.getTime())) {
return 'NaN';
return DEFAULT_VALUE;
}
// TODO: use locale from some context
return date.toLocaleDateString('en-UK', {
Expand All @@ -12,7 +14,7 @@ export const formatDate = (isoString: string): string => {
};

export const formatFileSize = (bytes: number): string => {
if (isNaN(bytes) || bytes < 0) return 'NaN';
if (isNaN(bytes) || bytes < 0) return DEFAULT_VALUE;
if (bytes === 0) return '0 Bytes';
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
const i = Math.floor(Math.log(bytes) / Math.log(1024));
Expand All @@ -31,7 +33,9 @@ export const formatSeconds = (seconds: number): string => {
return `${hours} hour${hours > 1 ? 's' : ''}`;
} else if (minutes > 0) {
return `${minutes} minute${minutes > 1 ? 's' : ''}`;
} else {
} else if (seconds > 0) {
return `${remainingSeconds} second${remainingSeconds > 1 ? 's' : ''}`;
} else {
return DEFAULT_VALUE;
}
}

0 comments on commit 22c5538

Please sign in to comment.