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:
@@ -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`;
|
||||
|
||||
Reference in New Issue
Block a user