diff --git a/src/libiso8601/calc.c b/src/libiso8601/calc.c index 6381274..3c0ac11 100644 --- a/src/libiso8601/calc.c +++ b/src/libiso8601/calc.c @@ -295,6 +295,31 @@ int iso8601_from_cal(struct iso8601_date* date, int year, int month, int day) +int iso8601_from_ord(struct iso8601_date* date, int year, int oday) +{ + // check for domain errors + if(oday < 1 || oday > (iso8601_isleap(year) ? 366 : 365)) { + errno = EDOM; + return -1; + } + + // perform year calculation + if(_from_year(date, year)) return -1; + + // now simply add number of days elapsed this year + date->day += oday - 1; + + return 0; +} + + + +int iso8601_from_week(struct iso8601_date* date, int isoyear, int week, int wday) +{ +} + + + /* options for text editors kate: replace-trailing-space-save true; space-indent true; tab-width 4; vim: expandtab:ts=4:sw=4 diff --git a/src/tests/printer.c b/src/tests/printer.c index bd5c2b9..1b7a7b6 100644 --- a/src/tests/printer.c +++ b/src/tests/printer.c @@ -142,6 +142,28 @@ void do_details_ordinal(struct iso8601_details* dt_out, const struct iso8601_det dt_out->date_prec = iso8601_prec_ord; } +void do_details_week(struct iso8601_details* dt_out, const struct iso8601_details* dt_in) +{ + memcpy(dt_out, dt_in, sizeof(struct iso8601_details)); + dt_out->tz_sec = 0; + dt_out->date_prec = iso8601_prec_week; +} + +void do_details_week_day(struct iso8601_details* dt_out, const struct iso8601_details* dt_in) +{ + memcpy(dt_out, dt_in, sizeof(struct iso8601_details)); + dt_out->tz_sec = 0; + dt_out->date_prec = iso8601_prec_wday; + dt_out->time_prec = iso8601_prec_none; +} + +void do_details_week_full(struct iso8601_details* dt_out, const struct iso8601_details* dt_in) +{ + memcpy(dt_out, dt_in, sizeof(struct iso8601_details)); + dt_out->tz_sec = 0; + dt_out->date_prec = iso8601_prec_wday; +} + struct test { @@ -169,6 +191,9 @@ const struct test tests[] = { { "Local year", do_details_local_year }, { "Ordinal date", do_details_ordinal_date }, { "Ordinal full", do_details_ordinal }, + { "Week number", do_details_week }, + { "Week date", do_details_week_day }, + { "Week full", do_details_week_full }, { 0, 0 } };