Re: [HELP] Time keeps on slipping,slipping... (was: Backstab crashing)

From: Peter Ajamian (peter@pajamian.dhs.org)
Date: 01/27/01


George Greer wrote:
> >Flexibility is also the reason for keeping the days per week and the
> >number of days per month separate (instead of doing, say, MUD_DAY_PER_WEEK
> >and MUD_WEEK_PER_MONTH).  If you wanted to model our calendar system, for
> >instance, you could not because the number of days in a month cannot
> >usually be evenly divided by the number of days in a week (the exception
> >is February in non-leap years) and is dependent upon the month.
>
> So how about:
> unsigned char days_per_month[] = { 30, 28, 31, 31, 31, 30, 15, 45, ... };
>
> The only problem being when people start changing defines and not changing
> the values.  We'll probably have to write a wrapper function that checks
> the bounds to make sure it isn't exceeded.

You can do it like this to make a best guess (an average) for the days
in the month of an invalid month...

/* 0 MUST be last */
unsigned char days_per_month[] = { 31, 28, 31, 30, 31, ... , 0}

unsigned char get_days_in_month(int month)
{
  int retval = 0;    /* This needs to be an integer to have enough room
                        for the sum total.  If it were in it's own
                        function I'd use a different algorythm for the
                        average or try to fake a larger data type than
                        long (yes I know gcc has long long but it's not
                        portable) */
  int max_months = strlen((char*)days_per_month);
  char buf[MAX_INPUT_LENGTH];

  month--; /* Assumes that the first month is 1, not 0 */
  if (month < 0 || month >= max_months) {
    sprintf(buf, "SYSERR: %d passed as month to get_days_in_month",
month+1);
    mudlog(buf, BRF, LVL_IMPL, TRUE);

    /* This should probably be in it's own function, but, oh well... */
    for (month = 0; month < max_months; month++)
      retval += days_per_month[month];

    retval /= months;
    return (unsigned char)retval;
  }

  return days_per_month[month];
}

Regards, Peter

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/03/01 PST