moment / luxon

⏱ A library for working with dates and times in JS
https://moment.github.io/luxon
MIT License
15.12k stars 728 forks source link

Disappearing datetime #1491

Closed CoderLordOfSECRETS closed 10 months ago

CoderLordOfSECRETS commented 11 months ago

Describe the bug I am Attempting to create a group of nested arrays and every time I assign the lowest level a date time it disappears. Help would be appreciated as I am not super experienced with the library.

To Reproduce function createTimeArrays(numArrays) { let arraysContainer = []; for (let i = 0; i < numArrays; i++) { let week = []; arraysContainer.push(week); for (let n = 0; n < 7; n++) { let day = []; arraysContainer[i].push(day); for (let o = 0; o < 24 * 2; o++) { let halfhour = []; arraysContainer[i][n].push(halfhour); arraysContainer[i][n][o] = "null"; } } } console.log(arraysContainer) return arraysContainer; }

function AssignDate(timeslots) { const startDateInput = document.getElementById('StartDate'); const startDate = luxon.DateTime.fromISO(startDateInput.value); console.log(startDateInput) console.log(startDate)

let currentDate = startDate;

for (let i = 0; i < timeslots.length; i++) {
    for (let n = 0; n < timeslots[i].length; n++) {
        for (let h = 0; h < timeslots[i][n].length; h++) {
            let timeslot = currentDate;
            console.log(timeslot)
            timeslots[i][n][h] = timeslot;

            // Assign time and calculate next currentTime
            currentDate = currentDate.plus({ minutes: 30 }); // Reassign currentDate

        }
    }
}

console.log("Debug", timeslots);
return timeslots;

}

Actual vs Expected behavior Returns one blank array, should return nested datetime luxon arrays

Desktop (please complete the following information):

diesieben07 commented 11 months ago

Hi, can you please provide a more complete code example? Right now it is just two functions. How are these functions called?

icambron commented 10 months ago

Looks like it works to me: https://jsfiddle.net/sao3q5uL/

In general, please don't file issues like this. Issues for Luxon should look "here is the function I called in Luxon. Here's what I expected it to do, but here's what it did." Luxon can't control what items end up in your array; it can only take in values and return things. If those things are wrong or even just confusing, we're happy to help. But this isn't the right forum for general debugging help.