Branch: Tag:

2008-05-22

2008-05-22 23:56:44 by Martin Stjernholm <mast@lysator.liu.se>

No longer any need to handle days before the first day of the year in
month_from_yday; it doesn't work consistently anyway.

Fixed inconsistent handling of the leap day in Year.place: When using
the force flag and going from February 24th on a leap year to a
non-leap year it backed up to the 23rd, while Month.place keeps the
day. The behavior of Month.place seems slightly more natural.

Cleaned up the leap day handling in Month.place a bit. Functionality
is the same.

Fixed propagation of the force flag to the inherited place functions
in both Year.place and Month.place.

Rev: lib/modules/Calendar.pmod/Gregorian.pmod:1.11

88:   static array(int) month_from_yday(int y,int yd)   {   // [month,day-of-month,ndays,month-year-day] -  if (yd<1) return ({12,31+yd,32,335+year_leap_year(y-1)}); +  if (yd >= 1) {    int l=year_leap_year(y);    if (yd<32) return ({1,yd,31,1});    yd-=l;    switch (yd)    {    case 0..59: return ({2,yd-31+l,28+l,32}); -  case 60..90: return ({3,yd-59,31 ,60+year_leap_year(y)}); -  case 91..120: return ({4,yd-90,30 ,91+year_leap_year(y)}); -  case 121..151: return ({5,yd-120,31 ,121+year_leap_year(y)}); -  case 152..181: return ({6,yd-151,30 ,152+year_leap_year(y)}); -  case 182..212: return ({7,yd-181,31 ,182+year_leap_year(y)}); -  case 213..243: return ({8,yd-212,31 ,213+year_leap_year(y)}); -  case 244..273: return ({9,yd-243,30 ,244+year_leap_year(y)}); -  case 274..304: return ({10,yd-273,31,274+year_leap_year(y)}); -  case 305..334: return ({11,yd-304,30,305+year_leap_year(y)}); -  case 335..365: return ({12,yd-334,31,335+year_leap_year(y)}); +  case 60..90: return ({3,yd-59,31 ,60+l}); +  case 91..120: return ({4,yd-90,30 ,91+l}); +  case 121..151: return ({5,yd-120,31 ,121+l}); +  case 152..181: return ({6,yd-151,30 ,152+l}); +  case 182..212: return ({7,yd-181,31 ,182+l}); +  case 213..243: return ({8,yd-212,31 ,213+l}); +  case 244..273: return ({9,yd-243,30 ,244+l}); +  case 274..304: return ({10,yd-273,31,274+l}); +  case 305..334: return ({11,yd-304,30,305+l}); +  case 335..365: return ({12,yd-334,31,335+l});    } -  +  }    error("yday out of range.\n");   }   
199:    case 11:    break;    case 10: /* from leap to non-leap */ -  if (yd==55 && !force) return 0; // not this year +  if (yd==55) { +  if (!force) return 0; // not this year +  break; +  }    yd--;    break;    case 01: /* from non-leap to leap */
209:    return Day("ymd_yd",rules,y,yjd,yjd+yd-1,yd,what->n);    }    -  return ::place(what); +  return ::place(what, force);    }   }   
248:    {    int l1=year_leap_year(what->y);    int l2=year_leap_year(y); -  if (l1||l2) +  if (l1 != l2)    { -  if (l1 && wmd==24) -  if (l2) wmd=24; -  else { if (!force) return 0; } +  if (l1) { +  if (wmd>24) wmd--; +  else if (wmd==24) { +  if (!force) return 0; +  } +  }    else    { -  if (l1 && wmd>24) wmd--; -  if (l2 && wmd>24) wmd++; +  if (wmd>24) wmd++;    }    }    }
264:    return Day("ymd_yd",rules,y,yjd,jd+wmd-1,yd+wmd-1,what->n);    }    -  return ::place(what); +  return ::place(what, force);    }   }