Keep parsed values in date if parse was OK, but no valid date.
[gedcom-parse.git] / gedcom / date.c
index 40cb18a7115eca0c5a86f2600e6c73b54b311dee..9c086e7e2494ccb4de39d7517826ff574acbe710 100644 (file)
@@ -336,7 +336,7 @@ int numbers_to_strings(struct date *d)
     if (d->day != -1)
       sprintf(d->day_str, "%d", d->day);
     
-    if (d->month != -1)
+    if (d->month > 0 && d->month <= max_month[d->cal])
       strcpy(d->month_str, month_name[d->cal][d->month - 1]);
     
     if (d->year_type == YEAR_SINGLE)
@@ -405,12 +405,14 @@ struct date_value* gedcom_new_date_value(const struct date_value* copy_from)
 struct date_value gedcom_parse_date(const char* line_value)
 {
   int result = 0;
+  init_date(&dv_s.date1);
+  init_date(&dv_s.date2);
   init_date(&date_s);
   init_date(&def_date);
   curr_line_value = line_value;
   if (compat_mode(C_NO_REQUIRED_VALUES)
-      && !strncmp(curr_line_value, "-", 2)) {
-    gedcom_date_error(_("Empty value changed to '-'"));
+      && !strncmp(curr_line_value, VALUE_IF_MISSING, 2)) {
+    gedcom_date_error(_("Empty value changed to '%s'"), VALUE_IF_MISSING);
     result = 1;
   }
   else {
@@ -424,7 +426,7 @@ struct date_value gedcom_parse_date(const char* line_value)
   }
   if (result != 0) {
     gedcom_date_error(_("Putting date in 'phrase' member"));
-    make_date_value(DV_PHRASE, &def_date, &def_date, curr_line_value);
+    make_date_value(DV_PHRASE, &dv_s.date1, &dv_s.date2, curr_line_value);
   }
   return dv_s;
 }