function sortIntoDays(newMinChunks, oldMinChunks) {
                                let currentDay = []
                                let dayFiles = []
                                let chunksToSort = []
                                
                                // TODO: refactor boths side of the main logic switch to use the same core sorting logic via a function
                                // if we have an old day file to start from we first figure out where our new data begins in regards to the old data
                                if (oldMinChunks != undefined) {
                                    // merge the old minChunks with new minChunks to create the most complete day
                                    [currentDay, chunksToSort] = mergeChunks(newMinChunks, oldMinChunks)
                                    dayFiles.push(currentDay)
                                    currentDay = []

                                    SA.logger.info(MODULE_NAME + ' Sorting into Day files. Current file count: ' + dayFiles.length)
                                    TS.projects.foundations.functionLibraries.processFunctions.processHeartBeat(processIndex,  'Sorting into Day files. Current file count: ' + dayFiles.length)                           
                   
                                    if (chunksToSort != undefined) {
                                        // sort remaining chunks into day files
                                        for (let minChunk of chunksToSort) { 
                                            if (currentDay.length > 0) {
                                                // check if chunk still in current day
                                                let lastChunk = currentDay[currentDay.length - 1]
                                                let lastChunkEnd = new Date(lastChunk[1])
                                                let currentChunkBegin = new Date(minChunk[0])
                                                if (checkIfOnSameDay(lastChunkEnd, currentChunkBegin)) {
                                                    // if so add them to the same day
                                                    currentDay.push(minChunk) 
                                                } else {
                                                    // if not save the current day file and continue to the next
                                                    dayFiles.push(currentDay)
                                                    currentDay = []
                                                    currentDay.push(minChunk)

                                                    SA.logger.info(MODULE_NAME + ' Sorting into Day files. Current file count: ' + dayFiles.length)
                                                    TS.projects.foundations.functionLibraries.processFunctions.processHeartBeat(processIndex,  'Sorting into Day files. Current file count: ' + dayFiles.length)                          
                                                }
                                            } else {
                                                currentDay.push(minChunk)
                                            }
                                        }

                                        dayFiles.push(currentDay) 

                                        SA.logger.info(MODULE_NAME + ' Sorting into Day files. Current file count: ' + dayFiles.length)
                                        TS.projects.foundations.functionLibraries.processFunctions.processHeartBeat(processIndex,  'Sorting into Day files. Current file count: ' + dayFiles.length)                          
                                    }

                                    return dayFiles
                                } else {
                                    // Else we need to start fresh and sort into day files
                                    for (let minChunk of newMinChunks) { 
                                        if (currentDay.length > 0) {
                                            // check if chunk still in current day
                                            let lastChunk = currentDay[currentDay.length - 1]
                                            let lastChunkEnd = new Date(lastChunk[1])
                                            let currentChunkBegin = new Date(minChunk[0])
                                            if (checkIfOnSameDay(lastChunkEnd, currentChunkBegin)) {
                                                // if so add them to the same day
                                                currentDay.push(minChunk)
                                            } else {
                                                // if not save the current day file and continue to the next
                                                dayFiles.push(currentDay)
                                                currentDay = []
                                                currentDay.push(minChunk)

                                                SA.logger.info(MODULE_NAME + ' Sorting into Day files. Current file count: ' + dayFiles.length)
                                                TS.projects.foundations.functionLibraries.processFunctions.processHeartBeat(processIndex,  'Sorting into Day files. Current file count: ' + dayFiles.length)                          
                                            }
                                        } else {
                                            currentDay.push(minChunk)
                                        }
                                    }

                                    dayFiles.push(currentDay)

                                    SA.logger.info(MODULE_NAME + ' Sorting into Day files. Current file count: ' + dayFiles.length)
                                    TS.projects.foundations.functionLibraries.processFunctions.processHeartBeat(processIndex,  'Sorting into Day files. Current file count: ' + dayFiles.length)                          
    
                                    return dayFiles
                                }
                            }
The function sorts data into day files based on timestamps.
@param newMinChunks - an array of one minute chunks (each represented as an
array with at least three elements: start timestamp, end timestamps, and data values) that need to be
sorted into day files.
@param oldMinChunks - an array of one minute chunks coming from a previously saved day
file
@returns an array of day files, where each day file is an array of
minChunks.