}
}
+/**
+ * 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,
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]);