void sortify_date(const char *s, int len, string &key) { const char *year_end; const char *year_start = find_year(s, s + len, &year_end); if (!year_start) { // Things without years are often `forthcoming', so it makes sense // that they sort after things with explicit years. key += 'A'; sortify_words(s, s + len, 0, key); return; } int n = year_end - year_start; while (n < 4) { key += '0'; n++; } while (year_start < year_end) key += *year_start++; int m = find_month(s, s + len); if (m < 0) return; key += 'A' + m; const char *day_end; const char *day_start = find_day(s, s + len, &day_end); if (!day_start) return; if (day_end - day_start == 1) key += '0'; while (day_start < day_end) key += *day_start++; }
/* Test if a year is a leap year */ void date_isleap(enum nilop op) { int y, t = 0; decNumber x; getX(&x); if (! find_year(&x, &y)) t = isleap(y); fin_tst(t); }
const char *reference::get_year(const char **endp) const { if (field_index['D'] != NULL_FIELD_INDEX) { string &date = field[field_index['D']]; const char *start = date.contents(); const char *end = start + date.length(); return find_year(start, end, endp); } else return 0; }
/* Date of Easter. Input is the year and output is a date. * The input can either be specified as an integer year or as a * valid date in the current format. */ decNumber *dateEaster(decNumber *res, const decNumber *x) { int y; if (find_year(x, &y)) { set_NaN(res); return res; } else { int m, d; easter(y, &m, &d); build_date(res, y, m, d); } return res; }
int main() { head hd; LIBRARY* lib; int count = 1; hd.name = NULL; hd.year = NULL; add(&hd, "2121212", "kelebek", 2010); add(&hd, "7867667", "osman", 2008); printf("Name ____\n"); list_name( &hd ); printf("Year ____\n"); list_year( &hd ); find_name(&hd, "kamil"); printf("__\n"); find_year(&hd, 2012); return 0; }