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

version» Context lines:

pike.git/lib/modules/Calendar.pmod/TimeRanges.pmod:252:   //! </pre>   //!   //! note:   //! a-b does not give the distance between the start of a and b.   //! Use the <ref>distance</ref>() function to calculate that.   //!   //! The integer used to `+, `- and add are the <i>number</i>   //! of steps the motion will be. It does <i>never</i> represent   //! any <i>fixed</i> amount of time, like seconds or days.    -  TimeRange `+(program|this_program|int n, +  protected TimeRange `+(program|this_program|int n,    program|this_program|int ... more)    {    TimeRange res;    if (objectp(n)) res = add(1,n);    else res = add(n);    if (sizeof(more))    return predef::`+(res, @more);    return res;    }    -  TimeRange ``+(int n, int ... more) +  protected TimeRange ``+(int n, int ... more)    {    if (sizeof(more)) n = predef::`+(n, @more);    return add(n);    }    -  TimeRange `-(program|this_program|int n, +  protected TimeRange `-(program|this_program|int n,    TimeRange|this_program|int ... more)    {    if (sizeof(more)) n = predef::`+(n, @more);    if (objectp(n)) return add(-1,n);    return add(-n);    }      //! method TimeRange next()   //! method TimeRange prev()   //! Next and prev are compatible and convinience functions;
pike.git/lib/modules/Calendar.pmod/TimeRanges.pmod:298:    TimeRange prev()    {    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>.    -  TimeRange ``* (int n) {return `* (n);} -  TimeRange `*(int|float n) +  protected TimeRange ``* (int n) {return `* (n);} +  protected TimeRange `*(int|float n)    {    return set_size((int)n,this);    }      //! 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 necessarily of the same type as the called one.   //! If the optional timerange is specified then the resulting timeranges
pike.git/lib/modules/Calendar.pmod/TimeRanges.pmod:391:       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|float x) +  protected array(TimeRange)|int `/(TimeRange|program|int|float 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.   //!
pike.git/lib/modules/Calendar.pmod/TimeRanges.pmod:637:    return !a[END_END];    }      //! method int(0..1) `<(TimeRange compared_to)   //! method int(0..1) `>(TimeRange compared_to)   //! These operators sorts roughty on the   //! periods place in time. The major use   //! might be to get multiset to work,   //! besides sorting events clearly defined in time.    -  int(0..1) `<(TimeRange compared_to) +  protected int(0..1) `<(TimeRange compared_to)    {    array(int(-1..1)) a=_compare(compared_to);    if (a[0]<0) return 1;    if (a[0]>0) return 0;    if (a[3]<0) return 1;    return 0;    }    -  int(0..1) `>(TimeRange compared_to) +  protected int(0..1) `>(TimeRange compared_to)    {    array(int(-1..1)) a=_compare(compared_to);    if (a[0]>0) return 1;    if (a[0]<0) return 0;    if (a[3]>0) return 1;    return 0;    }      //! method int(0..1) `==(TimeRange compared_to)   //! method int(0..1) _equal(TimeRange compared_to)
pike.git/lib/modules/Calendar.pmod/TimeRanges.pmod:675:   //! true if a and b are the same timerange, exactly the same   //! as the <ref>equals</ref> method.   //!   //! The <tt>__hash</tt> method is also present,   //! to make timeranges possible to use as keys in mappings.   //!   //! known bugs:   //! _equal is not currently possible to overload,   //! due to weird bugs, so equal uses `== for now.    -  int(0..1) `==(mixed what) +  protected int(0..1) `==(mixed what)    {    return objectp(what) && functionp(what->ruleset) &&    what->ruleset()==ruleset() && equals(what);    }       protected int __hash();      // int(0..1) _equal(TimeRange what)   // {   // return equals(what);
pike.git/lib/modules/Calendar.pmod/TimeRanges.pmod:699:   //! Gives the cut on the called time period   //! with another time period. The result is   //! zero if the two periods doesn't overlap.   //! <pre>   //! &gt;- the past the future -&lt;   //! |-------called-------|   //! |-------other--------|   //! &gt;----- cut -----&lt;   //! </pre>    -  TimeRange|zero ``& (TimeRange with, mixed... extra) +  protected TimeRange|zero ``& (TimeRange with, mixed... extra)    {return `& (with, @extra);} -  TimeRange|zero `&(TimeRange with, mixed ...extra) +  protected TimeRange|zero `&(TimeRange with, mixed ...extra)    {    if (with->is_nulltimerange)    return with;    array(int(-1..1)) a=_compare(with);    if (a[END_BEGIN]<0 || a[BEGIN_END]>0)    return nulltimerange; // no overlap, no extra       if (with->is_supertimerange)    return predef::`&(with,this,@extra); // let it handle that...   
pike.git/lib/modules/Calendar.pmod/TimeRanges.pmod:736:   //! method TimeRange `|(TimeRange with)   //! Gives the union on the called time period   //! and another time period.   //! <pre>   //! &gt;- the past the future -&lt;   //! |-------called-------|   //! |-------other--------|   //! &lt;----------union----------&gt;   //! </pre>    -  TimeRange ``| (TimeRange with, mixed... extra) {return `| (with, @extra);} -  TimeRange `|(TimeRange with,mixed ...extra) +  protected TimeRange ``| (TimeRange with, mixed... extra) {return `| (with, @extra);} +  protected TimeRange `|(TimeRange with,mixed ...extra)    {    if (with->is_nulltimerange)    return sizeof(extra)?`|(@extra):this;    array(int(-1..1)) a=_compare(with);    TimeRange from,to;       if (a[END_BEGIN]<0 || a[BEGIN_END]>0)    from=SuperTimeRange( sort(({this,with})) ); // no overlap    else    {
pike.git/lib/modules/Calendar.pmod/TimeRanges.pmod:775:   //! and another time period, ie the union without   //! the cut. The result is zero if the   //! two periods were the same.   //! <pre>   //! &gt;- the past the future -&lt;   //! |-------called-------|   //! |-------other--------|   //! &lt;----| |----> - exclusive or   //! </pre>    -  TimeRange ``^ (TimeRange with, mixed... extra) {return `^ (with, @extra);} -  TimeRange `^(TimeRange with,mixed ... extra) +  protected TimeRange ``^ (TimeRange with, mixed... extra) {return `^ (with, @extra);} +  protected TimeRange `^(TimeRange with,mixed ... extra)    {    if (with->is_supertimerange)    return `^(with,this,@extra); // let it handle that...    if (with->is_nulltimerange)    return sizeof(extra)?`^(@extra):this;       TimeRange res;       array(int(-1..1)) a=_compare(with);   
pike.git/lib/modules/Calendar.pmod/TimeRanges.pmod:1021:    res+=({last});    last=part;    }    else    last=last|part;    }    if (!sizeof(res)) return last;    return SuperTimeRange(res+({last}));    }    -  TimeRange `&(TimeRange with,mixed... extra) +  protected TimeRange `&(TimeRange with,mixed... extra)    {    array r=({});    foreach (parts,TimeRange part)    {    TimeRange tmp=predef::`&(part,with,@extra);    if (tmp)    if (tmp->is_supertimerange) r+=tmp->parts;    else if (!tmp->is_nulltimerange) r+=({tmp});    }    switch (sizeof(r))    {    case 0: return nulltimerange;    case 1: return r[0];    default: return SuperTimeRange(r);    }    }    -  TimeRange `|(TimeRange with,mixed ...extra) +  protected TimeRange `|(TimeRange with,mixed ...extra)    {    TimeRange res;    if (with->is_supertimerange)    res=mend_overlap(sort(with->parts+parts));    else if (with->is_nulltimerange)    return this;    else    res=mend_overlap(sort( ({with})+parts ));    if (sizeof(extra))    return predef::`|(res,@extra);
pike.git/lib/modules/Calendar.pmod/TimeRanges.pmod:1061:    }       TimeRange subtract(TimeRange with,mixed ...extra)    {    array r=({});    foreach (parts,TimeRange part)    r+=({part->subtract(part,with,@extra)});    return predef::`|(@r);    }    -  TimeRange `^(TimeRange with,mixed ...extra) +  protected TimeRange `^(TimeRange with,mixed ...extra)    {   // werror("1 %O\n",with);   // werror("2 %O\n",`|(with));   // werror("3 %O\n",`&(with));    TimeRange r=`|(with)->subtract(`&(with));    if (sizeof(extra)) return predef::`^(r,@extra);    return r;    }      // == checks if equal    -  int `==(TimeRange with,mixed ...extra) +  protected int `==(TimeRange with,mixed ...extra)    {    if (!with->is_supertimerange)    return 0; // it has to be    if (sizeof(parts)!=sizeof(with->parts))    return 0; // it has to be    for (int i=0; i<sizeof(parts); i++)    if (parts[i]!=with->parts[i]) return 0;    return sizeof(extra)?predef::`==(with,@extra):1;    }   
pike.git/lib/modules/Calendar.pmod/TimeRanges.pmod:1096:    {    array(int(-1..1)) a,b;    a=parts[0]->_compare(what);    b=parts[-1]->_compare(what);    return ({a[0],a[1],b[2],b[3]});    }      // `< and `> sort for multiset   // a little bit heavier for super-time-ranges    -  int(0..1) `<(TimeRange with) +  protected int(0..1) `<(TimeRange with)    {    array(int(-1..1)) a=_compare(with);    if (a[0]<0) return 1;    if (a[0]>0) return 0;    if (a[3]<0) return 1;    if (a[3]>0) return 0;    if (!with->is_supertimerange) return 1; // always    if (sizeof(parts)>sizeof(with->parts)) return 1;    if (sizeof(parts)<sizeof(with->parts)) return 0;    for (int i=0; i<sizeof(parts); i++)    if (parts[i]<with->parts[i]) return 1;    return 0;    }    -  int(0..1) `>(TimeRange with) +  protected int(0..1) `>(TimeRange with)    {    array(int(-1..1)) a=_compare(with);    if (a[0]>0) return 1;    if (a[0]<0) return 0;    if (a[3]>0) return 1;    if (a[3]<0) return 0;    if (!with->is_supertimerange) return 0; // always    if (sizeof(parts)<sizeof(with->parts)) return 1;    if (sizeof(parts)>sizeof(with->parts)) return 0;    for (int i=0; i<sizeof(parts); i++)
pike.git/lib/modules/Calendar.pmod/TimeRanges.pmod:1207:    if (to==this) return this;    error("Can't distance/space/range with the null timerange\n");    }       array(int(-1..1)) _compare(TimeRange with)    {    if (with==this) return ({0,0,0,0});    return ({-1,-1,-1,-1});    }    -  int(0..1) `<(TimeRange with) +  protected int(0..1) `<(TimeRange with)    {    return !(with==this);    }    -  int(0..1) `>(TimeRange with) +  protected int(0..1) `>(TimeRange with)    {    return 0;    }    -  int(0..1) `==(TimeRange with) +  protected int(0..1) `==(TimeRange with)    {    return objectp(with) && with->is_nulltimerange;    }       int(0..1) equals(TimeRange with)    {    return objectp(with) && with->is_nulltimerange;    }    -  TimeRange `&(TimeRange with, mixed ...extra) +  protected TimeRange `&(TimeRange with, mixed ...extra)    {    return predef::`&(with,this,@extra);    }    -  TimeRange `|(TimeRange with, mixed ...extra) +  protected TimeRange `|(TimeRange with, mixed ...extra)    {    return predef::`|(with,this,@extra);    }    -  TimeRange `^(TimeRange with, mixed ...extra) +  protected TimeRange `^(TimeRange with, mixed ...extra)    {    return predef::`^(with,this,@extra);    }       this_program subtract(TimeRange with, mixed ...extra)    {    return this;    }    -  int(1..1) `!() +  protected int(1..1) `!()    {    return 1;    }       protected int __hash()    {    return 0;    }       protected string _sprintf(int t)