@ebarooni/capacitor-calendar 0.6.1 → 0.7.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 (33) hide show
  1. package/README.md +28 -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 +61 -783
  5. package/dist/esm/definitions.d.ts +20 -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 +5 -2
  22. package/dist/esm/web.js +3 -0
  23. package/dist/esm/web.js.map +1 -1
  24. package/dist/plugin.cjs.js +61 -2
  25. package/dist/plugin.cjs.js.map +1 -1
  26. package/dist/plugin.js +61 -2
  27. package/dist/plugin.js.map +1 -1
  28. package/ios/Plugin/CapacitorCalendar.swift +31 -2
  29. package/ios/Plugin/CapacitorCalendarPlugin.m +1 -0
  30. package/ios/Plugin/CapacitorCalendarPlugin.swift +20 -2
  31. package/ios/Plugin/CapacitorCalendarPluginError.swift +1 -0
  32. package/ios/Plugin/EventCreationParameters.swift +2 -2
  33. 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,7 @@ permissions can be found below:
78
79
  * [`getDefaultRemindersList()`](#getdefaultreminderslist)
79
80
  * [`getRemindersLists()`](#getreminderslists)
80
81
  * [`createReminder(...)`](#createreminder)
82
+ * [`openCalendar(...)`](#opencalendar)
81
83
  * [Interfaces](#interfaces)
82
84
  * [Type Aliases](#type-aliases)
83
85
  * [Enums](#enums)
@@ -210,14 +212,14 @@ Retrieves the default calendar set on the device.
210
212
  ### createEvent(...)
211
213
 
212
214
  ```typescript
213
- createEvent(options: { title: string; calendarId?: string; location?: string; startDate?: Date; endDate?: Date; isAllDay?: boolean; }) => Promise<{ eventCreated: boolean; }>
215
+ createEvent(options: { title: string; calendarId?: string; location?: string; startDate?: number; endDate?: number; isAllDay?: boolean; }) => Promise<{ eventCreated: boolean; }>
214
216
  ```
215
217
 
216
218
  Creates an event with the provided options.
217
219
 
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. |
220
+ | Param | Type | Description |
221
+ | ------------- | --------------------------------------------------------------------------------------------------------------------------------- | --------------------------------- |
222
+ | **`options`** | <code>{ title: string; calendarId?: string; location?: string; startDate?: number; endDate?: number; isAllDay?: boolean; }</code> | - Options for creating the event. |
221
223
 
222
224
  **Returns:** <code>Promise&lt;{ eventCreated: boolean; }&gt;</code>
223
225
 
@@ -267,6 +269,21 @@ Creates a reminder with the provided options.
267
269
  --------------------
268
270
 
269
271
 
272
+ ### openCalendar(...)
273
+
274
+ ```typescript
275
+ openCalendar(options: { date?: number; }) => Promise<void>
276
+ ```
277
+
278
+ Opens the calendar app. Since the user leaves your app, use this method with caution.
279
+
280
+ | Param | Type | Description |
281
+ | ------------- | ------------------------------- | ----------------------------------- |
282
+ | **`options`** | <code>{ date?: number; }</code> | - Options for opening the calendar. |
283
+
284
+ --------------------
285
+
286
+
270
287
  ### Interfaces
271
288
 
272
289
 
@@ -275,7 +292,7 @@ Creates a reminder with the provided options.
275
292
 
276
293
  #### Calendar
277
294
 
278
- Represents a calendar object with an ID and title.
295
+ Represents a calendar object.
279
296
 
280
297
  | Prop | Type |
281
298
  | ----------- | ------------------- |
@@ -283,57 +300,6 @@ Represents a calendar object with an ID and title.
283
300
  | **`title`** | <code>string</code> |
284
301
 
285
302
 
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
303
  #### RemindersList
338
304
 
339
305
 
@@ -385,11 +351,11 @@ Enables basic storage and retrieval of dates and times.
385
351
 
386
352
  #### ReminderRecurrenceFrequency
387
353
 
388
- | Members |
389
- | ------------- |
390
- | **`DAILY`** |
391
- | **`WEEKLY`** |
392
- | **`MONTHLY`** |
393
- | **`YEARLY`** |
354
+ | Members | Description |
355
+ | ------------- | --------------------------------------- |
356
+ | **`DAILY`** | The reminder repeats on a daily basis |
357
+ | **`WEEKLY`** | The reminder repeats on a weekly basis |
358
+ | **`MONTHLY`** | The reminder repeats on a monthly basis |
359
+ | **`YEARLY`** | The reminder repeats on a yearly basis |
394
360
 
395
361
  </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
  }