bugfixing

This commit is contained in:
MuslemRahimi 2025-02-14 14:12:22 +01:00
parent 642adcd676
commit 19c29ba27e

View File

@ -777,8 +777,9 @@ export function formatDate(dateStr) {
}); });
const parseDate = (date) => { const parseDate = (date) => {
const parts = nyFormatter?.formatToParts(date); const parts = nyFormatter.formatToParts(date);
const extract = (type) => parts?.find((p) => p?.type === type)?.value?.padStart(2, '0'); const extract = (type) =>
parts.find((p) => p.type === type)?.value.padStart(2, '0');
return new Date( return new Date(
`${extract('year')}-${extract('month')}-${extract('day')}T${extract('hour')}:${extract('minute')}:${extract('second')}` `${extract('year')}-${extract('month')}-${extract('day')}T${extract('hour')}:${extract('minute')}:${extract('second')}`
); );
@ -790,7 +791,12 @@ export function formatDate(dateStr) {
// Calculate the time difference in seconds // Calculate the time difference in seconds
const seconds = Math.floor((nyCurrentObj - nyDateObj) / 1000); const seconds = Math.floor((nyCurrentObj - nyDateObj) / 1000);
// Define time intervals in seconds // Everything below 12 hours (43,200 seconds) returns "Now"
if (seconds < 43200) {
return 'Now';
}
// Define time intervals for 12 hours or more
const intervals = [ const intervals = [
{ unit: 'year', seconds: 31536000 }, { unit: 'year', seconds: 31536000 },
{ unit: 'month', seconds: 2592000 }, { unit: 'month', seconds: 2592000 },
@ -802,13 +808,14 @@ export function formatDate(dateStr) {
// Determine the appropriate time interval // Determine the appropriate time interval
for (const { unit, seconds: secondsInUnit } of intervals) { for (const { unit, seconds: secondsInUnit } of intervals) {
const count = Math?.floor(seconds / secondsInUnit); const count = Math.floor(seconds / secondsInUnit);
if (count >= 1) { if (count >= 1) {
return `${count} ${unit}${count === 1 ? '' : 's'} ago`; return `${count} ${unit}${count === 1 ? '' : 's'} ago`;
} }
} }
// If less than a minute
return 'Just now'; // Fallback (should not be reached due to our threshold)
return 'Now';
} catch (error) { } catch (error) {
console.error('Error formatting date:', error); console.error('Error formatting date:', error);
return 'Invalid date'; return 'Invalid date';
@ -818,6 +825,7 @@ export function formatDate(dateStr) {
export const formatRuleValue = (rule) => { export const formatRuleValue = (rule) => {
if (["interestIncome", "interestExpenses"].includes(rule.name)) { if (["interestIncome", "interestExpenses"].includes(rule.name)) {
return `$${rule.value === 1000 ? `${rule.value / 1000} Bn` : `${rule.value} Mio`}`; return `$${rule.value === 1000 ? `${rule.value / 1000} Bn` : `${rule.value} Mio`}`;