+
+int update_date(struct date_value** dv, struct tm* tm_ptr)
+{
+ int result;
+ struct date_value* dval = gedcom_new_date_value(NULL);
+ dval->type = DV_NO_MODIFIER;
+ dval->date1.cal = CAL_GREGORIAN;
+ dval->date1.day = tm_ptr->tm_mday;
+ dval->date1.month = tm_ptr->tm_mon + 1;
+ dval->date1.year = tm_ptr->tm_year + 1900;
+ result = gedcom_normalize_date(DI_FROM_NUMBERS, dval);
+
+ if (result == 0) {
+ if (*dv) free(*dv);
+ *dv = dval;
+ }
+ return result;
+}
+
+int update_time(char** tv, struct tm* tm_ptr)
+{
+ char tval[16];
+ sprintf(tval, "%02d:%02d:%02d",
+ tm_ptr->tm_hour, tm_ptr->tm_min, tm_ptr->tm_sec);
+
+ if (gom_set_string(tv, tval))
+ return 0;
+ else
+ return 1;
+}
+
+int gom_update_timestamp(struct change_date** chan, time_t t)
+{
+ int result = 1;
+ if (chan) {
+ if (! *chan) gom_set_new_change_date(chan);
+ if (*chan) {
+ struct tm *tm_ptr = localtime(&t);
+ result = 0;
+ result |= update_date(&((*chan)->date), tm_ptr);
+ result |= update_time(&((*chan)->time), tm_ptr);
+ }
+ }
+ return result;
+}
+
+int write_change_date(Gedcom_write_hndl hndl, int parent,
+ struct change_date *chan)
+{
+ int result = 0;
+
+ if (!chan) return 1;
+
+ result |= gedcom_write_element_str(hndl, ELT_SUB_CHAN, 0, parent, NULL);
+ if (chan->date)
+ result |= gedcom_write_element_date(hndl, ELT_SUB_CHAN_DATE, 0,
+ ELT_SUB_CHAN, chan->date);
+ if (chan->time)
+ result |= gedcom_write_element_str(hndl, ELT_SUB_CHAN_TIME, 0,
+ ELT_SUB_CHAN_DATE, chan->time);
+ if (chan->note)
+ result |= write_note_subs(hndl, ELT_SUB_CHAN, chan->note);
+ if (chan->extra)
+ result |= write_user_data(hndl, chan->extra);
+
+ return result;
+}