From: Thomas Thurman Date: Mon, 31 Aug 2009 23:52:46 +0000 (-0400) Subject: days until practice night X-Git-Url: https://vcs.maemo.org/git/?a=commitdiff_plain;h=84ed87f007e12054dc56f8bebf5385455d13d2ef;hp=be4363263c937269e19b0646f5d82627f2047aff;p=belltower days until practice night --- diff --git a/belltower.c b/belltower.c index 89e9574..dd1bcb0 100644 --- a/belltower.c +++ b/belltower.c @@ -281,6 +281,43 @@ distance_to_tower_str (tower *details) } } +/** + * Returns the number of days from today until + * the tower's practice night. If the tower's + * practice night is unknown, returns 9: this + * means that such towers always sort to the end. + */ +static gint +days_until_practice_night (tower *details) +{ + /* let's not use the date parsing routines, because + * we might get confused by locales, and the day names + * used in Dove are constant + */ + time_t now = time (NULL); + struct tm *calendar = localtime (&now); + const char* dove_days = "SunMonTueWedThuFriSat"; + char *found; + gint practice_night; + + if (strcmp (details->fields[FieldPracticeNight], "")==0) + { + /* we don't know */ + return 9; + } + + found = strstr (dove_days, details->fields[FieldPracticeNight]); + + if (!found) + { + return 9; + } + + practice_night = (found-dove_days)/3; + + return ((practice_night+7)-calendar->tm_wday)%7; +} + static void call_dbus (DBusBusType type, char *name, @@ -798,7 +835,9 @@ found_tower_new (tower *basis) basis->fields[FieldPlace]); break; case TOWERSORT_PRACTICE: - result->sortkey = g_strdup ("FIXME"); + result->sortkey = g_strdup_printf ("%d %s", + days_until_practice_night (basis), + basis->fields[FieldPlace]); break; case TOWERSORT_BELLS: result->sortkey = g_strdup_printf ("%10s", basis->fields[FieldBells]);