X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;ds=sidebyside;f=gedcom%2Fdate.c;h=23a689e21abd7b02848a4c1a845397ac099161ab;hb=c07434e2fd111d986fde2226828084ac44743dd6;hp=3ce3783ea5d16a022a0ce87f5f6f2b471a0a47bc;hpb=c241fd2658149a029f8c9119007341d17ffd748c;p=gedcom-parse.git diff --git a/gedcom/date.c b/gedcom/date.c index 3ce3783..23a689e 100644 --- a/gedcom/date.c +++ b/gedcom/date.c @@ -147,7 +147,7 @@ int numbers_to_sdn(struct date *d) int result = 0; if (d->cal == CAL_UNKNOWN) { d->type = DATE_UNRECOGNIZED; - gedcom_error(_("Cannot compute SDN for unknown calendar type")); + gedcom_date_error(_("Cannot compute SDN for unknown calendar type")); result = 1; } else { @@ -171,7 +171,7 @@ int numbers_to_sdn(struct date *d) } } else { - gedcom_error(_("Year has to be given in bounded date")); + gedcom_date_error(_("Year has to be given in bounded date")); result = 1; } } @@ -182,7 +182,7 @@ int numbers_to_sdn(struct date *d) d->sdn1 = checkedCalToSdn(d->cal, begin_date.year, begin_date.month, begin_date.day); if (d->sdn1 == -1) { - gedcom_error(_("Error converting date: year %d, month %d, day %d"), + gedcom_date_error(_("Error converting date: year %d, month %d, day %d"), begin_date.year, begin_date.month, begin_date.day); result = 1; } @@ -191,7 +191,7 @@ int numbers_to_sdn(struct date *d) d->sdn2 = checkedCalToSdn(d->cal, end_date.year, end_date.month, end_date.day); if (d->sdn2 == -1) { - gedcom_error(_("Error converting date: year %d, month %d, day %d"), + gedcom_date_error(_("Error converting date: year %d, month %d, day %d"), end_date.year, end_date.month, end_date.day); result = 1; } @@ -210,7 +210,7 @@ int sdn_to_numbers(struct date *d) { int result = 0; if (d->cal == CAL_UNKNOWN) { - gedcom_error(_("Cannot compute from SDN for unknown calendar type")); + gedcom_date_error(_("Cannot compute from SDN for unknown calendar type")); result = 1; } else { @@ -218,38 +218,38 @@ int sdn_to_numbers(struct date *d) struct date end_date; if (d->sdn1 <= 0) { - gedcom_error(_("SDN 1 should be bigger than zero")); + gedcom_date_error(_("SDN 1 should be bigger than zero")); result = 1; } else { copy_date(&begin_date, d); if (!checkedSdnToCal(d->cal, d->sdn1, &begin_date.year, &begin_date.month, &begin_date.day)) { - gedcom_error(_("SDN 1 isn't a valid date in the given calendar")); + gedcom_date_error(_("SDN 1 isn't a valid date in the given calendar")); result = 1; } else { switch (d->type) { case DATE_EXACT: if (d->sdn2 != -1) { - gedcom_error(_("SDN 2 should be -1 for exact dates")); + gedcom_date_error(_("SDN 2 should be -1 for exact dates")); result = 1; } break; case DATE_BOUNDED: if (d->sdn2 <= 0) { - gedcom_error(_("SDN 2 should be bigger than zero")); + gedcom_date_error(_("SDN 2 should be bigger than zero")); result = 1; } else if (d->sdn2 <= d->sdn1) { - gedcom_error(_("SDN 2 should be bigger than SDN 1")); + gedcom_date_error(_("SDN 2 should be bigger than SDN 1")); result = 1; } else { copy_date(&end_date, d); if (!checkedSdnToCal(d->cal, d->sdn2, &end_date.year, &end_date.month, &end_date.day)) { - gedcom_error(_("SDN 2 isn't a valid date in the given calendar")); + gedcom_date_error(_("SDN 2 isn't a valid date in the given calendar")); result = 1; } else { @@ -270,7 +270,7 @@ int sdn_to_numbers(struct date *d) } } else { - gedcom_error(_("SDN1/SDN2 isn't a bounded date")); + gedcom_date_error(_("SDN1/SDN2 isn't a bounded date")); result = 1; } } @@ -296,7 +296,7 @@ int strings_to_numbers(struct date *d) { int result = 0; if (d->cal == CAL_UNKNOWN) { - gedcom_error(_("Cannot compute months for unknown calendar type")); + gedcom_date_error(_("Cannot compute months for unknown calendar type")); result = 1; } else { @@ -329,14 +329,14 @@ int numbers_to_strings(struct date *d) { int result = 0; if (d->cal == CAL_UNKNOWN) { - gedcom_error(_("Cannot compute month names for unknown calendar type")); + gedcom_date_error(_("Cannot compute month names for unknown calendar type")); result = 1; } else { 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) @@ -347,11 +347,77 @@ int numbers_to_strings(struct date *d) return result; } -int gedcom_normalize_date(Date_input input, struct date_value *val) +/** This function can be called to ensure that an updated date_value is + consistent, i.e. all its struct fields are consistent with each other. + Depending on which fields you have updated, you should give the correct + \c compute_from field. + + The following table gives an overview of the input and output parameters + (the calendar type \c cal is always an input parameter, and should not be + \c CAL_UNKNOWN): +
compute_from | +input parameters | +output parameters | +
---|---|---|
DI_FROM_STRINGS |
+ day_str, month_str, year_str |
+ day, month, year, year_type |
+
DI_FROM_NUMBERS |
+ day, month, year, year_type |
+ day_str, month_str, year_str |
+
DI_FROM_SDN |
+ type, sdn1, sdn2 |
+ day, month, year |
+