'NodeMailer - ICALToolkit Event Days are Always Incorrect by -1 Day on Start & -2 Day on end
The Dates on my NodeJS Side are Correct.
Once The User receives the event (On Their Email Client) the dates are Incorrect.
The Dates are always off by an Exact amount
- -1 On the Starting Day E.G 02 Feb -> 01 Feb.
- -2 On the Ending Date E.G 05Feb -> 03Feb
Dates are Received from an Angular Application, I can confirm the dates provided are correct dates Formatting is another matter.
Is my Formatting Incorrect? & or Is this a TimeZone Problem?
Please find Below Code:
I am Unsure How to Recreate a working Example of a Node.js Application using the SO builder, Please Lend guidance regarding this if required and I will update were needed
var startDate = new Date(user.sDate)//YYYY/MM/DD;
var EndDate = new Date(user.eDate)//YYYY/MM/DD
var builder = icalToolkit.createIcsFileBuilder();
builder.calname = 'Temp Cal';
builder.timezone = 'Africa/Johannesburg';
builder.tzid = 'Africa/Johannesburg';
builder.method = 'REQUEST';
console.log(startDate + " sDate") //Sat Feb 25 2023 00:00:00 GMT+0200 (South Africa Standard Time)
console.log(user.eDate + " eDate") //2023/02/27 eDate
builder.events.push({
//Required: type Date()
start: startDate,
end: EndDate,
summary: 'Test Event',
allDay: true,
description: 'Testing it!',
organizer: {
name: 'SomePlace ',
email: '[email protected]',
sentBy: '[email protected]'
},
method: 'REQUEST',
status: 'CONFIRMED',
})
var icsFileContent = builder.toString();
let mailOptions = {
from: '[email protected]', // sender address
to: "[email protected]", // list of receivers
subject: "New Booking Made", // Subject line
html: `<h1>Hi ${user.name}</h1><br>
<h4>Here is your new Booking</h4><br>
<p>Calendar Event Here: </p>
<p>${user.sDate}</p><br>
<p>${user.eDate}</p><br>`,
alternatives: [{
contentType: 'text/calendar; charset="utf-8"; method=REQUEST',
content: icsFileContent.toString()
}]
};
let info = await transporter.sendMail(mailOptions);
callback(info);
Extra info: Angular App Date Formatting:
const format = 'yyyy/MM/dd';
const startD = sy+ "-" + sm + "-" + sd;
const endD = ey+ "-" + em + "-" + ed;
const locale = 'en-US';
const formattedDateStart = formatDate(startD, format, locale);
const formattedDateEnd = formatDate(endD, format, locale);
this.SendEmail(formattedDateStart,formattedDateEnd);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
