Currently, I am working with Mongoose and Luxon to present a date chosen by the user from a form. However, there seems to be an issue where the date is being console logged as one day, but appearing on the page as the previous day.
Below is my model setup:
const mongoose = require("mongoose");
const { DateTime, Settings } = require("luxon");
// Setting up time zone
console.log(Settings);
const Schema = mongoose.Schema;
let AccomplishmentSchema = new Schema({
dateInput: {
type: Date,
required: true,
},
textInput: {
type: String,
required: true,
},
});
AccomplishmentSchema.virtual("dateInput_formatted").get(function () {
return DateTime.fromJSDate(this.dateInput).toLocaleString(DateTime.DATE_FULL); // format 'YYYY-MM-DD
});
module.exports = mongoose.model("Accomplishment", AccomplishmentSchema);
The following displays the console log alongside what appears on the webpage:
dateInput: 2023-01-01T00:00:00.000Z,
textInput: 'etst',
December 31, 2022 etst
It seems like this discrepancy could be related to some sort of time conversion error. Despite adjusting the time zone and settings, the problem persists, leaving me unable to identify a solution.