/* Monolith calendar widget. * - by Richard W.M. Jones * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * $Id: ml_calendar_lib.c,v 1.5 2003/02/22 12:56:24 rich Exp $ */ #include "config.h" #include #include #ifdef HAVE_TIME_H #include #endif #include "ml_calendar_lib.h" /* Return the current month as a string. */ const char * _ml_calendar_text_month (int mm) { switch (mm) { case 1: return "January"; case 2: return "February"; case 3: return "March"; case 4: return "April"; case 5: return "May"; case 6: return "June"; case 7: return "July"; case 8: return "August"; case 9: return "September"; case 10: return "October"; case 11: return "November"; case 12: return "December"; } abort (); } /* Return the first weekday of the month (range 0 - 6). I don't know an * easier way to do this. */ int _ml_calendar_first_wday_of_month (int mm, int yyyy) { struct tm tm; tm.tm_sec = 0; tm.tm_min = 0; tm.tm_hour = 12; tm.tm_mday = 1; tm.tm_mon = mm-1; tm.tm_year = yyyy-1900; tm.tm_wday = -1; tm.tm_yday = -1; tm.tm_isdst = 0; mktime (&tm); assert (tm.tm_wday >= 0); return tm.tm_wday; } /* Map the calendar number to a colour using a fixed table. This isn't * very satisfactory. In future we should allow users to choose the * colours of calendars. */ const char * _ml_calendar_colour (int resid) { static const char *cols[8] = { "black", "blue", "red", "magenta", "orange", "green", "pink", "purple" }; return cols[resid & 7]; }