Skip to content
This repository was archived by the owner on Jun 9, 2025. It is now read-only.

Commit 75e5be4

Browse files
Added recuridTimezone and adapted logic for RecurrenceId (#100)
* Added recuridTimezone and adapted logic for RecurrenceId * minor code improvement
1 parent 8c34e81 commit 75e5be4

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

src/main/java/at/bitfire/ical4android/JtxICalObject.kt

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ open class JtxICalObject(
106106
var exdate: String? = null //only for recurring events, see https://tools.ietf.org/html/rfc5545#section-3.8.5.1
107107
var rdate: String? = null //only for recurring events, see https://tools.ietf.org/html/rfc5545#section-3.8.5.2
108108
var recurid: String? = null //only for recurring events, see https://tools.ietf.org/html/rfc5545#section-3.8.5
109-
109+
var recuridTimezone: String? = null
110110
//var rstatus: String? = null
111111

112112
var collectionId: Long = collection.id
@@ -416,7 +416,15 @@ open class JtxICalObject(
416416
}
417417
iCalObject.exdate = exdateList.toTypedArray().joinToString(separator = ",")
418418
}
419-
is RecurrenceId -> iCalObject.recurid = prop.value
419+
is RecurrenceId -> {
420+
iCalObject.recurid = prop.date.toString()
421+
iCalObject.recuridTimezone = when {
422+
prop.date is DateTime && prop.timeZone != null -> prop.timeZone.id
423+
prop.date is DateTime && prop.isUtc -> TimeZone.getTimeZone("UTC").id
424+
prop.date is DateTime && !prop.isUtc && prop.timeZone == null -> null
425+
else -> TZ_ALLDAY // prop.date is Date (and not DateTime), therefore it must be Allday
426+
}
427+
}
420428

421429
//is RequestStatus -> iCalObject.rstatus = prop.value
422430

@@ -932,10 +940,12 @@ open class JtxICalObject(
932940
props += RRule(rrule)
933941
}
934942
recurid?.let { recurid ->
935-
props += if(dtstartTimezone == TZ_ALLDAY)
936-
RecurrenceId(Date(recurid))
937-
else
938-
RecurrenceId(DateTime(recurid))
943+
props += when {
944+
recuridTimezone == TZ_ALLDAY -> RecurrenceId(Date(recurid))
945+
recuridTimezone == TimeZone.getTimeZone("UTC").id -> RecurrenceId(DateTime(recurid).apply { this.isUtc = true })
946+
recuridTimezone.isNullOrEmpty() -> RecurrenceId(DateTime(recurid).apply { this.isUtc = false })
947+
else -> RecurrenceId(DateTime(recurid, TimeZoneRegistryFactory.getInstance().createRegistry().getTimeZone(recuridTimezone)))
948+
}
939949
}
940950

941951
rdate?.let { rdateString ->
@@ -1428,6 +1438,7 @@ duration?.let(props::add)
14281438
this.rdate = newData.rdate
14291439
this.exdate = newData.exdate
14301440
this.recurid = newData.recurid
1441+
this.recuridTimezone = newData.recuridTimezone
14311442

14321443

14331444
this.categories = newData.categories
@@ -1483,6 +1494,7 @@ duration?.let(props::add)
14831494
values.getAsString(JtxContract.JtxICalObject.EXDATE)?.let { exdate -> this.exdate = exdate }
14841495
values.getAsString(JtxContract.JtxICalObject.RDATE)?.let { rdate -> this.rdate = rdate }
14851496
values.getAsString(JtxContract.JtxICalObject.RECURID)?.let { recurid -> this.recurid = recurid }
1497+
values.getAsString(JtxContract.JtxICalObject.RECURID_TIMEZONE)?.let { recuridTimezone -> this.recuridTimezone = recuridTimezone }
14861498

14871499
this.collectionId = collection.id
14881500
values.getAsString(JtxContract.JtxICalObject.DIRTY)?.let { dirty -> this.dirty = dirty == "1" || dirty == "true" }
@@ -1709,6 +1721,7 @@ duration?.let(props::add)
17091721
put(JtxContract.JtxICalObject.RDATE, rdate)
17101722
put(JtxContract.JtxICalObject.EXDATE, exdate)
17111723
put(JtxContract.JtxICalObject.RECURID, recurid)
1724+
put(JtxContract.JtxICalObject.RECURID_TIMEZONE, recuridTimezone)
17121725

17131726
put(JtxContract.JtxICalObject.FILENAME, fileName)
17141727
put(JtxContract.JtxICalObject.ETAG, eTag)

src/main/java/at/techbee/jtx/JtxContract.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ object JtxContract {
4242
const val AUTHORITY = "at.techbee.jtx.provider"
4343

4444
/** The version of this SyncContentProviderContract */
45-
const val VERSION = 5
45+
const val VERSION = 6
4646

4747
/** Constructs an Uri for the Jtx Sync Adapter with the given Account
4848
* @param [account] The account that should be appended to the Base Uri
@@ -450,6 +450,17 @@ object JtxContract {
450450
*/
451451
const val RECURID = "recurid"
452452

453+
/**
454+
* Purpose: This property is used in conjunction with the "UID" and
455+
* "SEQUENCE" properties to identify a specific instance of a
456+
* recurring "VEVENT", "VTODO", or "VJOURNAL" calendar component.
457+
* The property value is the original value of the "DTSTART" property
458+
* of the recurrence instance, ie. a DATE or DATETIME value e.g. "20211101T160000".
459+
* Must be null for non-recurring and original events from which recurring events are derived.
460+
* Type: [String?]
461+
*/
462+
const val RECURID_TIMEZONE = "recuridtimezone"
463+
453464
/**
454465
* Stores the reference to the original event from which the recurring event was derived.
455466
* This value is NULL for the orignal event or if the event is not recurring

0 commit comments

Comments
 (0)