@@ -54,9 +54,39 @@ object EventHandler : DataRowHandler() {
5454
5555 override fun forMimeType () = Event .CONTENT_ITEM_TYPE
5656
57+ override fun handle (values : ContentValues , contact : Contact ) {
58+ super .handle(values, contact)
59+
60+ val dateStr = values.getAsString(Event .START_DATE ) ? : return
61+ val full: Temporal ? = parseFullDate(dateStr)
62+ val partial: PartialDate ? = if (full == null )
63+ parsePartialDate(dateStr)
64+ else
65+ null
66+
67+ if (full != null || partial != null )
68+ when (values.getAsInteger(Event .TYPE )) {
69+ Event .TYPE_ANNIVERSARY ->
70+ contact.anniversary =
71+ if (full != null ) Anniversary (full) else Anniversary (partial)
72+
73+ Event .TYPE_BIRTHDAY ->
74+ contact.birthDay = if (full != null ) Birthday (full) else Birthday (partial)
75+ /* Event.TYPE_OTHER,
76+ Event.TYPE_CUSTOM */
77+ else -> {
78+ val abDate = if (full != null ) XAbDate (full) else XAbDate (partial)
79+ val label = values.getAsString(Event .LABEL ).trimToNull()
80+ contact.customDates + = LabeledProperty (abDate, label)
81+ }
82+ }
83+ }
84+
5785 /* *
5886 * Tries to parse a contact event date string into a [Temporal] object using multiple acceptable formats.
5987 *
88+ * "Full" means "with year" in this context.
89+ *
6090 * @param dateString The contact event date string to parse.
6191 *
6292 * @return The parsed [Temporal] if successful, or `null` if none of the formats match. If format is:
@@ -66,6 +96,7 @@ object EventHandler : DataRowHandler() {
6696 */
6797 @VisibleForTesting
6898 internal fun parseFullDate (dateString : String ): Temporal ? {
99+ // try to parse as full date-time
69100 for (formatter in fullDateTimeFormats) {
70101 try {
71102 return OffsetDateTime .parse(dateString, formatter)
@@ -74,7 +105,7 @@ object EventHandler : DataRowHandler() {
74105 }
75106 }
76107
77- // try parsing as full date only (no time)
108+ // try to parse as full date (without time)
78109 try {
79110 return LocalDate .parse(dateString, fullDateFormat)
80111 } catch (_: DateTimeParseException ) {
@@ -95,6 +126,8 @@ object EventHandler : DataRowHandler() {
95126 * Does some preprocessing to handle the 'Z' suffix and strip nanoseconds
96127 * (both not supported by [PartialDate.parse]).
97128 *
129+ * "Partial" means "without year" in this context.
130+ *
98131 * @param dateString The date string to parse.
99132 * @return The parsed [PartialDate] or `null` if parsing fails.
100133 */
@@ -111,7 +144,7 @@ object EventHandler : DataRowHandler() {
111144
112145 // PartialDate.parse() does not accept fractions of seconds, so strip them if present
113146 val subSecondsRegex = " \\ .\\ d+" .toRegex() // 2025-12-05T010203.456+00:30
114- // ^^^^ (number of digits may vary)
147+ // ^^^^ (number of digits may vary)
115148 val subSecondsMatch = subSecondsRegex.find(withoutZ)
116149 val withoutSubSeconds = if (subSecondsMatch != null )
117150 withoutZ.removeRange(subSecondsMatch.range)
@@ -125,32 +158,4 @@ object EventHandler : DataRowHandler() {
125158 }
126159 }
127160
128- override fun handle (values : ContentValues , contact : Contact ) {
129- super .handle(values, contact)
130-
131- val dateStr = values.getAsString(Event .START_DATE ) ? : return
132- val full: Temporal ? = parseFullDate(dateStr)
133- val partial: PartialDate ? = if (full == null )
134- parsePartialDate(dateStr)
135- else
136- null
137-
138- if (full != null || partial != null )
139- when (values.getAsInteger(Event .TYPE )) {
140- Event .TYPE_ANNIVERSARY ->
141- contact.anniversary =
142- if (full != null ) Anniversary (full) else Anniversary (partial)
143-
144- Event .TYPE_BIRTHDAY ->
145- contact.birthDay = if (full != null ) Birthday (full) else Birthday (partial)
146- /* Event.TYPE_OTHER,
147- Event.TYPE_CUSTOM */
148- else -> {
149- val abDate = if (full != null ) XAbDate (full) else XAbDate (partial)
150- val label = values.getAsString(Event .LABEL ).trimToNull()
151- contact.customDates + = LabeledProperty (abDate, label)
152- }
153- }
154- }
155-
156161}
0 commit comments