@ebarooni/capacitor-calendar 0.6.1 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/README.md +41 -62
  2. package/android/src/main/java/dev/barooni/capacitor/calendar/CapacitorCalendar.kt +12 -10
  3. package/android/src/main/java/dev/barooni/capacitor/calendar/CapacitorCalendarPlugin.kt +13 -2
  4. package/dist/docs.json +87 -783
  5. package/dist/esm/definitions.d.ts +31 -6
  6. package/dist/esm/definitions.js.map +1 -1
  7. package/dist/esm/schemas/enums/calendar-chooser-display-style.d.ts +2 -1
  8. package/dist/esm/schemas/enums/calendar-chooser-display-style.js +2 -1
  9. package/dist/esm/schemas/enums/calendar-chooser-display-style.js.map +1 -1
  10. package/dist/esm/schemas/enums/calendar-chooser-selection-style.d.ts +2 -1
  11. package/dist/esm/schemas/enums/calendar-chooser-selection-style.js +2 -1
  12. package/dist/esm/schemas/enums/calendar-chooser-selection-style.js.map +1 -1
  13. package/dist/esm/schemas/enums/plugin-permission.d.ts +36 -0
  14. package/dist/esm/schemas/enums/plugin-permission.js +36 -0
  15. package/dist/esm/schemas/enums/plugin-permission.js.map +1 -1
  16. package/dist/esm/schemas/enums/reminder-recurrence-frequency.d.ts +18 -0
  17. package/dist/esm/schemas/enums/reminder-recurrence-frequency.js +18 -0
  18. package/dist/esm/schemas/enums/reminder-recurrence-frequency.js.map +1 -1
  19. package/dist/esm/schemas/interfaces/calendar.d.ts +1 -1
  20. package/dist/esm/schemas/interfaces/calendar.js.map +1 -1
  21. package/dist/esm/web.d.ts +6 -2
  22. package/dist/esm/web.js +6 -0
  23. package/dist/esm/web.js.map +1 -1
  24. package/dist/plugin.cjs.js +64 -2
  25. package/dist/plugin.cjs.js.map +1 -1
  26. package/dist/plugin.js +64 -2
  27. package/dist/plugin.js.map +1 -1
  28. package/ios/Plugin/CapacitorCalendar.swift +26 -2
  29. package/ios/Plugin/CapacitorCalendarPlugin.m +2 -0
  30. package/ios/Plugin/CapacitorCalendarPlugin.swift +31 -2
  31. package/ios/Plugin/CapacitorCalendarPluginError.swift +2 -0
  32. package/ios/Plugin/CapacitorReminders.swift +25 -0
  33. package/ios/Plugin/EventCreationParameters.swift +2 -2
  34. package/package.json +1 -1
package/README.md CHANGED
@@ -51,6 +51,7 @@ The video is just for showing the functionality, otherwise the `createEventWithP
51
51
  - ✅ Get default calendar
52
52
  - ✅ Create calendar events without native prompts
53
53
  - ✅️ Create reminders (only supported on iOS)
54
+ - ✅ Open calendar app at a specific date
54
55
  - ⌛️ Find calendar events
55
56
  - ⌛️ Delete calendar events
56
57
 
@@ -78,6 +79,8 @@ permissions can be found below:
78
79
  * [`getDefaultRemindersList()`](#getdefaultreminderslist)
79
80
  * [`getRemindersLists()`](#getreminderslists)
80
81
  * [`createReminder(...)`](#createreminder)
82
+ * [`openCalendar(...)`](#opencalendar)
83
+ * [`openReminders()`](#openreminders)
81
84
  * [Interfaces](#interfaces)
82
85
  * [Type Aliases](#type-aliases)
83
86
  * [Enums](#enums)
@@ -210,14 +213,14 @@ Retrieves the default calendar set on the device.
210
213
  ### createEvent(...)
211
214
 
212
215
  ```typescript
213
- createEvent(options: { title: string; calendarId?: string; location?: string; startDate?: Date; endDate?: Date; isAllDay?: boolean; }) => Promise<{ eventCreated: boolean; }>
216
+ createEvent(options: { title: string; calendarId?: string; location?: string; startDate?: number; endDate?: number; isAllDay?: boolean; }) => Promise<{ eventCreated: boolean; }>
214
217
  ```
215
218
 
216
219
  Creates an event with the provided options.
217
220
 
218
- | Param | Type | Description |
219
- | ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------- |
220
- | **`options`** | <code>{ title: string; calendarId?: string; location?: string; startDate?: <a href="#date">Date</a>; endDate?: <a href="#date">Date</a>; isAllDay?: boolean; }</code> | - Options for creating the event. |
221
+ | Param | Type | Description |
222
+ | ------------- | --------------------------------------------------------------------------------------------------------------------------------- | --------------------------------- |
223
+ | **`options`** | <code>{ title: string; calendarId?: string; location?: string; startDate?: number; endDate?: number; isAllDay?: boolean; }</code> | - Options for creating the event. |
221
224
 
222
225
  **Returns:** <code>Promise&lt;{ eventCreated: boolean; }&gt;</code>
223
226
 
@@ -267,6 +270,33 @@ Creates a reminder with the provided options.
267
270
  --------------------
268
271
 
269
272
 
273
+ ### openCalendar(...)
274
+
275
+ ```typescript
276
+ openCalendar(options: { date?: number; }) => Promise<void>
277
+ ```
278
+
279
+ Opens the calendar app. Since the user leaves your app, use this method with caution.
280
+ It will open the calendar on today's date if no date is provided.
281
+
282
+ | Param | Type | Description |
283
+ | ------------- | ------------------------------- | ----------------------------------- |
284
+ | **`options`** | <code>{ date?: number; }</code> | - Options for opening the calendar. |
285
+
286
+ --------------------
287
+
288
+
289
+ ### openReminders()
290
+
291
+ ```typescript
292
+ openReminders() => Promise<void>
293
+ ```
294
+
295
+ Opens the reminders app. Since the user leaves your app, use this method with caution.
296
+
297
+ --------------------
298
+
299
+
270
300
  ### Interfaces
271
301
 
272
302
 
@@ -275,7 +305,7 @@ Creates a reminder with the provided options.
275
305
 
276
306
  #### Calendar
277
307
 
278
- Represents a calendar object with an ID and title.
308
+ Represents a calendar object.
279
309
 
280
310
  | Prop | Type |
281
311
  | ----------- | ------------------- |
@@ -283,57 +313,6 @@ Represents a calendar object with an ID and title.
283
313
  | **`title`** | <code>string</code> |
284
314
 
285
315
 
286
- #### Date
287
-
288
- Enables basic storage and retrieval of dates and times.
289
-
290
- | Method | Signature | Description |
291
- | ---------------------- | ------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------- |
292
- | **toString** | () =&gt; string | Returns a string representation of a date. The format of the string depends on the locale. |
293
- | **toDateString** | () =&gt; string | Returns a date as a string value. |
294
- | **toTimeString** | () =&gt; string | Returns a time as a string value. |
295
- | **toLocaleString** | () =&gt; string | Returns a value as a string value appropriate to the host environment's current locale. |
296
- | **toLocaleDateString** | () =&gt; string | Returns a date as a string value appropriate to the host environment's current locale. |
297
- | **toLocaleTimeString** | () =&gt; string | Returns a time as a string value appropriate to the host environment's current locale. |
298
- | **valueOf** | () =&gt; number | Returns the stored time value in milliseconds since midnight, January 1, 1970 UTC. |
299
- | **getTime** | () =&gt; number | Gets the time value in milliseconds. |
300
- | **getFullYear** | () =&gt; number | Gets the year, using local time. |
301
- | **getUTCFullYear** | () =&gt; number | Gets the year using Universal Coordinated Time (UTC). |
302
- | **getMonth** | () =&gt; number | Gets the month, using local time. |
303
- | **getUTCMonth** | () =&gt; number | Gets the month of a <a href="#date">Date</a> object using Universal Coordinated Time (UTC). |
304
- | **getDate** | () =&gt; number | Gets the day-of-the-month, using local time. |
305
- | **getUTCDate** | () =&gt; number | Gets the day-of-the-month, using Universal Coordinated Time (UTC). |
306
- | **getDay** | () =&gt; number | Gets the day of the week, using local time. |
307
- | **getUTCDay** | () =&gt; number | Gets the day of the week using Universal Coordinated Time (UTC). |
308
- | **getHours** | () =&gt; number | Gets the hours in a date, using local time. |
309
- | **getUTCHours** | () =&gt; number | Gets the hours value in a <a href="#date">Date</a> object using Universal Coordinated Time (UTC). |
310
- | **getMinutes** | () =&gt; number | Gets the minutes of a <a href="#date">Date</a> object, using local time. |
311
- | **getUTCMinutes** | () =&gt; number | Gets the minutes of a <a href="#date">Date</a> object using Universal Coordinated Time (UTC). |
312
- | **getSeconds** | () =&gt; number | Gets the seconds of a <a href="#date">Date</a> object, using local time. |
313
- | **getUTCSeconds** | () =&gt; number | Gets the seconds of a <a href="#date">Date</a> object using Universal Coordinated Time (UTC). |
314
- | **getMilliseconds** | () =&gt; number | Gets the milliseconds of a <a href="#date">Date</a>, using local time. |
315
- | **getUTCMilliseconds** | () =&gt; number | Gets the milliseconds of a <a href="#date">Date</a> object using Universal Coordinated Time (UTC). |
316
- | **getTimezoneOffset** | () =&gt; number | Gets the difference in minutes between the time on the local computer and Universal Coordinated Time (UTC). |
317
- | **setTime** | (time: number) =&gt; number | Sets the date and time value in the <a href="#date">Date</a> object. |
318
- | **setMilliseconds** | (ms: number) =&gt; number | Sets the milliseconds value in the <a href="#date">Date</a> object using local time. |
319
- | **setUTCMilliseconds** | (ms: number) =&gt; number | Sets the milliseconds value in the <a href="#date">Date</a> object using Universal Coordinated Time (UTC). |
320
- | **setSeconds** | (sec: number, ms?: number \| undefined) =&gt; number | Sets the seconds value in the <a href="#date">Date</a> object using local time. |
321
- | **setUTCSeconds** | (sec: number, ms?: number \| undefined) =&gt; number | Sets the seconds value in the <a href="#date">Date</a> object using Universal Coordinated Time (UTC). |
322
- | **setMinutes** | (min: number, sec?: number \| undefined, ms?: number \| undefined) =&gt; number | Sets the minutes value in the <a href="#date">Date</a> object using local time. |
323
- | **setUTCMinutes** | (min: number, sec?: number \| undefined, ms?: number \| undefined) =&gt; number | Sets the minutes value in the <a href="#date">Date</a> object using Universal Coordinated Time (UTC). |
324
- | **setHours** | (hours: number, min?: number \| undefined, sec?: number \| undefined, ms?: number \| undefined) =&gt; number | Sets the hour value in the <a href="#date">Date</a> object using local time. |
325
- | **setUTCHours** | (hours: number, min?: number \| undefined, sec?: number \| undefined, ms?: number \| undefined) =&gt; number | Sets the hours value in the <a href="#date">Date</a> object using Universal Coordinated Time (UTC). |
326
- | **setDate** | (date: number) =&gt; number | Sets the numeric day-of-the-month value of the <a href="#date">Date</a> object using local time. |
327
- | **setUTCDate** | (date: number) =&gt; number | Sets the numeric day of the month in the <a href="#date">Date</a> object using Universal Coordinated Time (UTC). |
328
- | **setMonth** | (month: number, date?: number \| undefined) =&gt; number | Sets the month value in the <a href="#date">Date</a> object using local time. |
329
- | **setUTCMonth** | (month: number, date?: number \| undefined) =&gt; number | Sets the month value in the <a href="#date">Date</a> object using Universal Coordinated Time (UTC). |
330
- | **setFullYear** | (year: number, month?: number \| undefined, date?: number \| undefined) =&gt; number | Sets the year of the <a href="#date">Date</a> object using local time. |
331
- | **setUTCFullYear** | (year: number, month?: number \| undefined, date?: number \| undefined) =&gt; number | Sets the year value in the <a href="#date">Date</a> object using Universal Coordinated Time (UTC). |
332
- | **toUTCString** | () =&gt; string | Returns a date converted to a string using Universal Coordinated Time (UTC). |
333
- | **toISOString** | () =&gt; string | Returns a date as a string value in ISO format. |
334
- | **toJSON** | (key?: any) =&gt; string | Used by the JSON.stringify method to enable the transformation of an object's data for JavaScript Object Notation (JSON) serialization. |
335
-
336
-
337
316
  #### RemindersList
338
317
 
339
318
 
@@ -385,11 +364,11 @@ Enables basic storage and retrieval of dates and times.
385
364
 
386
365
  #### ReminderRecurrenceFrequency
387
366
 
388
- | Members |
389
- | ------------- |
390
- | **`DAILY`** |
391
- | **`WEEKLY`** |
392
- | **`MONTHLY`** |
393
- | **`YEARLY`** |
367
+ | Members | Description |
368
+ | ------------- | --------------------------------------- |
369
+ | **`DAILY`** | The reminder repeats on a daily basis |
370
+ | **`WEEKLY`** | The reminder repeats on a weekly basis |
371
+ | **`MONTHLY`** | The reminder repeats on a monthly basis |
372
+ | **`YEARLY`** | The reminder repeats on a yearly basis |
394
373
 
395
374
  </docgen-api>
@@ -3,13 +3,12 @@ package dev.barooni.capacitor.calendar
3
3
  import android.content.ContentResolver
4
4
  import android.content.ContentValues
5
5
  import android.content.Context
6
+ import android.content.Intent
6
7
  import android.net.Uri
7
8
  import android.provider.CalendarContract
8
9
  import com.getcapacitor.JSArray
9
10
  import com.getcapacitor.JSObject
10
- import java.text.SimpleDateFormat
11
11
  import java.util.Calendar
12
- import java.util.Locale
13
12
  import java.util.TimeZone
14
13
 
15
14
  class CapacitorCalendar() {
@@ -105,16 +104,12 @@ class CapacitorCalendar() {
105
104
  title: String,
106
105
  calendarId: String?,
107
106
  location: String?,
108
- startDate: String?,
109
- endDate: String?,
107
+ startDate: Long?,
108
+ endDate: Long?,
110
109
  isAllDay: Boolean?,
111
110
  ): Uri? {
112
- val isoFormatter =
113
- SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX", Locale.getDefault()).apply {
114
- timeZone = TimeZone.getTimeZone("UTC")
115
- }
116
- val startMillis = startDate?.let { isoFormatter.parse(it)?.time } ?: Calendar.getInstance().timeInMillis
117
- val endMillis = endDate?.let { isoFormatter.parse(it)?.time } ?: (startMillis + 3600 * 1000)
111
+ val startMillis = startDate ?: Calendar.getInstance().timeInMillis
112
+ val endMillis = endDate ?: (startMillis + 3600 * 1000)
118
113
 
119
114
  val values =
120
115
  ContentValues().apply {
@@ -129,4 +124,11 @@ class CapacitorCalendar() {
129
124
 
130
125
  return context.contentResolver.insert(CalendarContract.Events.CONTENT_URI, values)
131
126
  }
127
+
128
+ @Throws(Exception::class)
129
+ fun openCalendar(timestamp: Long): Intent {
130
+ return Intent(Intent.ACTION_VIEW).apply {
131
+ data = Uri.parse("content://com.android.calendar/time/$timestamp")
132
+ }
133
+ }
132
134
  }
@@ -178,8 +178,8 @@ class CapacitorCalendarPlugin : Plugin() {
178
178
  ?: throw Exception("[CapacitorCalendar.${::createEvent.name}] A title for the event was not provided")
179
179
  val calendarId = call.getString("calendarId")
180
180
  val location = call.getString("location")
181
- val startDate = call.getString("startDate")
182
- val endDate = call.getString("endDate")
181
+ val startDate = call.getLong("startDate")
182
+ val endDate = call.getLong("endDate")
183
183
  val isAllDay = call.getBoolean("isAllDay", false)
184
184
 
185
185
  val eventUri = implementation.createEvent(context, title, calendarId, location, startDate, endDate, isAllDay)
@@ -209,4 +209,15 @@ class CapacitorCalendarPlugin : Plugin() {
209
209
  call.unimplemented("[CapacitorCalendar.${::createReminder.name}] Not implemented on Android")
210
210
  return
211
211
  }
212
+
213
+ @PluginMethod(returnType = PluginMethod.RETURN_NONE)
214
+ fun openCalendar(call: PluginCall) {
215
+ val timestamp = call.getLong("date") ?: System.currentTimeMillis()
216
+ try {
217
+ return activity.startActivity(implementation.openCalendar(timestamp))
218
+ } catch (error: Exception) {
219
+ call.reject("", "[CapacitorCalendar.${::openCalendar.name}] Unable to open calendar")
220
+ return
221
+ }
222
+ }
212
223
  }