Back End Development and APIs Projects - Exercise Tracker test #8

Here is the solution:

I am storing dates in the DB simply as new Date(x).toISOString() for consistency and extensibility.

Before returning the date from the API, I’m calling a helper function I wrote with inspiration from @ryoshi1001 on this post: Back End Development and APIs Projects - Exercise Tracker - #9 by ryoshi1001

function localToUTCDate (localDate) {
        const year = new Date(localDate).getUTCFullYear()
        const month = new Date(localDate).getUTCMonth()
        const day = new Date(localDate).getUTCDate()
        const UTCDate = new Date(Date.UTC(year, month, day))

        return new Date(UTCDate.getTime() + UTCDate.getTimezoneOffset() * 60000).toDateString()
}