Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Events Saved on Wrong Calendar with No Alarm - Android #442

Open
SwhiteMHC opened this issue Oct 19, 2023 · 1 comment
Open

Events Saved on Wrong Calendar with No Alarm - Android #442

SwhiteMHC opened this issue Oct 19, 2023 · 1 comment

Comments

@SwhiteMHC
Copy link

Each time I attempt to save an event to a calendar on the android device, the event is saved to the holiday calendar and no alarm is added.

Environment

System:
  OS: macOS 13.4
  CPU: (10) arm64 Apple M2 Pro
  Memory: 76.61 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 20.5.1
    path: /opt/homebrew/bin/node
  Yarn:
    version: 1.22.19
    path: /opt/homebrew/bin/yarn
  npm:
    version: 9.8.1
    path: /opt/homebrew/bin/npm
  Watchman:
    version: 2023.08.14.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.12.1
    path: /usr/local/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 22.4
      - iOS 16.4
      - macOS 13.3
      - tvOS 16.4
      - watchOS 9.4
  Android SDK: Not Found
IDEs:
  Android Studio: 2022.3 AI-223.8836.35.2231.10406996
  Xcode:
    version: 14.3.1/14E300c
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 11.0.20
    path: /usr/bin/javac
  Ruby:
    version: 2.6.10
    path: /usr/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.72.4
    wanted: 0.72.4
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: false

Steps to Reproduce

useEffect(() => {
    async function init() {
      let permission = await RNCalendarEvents.checkPermissions();
      let permissionGranted = await RNCalendarEvents.requestPermissions();
      if (permissionGranted) {
        let calendars = await RNCalendarEvents.findCalendars();
        let calendarID = calendars[0].id;
        let currentTime = new Date();
        let currentTimeMS = currentTime.getTime();
        let startTimeMS = currentTimeMS + 240000; // Two Minutes in Future
        let startDate = new Date(startTimeMS);
        let alarmTimeMS = startTimeMS - 60000; // One Minute Prior to Start
        let alarmDate = new Date(alarmTimeMS);

        console.log(`Start Time: ${startDate.toISOString()}`);
        console.log(`End Time: ${startDate.toISOString()}`);
        console.log(`Snooze Time: ${alarmDate.toISOString()}`);

        try {
          let event = await RNCalendarEvents.saveEvent('Snooze CMS', {
            id: '1',
            calendarId: calendarID,
            startDate: startDate.toISOString(),
            endDate: startDate.toISOString(),
            alarms: [
              {
                date: alarmDate.toISOString(),
              },
            ],
          });

          console.log(event);
        } catch (e) {
          console.log(e);
        }

        await RNCalendarEvents.saveEvent('Snooze CMS', {
          id: '2',
          calendarId: '2',
          startDate: startDate.toISOString(),
          endDate: startDate.toISOString(),
          alarms: [
            {
              date: alarmDate.toISOString(),
            },
          ],
        });
        await RNCalendarEvents.saveEvent('Snooze CMS', {
          id: '3',
          calendarId: '3',
          startDate: startDate.toISOString(),
          endDate: startDate.toISOString(),
          alarms: [
            {
              date: alarmDate.toISOString(),
            },
          ],
        });
        await RNCalendarEvents.saveEvent('Snooze CMS', {
          id: '4',
          calendarId: '4',
          startDate: startDate.toISOString(),
          endDate: startDate.toISOString(),
          alarms: [
            {
              date: alarmDate.toISOString(),
            },
          ],
        });
      }
    }

    init();
    setSamples(apiPlaceholder);
  }, []);

Expected Behavior

Using different calendarIds results in the event being saved to the respective calendar. When the event is saved, an alert is set for one minute prior to the end date.

Actual Behavior

All events are saved to the holiday calendar and no alert is set.

Result from await RNCalendarEvents.findCalendars();

[
  {
    "allowedAvailabilities": ["busy", "free"],
    "allowsModifications": true,
    "color": "#4CB5DE",
    "id": "1",
    "isPrimary": true,
    "source": "My calendar",
    "title": "My calendar",
    "type": "LOCAL"
  },
  {
    "allowedAvailabilities": ["busy", "free"],
    "allowsModifications": true,
    "color": "#9FE1E7",
    "id": "2",
    "isPrimary": true,
    "source": "Removed for Privacy",
    "title": "Removed for Privacy",
    "type": "com.google"
  },
  {
    "allowedAvailabilities": ["busy", "free"],
    "allowsModifications": false,
    "color": "#16A765",
    "id": "3",
    "isPrimary": false,
    "source": "Removed for Privacy",
    "title": "Holidays in United States",
    "type": "com.google"
  },
  {
    "allowedAvailabilities": ["busy", "free"],
    "allowsModifications": false,
    "color": "#92E1C0",
    "id": "4",
    "isPrimary": false,
    "source": "Removed for Privacy",
    "title": "Birthdays",
    "type": "com.google"
  }
]

Result in Calendar View:
image000000

@cleitoncsalvagni
Copy link

cleitoncsalvagni commented Oct 26, 2023

Time must be a number, right? There you define "toISOString()", but it must be 60, 15, 5... (if I'm not mistaken). Here is an example of how I use it:

          const differenceInMinutes =
            (eventDate.getTime() - currentMoment.getTime()) / (60 * 1000);

          const alarmMinutes =
            differenceInMinutes >= 60
              ? -60
              : differenceInMinutes >= 15
              ? -15
              : -5;

          const eventId = await RNCalendarEvents.saveEvent(description, {
            calendarId: item_code.toString(),
            location: establishment_name,
            startDate: startDate,
            endDate: endDate,
            alarms: [{date: alarmMinutes}],
          });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants