pike.git / lib / modules / Calendar.pmod / Gregorian.pmod

version» Context lines:

pike.git/lib/modules/Calendar.pmod/Gregorian.pmod:52:   //!   //! method array(string) lesser()   //! Gives a list of methods to get lesser (shorter) time units.   //! ie, for a month, this gives back <tt>({"day"})</tt>   //! and the method <tt>day(mixed n)</tt> gives back that   //! day object. The method <tt>days()</tt> gives back a   //! list of possible argument values to the method <tt>day</tt>.   //! Concurrently, <tt>Array.map(o->days(),o->day)</tt> gives   //! a list of day objects in the object <tt>o</tt>.   //! + //! + //! Ie:<pre> + //! array(string) lesser() - gives back a list of possible xxx's. + //! object xxxs() - gives back a list of possible n's. + //! object xxx(mixed n) - gives back xxx n + //! object xxx(object(Xxx) o) - gives back the corresponing xxx + //! </pre> + //! + //! The list of n's (as returned from xxxs) are always in order. + //! + //! There are two n's with special meaning, 0 and -1. + //! 0 always gives the first xxx, equal to + //! my_obj->xxx(my_obj->xxxs()[0]), and -1 gives the last, + //! equal to my_obj->xxx(my_obj->xxxs()[-1]). + //! + //! To get all xxxs in the object, do something like + //! <tt>Array.map(my_obj->xxxs(),my_obj->xxx)</tt>. + //! + //! xxx(object) may return zero, if there was no correspondning xxx. + //!   //! method array(string) greater()   //! Gives a list of methods to get greater (longer) time units   //! from this object. For a month, this gives back <tt>({"year"})</tt>,   //! thus the method <tt>month->year()</tt> gives the year object.   //!   //! method object next()   //! method object prev()   //! method object `+(int n)   //! method object `-(int n)   //! method object `-(object x)
pike.git/lib/modules/Calendar.pmod/Gregorian.pmod:196:    return 1721426 + d - a + (a/4) + (36525*(y-1))/100;    }       int leap()    {    if (!(y%400)) return 1;    if (!(y%100)) return 0;    return !(y%4);    }    +  int leap_day() +  { +  return 31+24-1; // 24 Feb +  } +     int number_of_weeks()    {    int j=julian_day(0)%7;       // years that starts on a thursday has 53 weeks    if (j==3) return 53;    // leap years that starts on a wednesday has 53 weeks    if (j==2 && this->leap()) return 53;    // other years has 52 weeks    return 52;
pike.git/lib/modules/Calendar.pmod/Gregorian.pmod:237:    {    case "int": return this->number();    case "string": return this->name();    default:    throw(({"can't cast to "+what+"\n",backtrace()}));    }    }      //-- less -----------------------------------------------------------    -  object month(string|int n) +  object month(object|string|int n)    { -  +  if (objectp(n)) +  if (object_program(n)==vMonth) +  n=n->number(); +     if (stringp(n))    { -  if (!week_day_mapping) +  if (!month_mapping) +  {    month_mapping=    mkmapping(Array.map(month_names,lower_case),    indices(allocate(13))[1..]); -  n=month_mapping[n]; +  werror(sprintf("%O\n",month_mapping));    } -  +  n=month_mapping[lower_case(n)]; +  if (!n) return 0; +  }       if (n<0)    return vMonth(y,13+n);    else    return vMonth(y,n||1);    }       array(mixed) months()    {    return ({1,2,3,4,5,6,7,8,9,10,11,12});    }    -  object week(int n) +  object week(object|int n)    { -  +  if (objectp(n)) +  if (object_program(n)==vWeek) +  { +  n=n->number(); +  if (n>number_of_weeks()) return 0; /* no such week */ +  } +     if (n<0)    return vWeek(y,this->number_of_weeks()+n+1);    else    return vWeek(y,n||1);    }       array(mixed) weeks()    {    return indices(allocate(this->number_of_weeks()+1))[1..];    }    -  object day(int n) +  object day(object|int n)    { -  +  if (objectp(n)) +  if (object_program(n)==vDay) +  { +  object o=n->year(); +  n=n->year_day(); +  if (n==o->leap_day()) +  if (!this->leap()) return 0; +  else n=this->leap_day(); +  if (o->leap() && n>o->leap_day()) n--; +  if (this->leap() && n>=this->leap_day()) n++; +  if (n>=number_of_days()) return 0; /* no such day */ +  } +  else return 0; /* illegal object */ +     if (n<0)    return vDay(y,this->number_of_days()+n);    else    return vDay(y,n);    }       array(mixed) days()    {    return indices(allocate(this->number_of_days()));    }
pike.git/lib/modules/Calendar.pmod/Gregorian.pmod:427:    {    case "int": return this->number();    case "string": return this->name();    default:    throw(({"can't cast to "+what+"\n",backtrace()}));    }    }      //-- less -----------------------------------------------------------    -  object day(int n) +  object day(int|object n)    { -  +  if (objectp(n)) +  if (object_program(n)==vDay) +  { +  n=n->month_day(); +  if (n>number_of_days()) return 0; /* no such day */ +  } +     if (n<0)    return vDay(y,yday()+this->number_of_days()+n);    else    return vDay(y,yday()+(n||1)-1);    }       array(mixed) days()    {    return indices(allocate(this->number_of_days()+1))[1..];    }
pike.git/lib/modules/Calendar.pmod/Gregorian.pmod:594:    {    case "int": return this->number();    case "string": return this->name();    default:    throw(({"can't cast to "+what+"\n",backtrace()}));    }    }      //-- less -----------------------------------------------------------    -  object day(int|string n) +  object day(int|string|object n)    {    if (stringp(n))    {    if (!week_day_mapping)    week_day_mapping=    mkmapping(Array.map(week_day_names,lower_case),    indices(allocate(8))[1..]);    n=week_day_mapping[n];    } -  +  else if (objectp(n)) +  if (object_program(n)==vDay) +  n=n->week_day(); +  else return 0;       if (n<0) n=8+n;    else if (!n) n=1;    n+=yday()-1;    if (n<0) return vYear(y-1)->day(n);    if (n>=this->year()->number_of_days())    return vYear(y+1)->day(n-this->year()->number_of_days());    return vDay(y,n);    }