Merge branch 'dev' of ssh://git.congegni.net:4022/Congegni/sintonia_webapp into dev

This commit is contained in:
Marco Cavalli 2025-04-03 15:01:11 +02:00
commit 36d3deab44
26 changed files with 521 additions and 243 deletions

View file

@ -2,4 +2,30 @@ export function cleanOptions(options: Object): Object {
return Object.fromEntries(
Object.entries(options).filter(([_, value]) => value !== undefined && value !== null)
);
}
}
export function camelToSnake(obj) {
if (Array.isArray(obj)) {
return obj.map(camelToSnake);
} else if (obj !== null && typeof obj === 'object') {
return Object.keys(obj).reduce((acc, key) => {
const snakeKey = key.replace(/([A-Z])/g, '_$1').toLowerCase();
acc[snakeKey] = camelToSnake(obj[key]);
return acc;
}, {});
}
return obj;
}
export function snakeToCamel(obj) {
if (Array.isArray(obj)) {
return obj.map(snakeToCamel);
} else if (obj !== null && typeof obj === 'object') {
return Object.keys(obj).reduce((acc, key) => {
const camelKey = key.replace(/_([a-z])/g, (_, char) => char.toUpperCase());
acc[camelKey] = snakeToCamel(obj[key]);
return acc;
}, {});
}
return obj;
}

View file

@ -9,5 +9,23 @@ export function extractTime(dateTimeString: string, extractTime: boolean = false
const minutes = String(date.getMinutes()).padStart(2, '0');
return `${hours}:${minutes}`;
}
return date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
};
return date.getFullYear() + '-' + String(date.getMonth() + 1).padStart(2, '0') + '-' + String(date.getDate()).padStart(2, '0');
};
export function getTimeDiff(startTime: Date, endTime: Date) {
const diffInMilliseconds = Math.abs(startTime.getTime() - endTime.getTime());
const hours = Math.floor((diffInMilliseconds % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
const minutes = Math.floor((diffInMilliseconds % (1000 * 60 * 60)) / (1000 * 60));
const formattedHours = String(hours).padStart(2, '0');
const formattedMinutes = String(minutes).padStart(2, '0');
return `${formattedHours}:${formattedMinutes}`;
}
export function getHoursMinutesFromString(timeString: string): Date {
const [ h, m ] = timeString.split(":");
const ms = new Date().setHours(h,m);
return new Date(ms)
}