46 lines
1.4 KiB
JavaScript
46 lines
1.4 KiB
JavaScript
|
import fs from 'fs/promises';
|
||
|
|
||
|
const filePath1 = './data/colorcrew_data_transformed.json.bkup2';
|
||
|
const filePath2 = './data/colorcrew_data_transformed_prod.json';
|
||
|
|
||
|
export async function compareFiles() {
|
||
|
try {
|
||
|
// Read the files from the hardcoded paths
|
||
|
const json1 = JSON.parse(await fs.readFile(filePath1, 'utf8'));
|
||
|
const json2 = JSON.parse(await fs.readFile(filePath2, 'utf8'));
|
||
|
|
||
|
const result = compareTimeIntervals(json1, json2);
|
||
|
if (result.length > 0) {
|
||
|
console.log('Differences in break hours:', JSON.stringify(result, null, 2));
|
||
|
console.log(`Total differences: ${result.length}`);
|
||
|
} else {
|
||
|
console.log('No differences in break hours for matching start and end times.');
|
||
|
}
|
||
|
} catch (error) {
|
||
|
console.error('Error reading or parsing files:', error);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Function to compare arrays of time intervals
|
||
|
export function compareTimeIntervals(arr1, arr2) {
|
||
|
const differences = [];
|
||
|
|
||
|
arr1.forEach((item1) => {
|
||
|
const matchingItem = arr2.find(item2 => item1.start_time === item2.start_time && item1.end_time === item2.end_time);
|
||
|
|
||
|
if (matchingItem) {
|
||
|
if (item1.break_hours !== matchingItem.break_hours) {
|
||
|
differences.push({
|
||
|
start_time: item1.start_time,
|
||
|
end_time: item1.end_time,
|
||
|
break_hours_in_first_file: item1.break_hours,
|
||
|
break_hours_in_second_file: matchingItem.break_hours
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
|
||
|
return differences;
|
||
|
}
|
||
|
|
||
|
compareFiles();
|