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

version» Context lines:

pike.git/lib/modules/Calendar.pmod/TimeRanges.pmod:1:   //! module Calendar    - // $Id: TimeRanges.pmod,v 1.29 2006/01/11 19:15:09 mbaehr Exp $ + // $Id: TimeRanges.pmod,v 1.30 2006/01/11 19:22:30 mbaehr Exp $      #pike __REAL_VERSION__      #define zero int(0..0)      program SuperTimeRange=cSuperTimeRange;      string calendar_name() { return "TimeRanges"; }      object calendar_object=this;
pike.git/lib/modules/Calendar.pmod/TimeRanges.pmod:295:    {    return this-1;    }      //! method TimeRange `*(int n)   //! This changes the amount of time in   //! the time period. <tt>t*17</tt> is   //! the same as doing <tt>t-><ref>set_size</ref>(t,17)</tt>.       function ``* = `*; -  TimeRange `*(int n) +  TimeRange `*(int|float n)    { -  return set_size(n,this); +  return set_size((int)n,this);    }    - //! method array(TimeRange) `/(int n) - //! method array(TimeRange) split(int n) + //! method array(TimeRange) `/(int|float n) + //! method array(TimeRange) split(int|float n, void|TimeRange with)   //! This divides the called timerange into   //! n pieces. The returned timerange type   //! is not neccesarily of the same type as the called one. -  + //! If the optional timerange is specified then the resulting timeranges + //! will be multiples of that range (except for the last one).   //!   //! known bugs:   //! These are currently not defined for   //! <ref to=SuperTimeRange>supertimeranges</ref>.      //! method int `/(TimeRange with)   //! method int how_many(TimeRange with)   //! This calculates how many instances of the given   //! timerange has passed during the called timerange.   //!   //! For instance, to figure out your age,   //! create the timerange of your lifespan, and divide   //! with the instance of a <ref to=YMD.Year>Year</ref>.      // virtual -  array(TimeRange) split(int n); +  array(TimeRange) split(int|float n, void|function|TimeRange with);       int how_many(function|TimeRange with)    {    if (functionp(with)) with=promote_program(with);   // default method; not optimized - guessing       TimeRange start=beginning();    TimeRange end=end();      // find low and high 2^n
pike.git/lib/modules/Calendar.pmod/TimeRanges.pmod:385:       t=start+with*nn;    if (t==end) return nn;    if (t<end) low=nn+1;    else high=nn-1;       if (low>high) return high; // can't go further    }    }    -  array(TimeRange)|int `/(TimeRange|program|int x) +  array(TimeRange)|int `/(TimeRange|program|int|float x)    { -  if (intp(x)) return split(x); +  if (intp(x) || floatp(x)) return split(x);    else return how_many(x);    }      //! method int offset_to(TimeRange x)   //! Calculates offset to x; this compares   //! two timeranges and gives the integer offset   //! between the two starting points.   //!   //! This is true for suitable a and b:   //! <tt>a+a->offset_to(b)==b</tt>