12156d
diff -up evolution-ews-3.28.5/src/addressbook/CMakeLists.txt.birthday-date evolution-ews-3.28.5/src/addressbook/CMakeLists.txt
12156d
--- evolution-ews-3.28.5/src/addressbook/CMakeLists.txt.birthday-date	2018-07-30 16:01:00.000000000 +0200
12156d
+++ evolution-ews-3.28.5/src/addressbook/CMakeLists.txt	2019-10-23 14:13:13.158137514 +0200
12156d
@@ -45,6 +45,7 @@ target_compile_options(ebookbackendews P
12156d
 	${LIBEBOOK_CFLAGS}
12156d
 	${LIBEDATABOOK_CFLAGS}
12156d
 	${LIBEDATASERVER_CFLAGS}
12156d
+	${LIBICAL_CFLAGS}
12156d
 	${MSPACK_CFLAGS}
12156d
 	${SOUP_CFLAGS}
12156d
 )
12156d
@@ -60,6 +61,7 @@ target_include_directories(ebookbackende
12156d
 	${LIBEBOOK_INCLUDE_DIRS}
12156d
 	${LIBEDATABOOK_INCLUDE_DIRS}
12156d
 	${LIBEDATASERVER_INCLUDE_DIRS}
12156d
+	${LIBICAL_INCLUDE_DIRS}
12156d
 	${MSPACK_INCLUDE_DIRS}
12156d
 	${SOUP_INCLUDE_DIRS}
12156d
 )
12156d
@@ -70,6 +72,7 @@ target_link_libraries(ebookbackendews
12156d
 	${LIBEBOOK_LDFLAGS}
12156d
 	${LIBEDATABOOK_LDFLAGS}
12156d
 	${LIBEDATASERVER_LDFLAGS}
12156d
+	${LIBICAL_LDFLAGS}
12156d
 	${MATH_LDFLAGS}
12156d
 	${MSPACK_LDFLAGS}
12156d
 	${SOUP_LDFLAGS}
12156d
diff -up evolution-ews-3.28.5/src/addressbook/e-book-backend-ews.c.birthday-date evolution-ews-3.28.5/src/addressbook/e-book-backend-ews.c
12156d
--- evolution-ews-3.28.5/src/addressbook/e-book-backend-ews.c.birthday-date	2019-10-23 14:04:31.100144733 +0200
12156d
+++ evolution-ews-3.28.5/src/addressbook/e-book-backend-ews.c	2019-10-23 14:15:41.719135459 +0200
12156d
@@ -37,6 +37,8 @@
12156d
 #include <glib/gstdio.h>
12156d
 #include <glib/gi18n-lib.h>
12156d
 
12156d
+#include <libical/ical.h>
12156d
+
12156d
 #include <libedata-book/libedata-book.h>
12156d
 
12156d
 #include "server/e-ews-item-change.h"
12156d
@@ -268,29 +270,36 @@ ebews_populate_nick_name (EBookBackendEw
12156d
 }
12156d
 
12156d
 static void
12156d
+ebews_populate_date_value (EBookBackendEws *bbews,
12156d
+			   EContact *contact,
12156d
+			   EContactField field,
12156d
+			   time_t value)
12156d
+{
12156d
+	if (value > (time_t) 0) {
12156d
+		struct icaltimetype itt;
12156d
+
12156d
+		itt = icaltime_from_timet_with_zone (value, TRUE, icaltimezone_get_utc_timezone ());
12156d
+
12156d
+		if (icaltime_is_valid_time (itt) && !icaltime_is_null_time (itt)) {
12156d
+			EContactDate edate = { 0 };
12156d
+
12156d
+			edate.year = itt.year;
12156d
+			edate.month = itt.month;
12156d
+			edate.day = itt.day;
12156d
+
12156d
+			e_contact_set (contact, field, &edate);
12156d
+		}
12156d
+	}
12156d
+}
12156d
+
12156d
+static void
12156d
 ebews_populate_birth_date (EBookBackendEws *bbews,
12156d
 			   EContact *contact,
12156d
 			   EEwsItem *item,
12156d
 			   GCancellable *cancellable,
12156d
 			   GError **error)
12156d
 {
12156d
-	time_t bdate;
12156d
-	GDate date;
12156d
-	EContactDate edate;
12156d
-
12156d
-	bdate = e_ews_item_get_birthday (item);
12156d
-
12156d
-	if (bdate) {
12156d
-		g_date_clear (&date, 1);
12156d
-		g_date_set_time_t (&date, bdate);
12156d
-
12156d
-		edate.year = date.year;
12156d
-		edate.month = date.month;
12156d
-		edate.day = date.day;
12156d
-
12156d
-		if (g_date_valid (&date))
12156d
-			e_contact_set (contact, E_CONTACT_BIRTH_DATE, &edate);
12156d
-	}
12156d
+	ebews_populate_date_value (bbews, contact, E_CONTACT_BIRTH_DATE, e_ews_item_get_birthday (item));
12156d
 }
12156d
 
12156d
 static void
12156d
@@ -300,23 +309,7 @@ ebews_populate_anniversary (EBookBackend
12156d
 			    GCancellable *cancellable,
12156d
 			    GError **error)
12156d
 {
12156d
-	time_t bdate;
12156d
-	GDate date;
12156d
-	EContactDate edate;
12156d
-
12156d
-	bdate = e_ews_item_get_wedding_anniversary (item);
12156d
-
12156d
-	if (bdate) {
12156d
-		g_date_clear (&date, 1);
12156d
-		g_date_set_time_t (&date, bdate);
12156d
-
12156d
-		edate.year = date.year;
12156d
-		edate.month = date.month;
12156d
-		edate.day = date.day;
12156d
-
12156d
-		if (g_date_valid (&date))
12156d
-			e_contact_set (contact, E_CONTACT_ANNIVERSARY, &edate);
12156d
-	}
12156d
+	ebews_populate_date_value (bbews, contact, E_CONTACT_ANNIVERSARY, e_ews_item_get_wedding_anniversary (item));
12156d
 }
12156d
 
12156d
 static EContactPhoto *
12156d
@@ -600,34 +593,41 @@ ebews_set_full_name (ESoapMessage *msg,
12156d
 	e_contact_name_free (name);
12156d
 }
12156d
 
12156d
-/* TODO Set birth and anniversary dates */
12156d
 static void
12156d
-ebews_set_birth_date (ESoapMessage *message,
12156d
-                      EContact *contact)
12156d
+ebews_set_date_value (ESoapMessage *message,
12156d
+		      EContact *contact,
12156d
+		      EContactField field,
12156d
+		      const gchar *element_name)
12156d
 {
12156d
 	EContactDate *date;
12156d
-	gchar *birthday;
12156d
+	gchar *value;
12156d
 
12156d
-	date = e_contact_get (contact, E_CONTACT_BIRTH_DATE);
12156d
+	date = e_contact_get (contact, field);
12156d
 
12156d
 	if (!date)
12156d
 		return;
12156d
 
12156d
-	birthday = g_strdup_printf (
12156d
-		"%04d-%02d-%02dT00:00:00",
12156d
+	value = g_strdup_printf ("%04d-%02d-%02dT00:00:00Z",
12156d
 		date->year, date->month, date->day);
12156d
 
12156d
-	e_ews_message_write_string_parameter (message, "Birthday", NULL, birthday);
12156d
+	e_ews_message_write_string_parameter (message, element_name, NULL, value);
12156d
 
12156d
-	g_free (birthday);
12156d
+	e_contact_date_free (date);
12156d
+	g_free (value);
12156d
+}
12156d
 
12156d
+static void
12156d
+ebews_set_birth_date (ESoapMessage *message,
12156d
+                      EContact *contact)
12156d
+{
12156d
+	ebews_set_date_value (message, contact, E_CONTACT_BIRTH_DATE, "Birthday");
12156d
 }
12156d
 
12156d
 static void
12156d
 ebews_set_anniversary (ESoapMessage *message,
12156d
                        EContact *contact)
12156d
 {
12156d
-
12156d
+	ebews_set_date_value (message, contact, E_CONTACT_ANNIVERSARY, "WeddingAnniversary");
12156d
 }
12156d
 
12156d
 static void
12156d
@@ -838,30 +838,33 @@ ebews_set_full_name_changes (EBookBacken
12156d
 }
12156d
 
12156d
 static void
12156d
-ebews_set_birth_date_changes (EBookBackendEws *bbews,
12156d
-			      ESoapMessage *message,
12156d
+ebews_set_date_value_changes (ESoapMessage *message,
12156d
 			      EContact *new,
12156d
 			      EContact *old,
12156d
-			      gchar **out_new_change_key,
12156d
-			      GCancellable *cancellable,
12156d
-			      GError **error)
12156d
+			      EContactField field,
12156d
+			      const gchar *element_name)
12156d
 {
12156d
 	EContactDate *new_date, *old_date;
12156d
-	gchar *birthday;
12156d
 
12156d
 	if (!message)
12156d
 		return;
12156d
 
12156d
-	new_date = e_contact_get (new, E_CONTACT_BIRTH_DATE);
12156d
-	old_date = e_contact_get (old, E_CONTACT_BIRTH_DATE);
12156d
+	new_date = e_contact_get (new, field);
12156d
+	old_date = e_contact_get (old, field);
12156d
 
12156d
 	if (!e_contact_date_equal (new_date, old_date)) {
12156d
-		birthday = g_strdup_printf (
12156d
-			"%04d-%02d-%02dT00:00:00",
12156d
-			new_date->year, new_date->month, new_date->day);
12156d
+		if (new_date) {
12156d
+			gchar *value;
12156d
+
12156d
+			value = g_strdup_printf ("%04d-%02d-%02dT00:00:00Z",
12156d
+				new_date->year, new_date->month, new_date->day);
12156d
+
12156d
+			convert_contact_property_to_updatexml (message, element_name, value, "contacts", NULL, NULL);
12156d
 
12156d
-		convert_contact_property_to_updatexml (message, "Birthday", birthday, "contacts", NULL, NULL);
12156d
-		g_free (birthday);
12156d
+			g_free (value);
12156d
+		} else {
12156d
+			e_ews_message_add_delete_item_field (message, element_name, "contacts");
12156d
+		}
12156d
 	}
12156d
 
12156d
 	e_contact_date_free (new_date);
12156d
@@ -869,6 +872,18 @@ ebews_set_birth_date_changes (EBookBacke
12156d
 }
12156d
 
12156d
 static void
12156d
+ebews_set_birth_date_changes (EBookBackendEws *bbews,
12156d
+			      ESoapMessage *message,
12156d
+			      EContact *new,
12156d
+			      EContact *old,
12156d
+			      gchar **out_new_change_key,
12156d
+			      GCancellable *cancellable,
12156d
+			      GError **error)
12156d
+{
12156d
+	ebews_set_date_value_changes (message, new, old, E_CONTACT_BIRTH_DATE, "Birthday");
12156d
+}
12156d
+
12156d
+static void
12156d
 ebews_set_anniversary_changes (EBookBackendEws *bbews,
12156d
 			       ESoapMessage *message,
12156d
 			       EContact *new,
12156d
@@ -877,7 +892,7 @@ ebews_set_anniversary_changes (EBookBack
12156d
 			       GCancellable *cancellable,
12156d
 			       GError **error)
12156d
 {
12156d
-
12156d
+	ebews_set_date_value_changes (message, new, old, E_CONTACT_ANNIVERSARY, "WeddingAnniversary");
12156d
 }
12156d
 
12156d
 static void
12156d
@@ -1373,7 +1388,7 @@ static const struct field_element_mappin
12156d
 	{ E_CONTACT_SPOUSE, ELEMENT_TYPE_SIMPLE, "SpouseName", e_ews_item_get_spouse_name},
12156d
 	{ E_CONTACT_FAMILY_NAME, ELEMENT_TYPE_SIMPLE, "Surname", e_ews_item_get_surname},
12156d
 	{ E_CONTACT_GIVEN_NAME, ELEMENT_TYPE_COMPLEX, "GivenName", NULL, ebews_populate_givenname, ebews_set_givenname, ebews_set_givenname_changes},
12156d
-	{ E_CONTACT_BIRTH_DATE, ELEMENT_TYPE_COMPLEX, "WeddingAnniversary", NULL,  ebews_populate_anniversary, ebews_set_anniversary, ebews_set_anniversary_changes },
12156d
+	{ E_CONTACT_ANNIVERSARY, ELEMENT_TYPE_COMPLEX, "WeddingAnniversary", NULL,  ebews_populate_anniversary, ebews_set_anniversary, ebews_set_anniversary_changes },
12156d
 	{ E_CONTACT_PHOTO, ELEMENT_TYPE_COMPLEX, "Photo", NULL,  ebews_populate_photo, ebews_set_photo, ebews_set_photo_changes },
12156d
 
12156d
 	/* Should take of uid and changekey (REV) */
12156d
@@ -3515,6 +3530,7 @@ ebb_ews_get_backend_property (EBookBacke
12156d
 			e_contact_field_name (E_CONTACT_ADDRESS_WORK),
12156d
 			e_contact_field_name (E_CONTACT_ADDRESS_HOME),
12156d
 			e_contact_field_name (E_CONTACT_ADDRESS_OTHER),
12156d
+			e_contact_field_name (E_CONTACT_ANNIVERSARY),
12156d
 			e_contact_field_name (E_CONTACT_BIRTH_DATE),
12156d
 			e_contact_field_name (E_CONTACT_NOTE),
12156d
 			e_contact_field_name (E_CONTACT_PHOTO),