feat(project-finance): implement time formatting utilities and update task time handling

- Added utility functions to format time in hours, minutes, and seconds, and to parse time strings back to seconds.
- Updated the project finance controller to use seconds for estimated time and total time logged, improving accuracy in calculations.
- Modified frontend components to reflect changes in time handling, ensuring consistent display of time in both seconds and formatted strings.
- Adjusted Redux slice and types to accommodate new time formats, enhancing data integrity across the application.
This commit is contained in:
chamiakJ
2025-05-28 12:28:03 +05:30
parent ca0c958918
commit 07bc5e6030
7 changed files with 163 additions and 55 deletions

View File

@@ -4,6 +4,21 @@ export function formatDate(date: Date): string {
return dayjs(date).format('MMM DD, YYYY');
}
export function parseTimeToSeconds(timeString: string): number {
if (!timeString || timeString === "0s") return 0;
let totalSeconds = 0;
const hourMatch = timeString.match(/(\d+)h/);
const minuteMatch = timeString.match(/(\d+)m/);
const secondMatch = timeString.match(/(\d+)s/);
if (hourMatch) totalSeconds += parseInt(hourMatch[1]) * 3600;
if (minuteMatch) totalSeconds += parseInt(minuteMatch[1]) * 60;
if (secondMatch) totalSeconds += parseInt(secondMatch[1]);
return totalSeconds;
}
export function buildTimeString(hours: number, minutes: number, seconds: number) {
const h = hours > 0 ? `${hours}h` : '';
const m = `${minutes}m`;