title: System.Reactive: Buffer(timeSpan, timeShift) by Timestamp field
body: <p>As said in <a href="https://stackoverflow.com/questions/67268654/reactive-time-based-buffer-by-timestamp-field">this previous question</a>, I am using the Reactive library in a C# project to group incoming data according to pre-configured policies. All these data implement the following interface:</p>
  <pre class="lang-cs prettyprint-override"><code>public interface IPoint
  {
      object Value { get; }
      DateTimeOffset Timestamp { get; }
  }
  </code></pre>
  <p>My goal is to implement a &quot;hopping&quot; buffer based on the <code>Timestamp</code>s of the received data (both buffer size and hop/shift size are declared at the beginning as <code>TimeSpan</code>s). Hop/shift size can be less than the buffer size, which means that some <code>IPoint</code> instances can belong to more than one group.</p>
  <p>An example: considering the following <code>IPoint</code></p>
  <pre><code>Value: 1, Timestamp: &quot;2021-05-25T00:00:01&quot;
  Value: 2, Timestamp: &quot;2021-05-25T00:00:02&quot;
  Value: 3, Timestamp: &quot;2021-05-25T00:00:03&quot;
  Value: 4, Timestamp: &quot;2021-05-25T00:00:04&quot;
  Value: 5, Timestamp: &quot;2021-05-25T00:00:05&quot;
  </code></pre>
  <ul>
  <li>with a buffer size of 3 seconds and a hop/shift size of 2 seconds, I am expecting them to be grouped as <code>[1, 2, 3], [3, 4, 5]</code>.</li>
  <li>with a buffer size of 2 seconds and a hop/shift size of 3 seconds, I am expecting them to be grouped as <code>[1, 2], [4, 5]</code></li>
  </ul>
  <p>I've seen that there is a <code>Buffer(timeSpan, timeShift)</code> extension doing this job, but it considers a runtime-calculated timestamp instead of the ones of the passed <code>IPoint</code>s.</p>
  <p>I've tried to look for a solution, but I couldn't find anything helpful.</p>
  <p>I am a newbie at Reactive, so any helpful comment is welcome (also for the other question). Thank you.</p>
  <p><strong>Edit</strong>: as in the previous question, I am using an <code>ISubject&lt;IPoint&gt;</code> in this way:</p>
  <pre class="lang-cs prettyprint-override"><code>ISubject&lt;IPoint&gt; subject = new Subject&lt;IPoint&gt;();
  // ...
  // when new data come from an external source
  public void Add(IPoint newPoint)
  {
      subject.OnNext(newPoint);
  }
  
  // subscription made by another class in order to be called when &quot;hopping&quot; buffer is ready
  public void Subscribe(Action&lt;IEnumerable&lt;IPoint&gt;&gt; callback)
  {
      // TODO: implement buffer + .Subscribe(callback)
  }
  </code></pre>