Branch: Tag:

2006-01-11

2006-01-11 19:22:31 by Martin Bähr <mbaehr@email.archlab.tuwien.ac.at>

extend * and / to handle floats
implement split, extend it to handle float as well as an optional type for the
granularity of the split

Rev: lib/modules/Calendar.pmod/Time.pmod:1.35
Rev: lib/modules/Calendar.pmod/TimeRanges.pmod:1.30
Rev: lib/modules/Calendar.pmod/YMD.pike:1.15

1016:    ->autopromote()});    }    +  TimeRange `*(int|float n) +  { +  if(intp(n)) +  return set_size(n,this); +  else +  return second()*(int)(how_many(Second)*n); +  } +  +  array(TimeRange) split(int|float n, void|function|TimeRange with) +  { +  if(!with) +  with=Second(); +  else if (functionp(with)) +  with=promote_program(with); +  +  int length=(int)(how_many(with)/n); +  +  TimeRange start=beginning(); +  TimeRange end=end(); +  array result=({}); +  while(start+with*length < end) +  { +  result += ({ start->distance(start+with*length) }); +  start=start+with*length; +  } +  result += ({ start->distance(end) }); +  return result; +  } +    // ----------------------------------------   // virtual functions needed   // ----------------------------------------