Skip to content

Wrong time shown in mobile and desktop application #288

@harsha-techcronus

Description

@harsha-techcronus

Code to generate ICS file -

`const fs = require("fs");
const path = require("path");
const moment = require("moment-timezone");

const generateICSFile = ({ id, user, service, start_date }) => {
try {
if (!id || !user || !service || !start_date || !service.service_duration) {
console.error("❌ Missing required parameters for ICS generation");
return null;
}

// Define correct timezone
const timezone = "Asia/Kolkata";

// Parse the start_date string into a moment object
const startMoment = moment(start_date).tz(timezone);

// Extract Duration from service.service_duration
let durationValue = parseInt(service.service_duration);
let durationUnit = service.service_duration.includes("hour")
  ? "hours"
  : "minutes";

// Create end time by adding duration
const endMoment = startMoment.clone().add(durationValue, durationUnit);

// Debug logs

// Convert to correct local time format
const startLocal = moment(startMoment)
  .tz("Asia/Kolkata")
  .format("YYYYMMDDTHHmmss");
const endLocal = moment(endMoment)
  .tz("Asia/Kolkata")
  .format("YYYYMMDDTHHmmss");

const filePath = path.join(__dirname, `booking_${id}.ics`);

// Ensure old ICS file is deleted before generating a new one
if (fs.existsSync(filePath)) {
  fs.unlinkSync(filePath);
}

// Generate ICS content
const icsContent = `BEGIN:VCALENDAR

VERSION:2.0
PRODID:-//Pbmc Consultants//Booking System//EN
CALSCALE:GREGORIAN
METHOD:REQUEST
BEGIN:VTIMEZONE
TZID:Asia/Kolkata
BEGIN:STANDARD
DTSTART:19700101T000000
TZOFFSETFROM:+0530
TZOFFSETTO:+0530
TZNAME:IST
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
UID:${id}@pbmc.com
DTSTAMP:${moment().tz("Asia/Kolkata").format("YYYYMMDDTHHmmss")}
DTSTART;TZID=Asia/Kolkata:${startLocal}
DTEND;TZID=Asia/Kolkata:${endLocal}
SUMMARY:${service.service_name || "Service Booking"}
DESCRIPTION:Your booking for ${
service.service_name || "Service"
} is scheduled with ${user.name || "PBMC Consultants"}.
LOCATION:Middle East
STATUS:CONFIRMED
SEQUENCE:1
TRANSP:OPAQUE
ORGANIZER;CN=Pbmc Consultants:MAILTO:[email protected]
BEGIN:VALARM
TRIGGER:-PT15M
ACTION:DISPLAY
DESCRIPTION:Reminder
END:VALARM
END:VEVENT
END:VCALENDAR`;

// Write the file
fs.writeFileSync(filePath, icsContent);

return filePath;

} catch (error) {
console.error("❌ Error generating ICS file:", error);
return null;
}
};

module.exports = generateICSFile;
`

Screenshot for reference -

Mobile ScreenShot -
Image

Desktop ScreenShot -
Image

Note - In mobile i have gmail applciation and in desktop i am logged In gmail through browser is this is making issue ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions