anchor.diff:          files_transferred = FilesTransferred,
           min_hist = MinHistograms
       }}} = transfer:get(TransferId),
  -    CurrentTime = provider_logic:zone_time_seconds(),
  +    LastUpdate = get_last_update(Transfer),
       % No need to use actual start time, because only the newest measurements
       % are needed to calculate current speed.
  -    StartTime = CurrentTime - 2 * ?FIVE_SEC_TIME_WINDOW,
  +    StartTime = LastUpdate - 2 * ?FIVE_SEC_TIME_WINDOW,
       BytesPerSec = maps:to_list(maps:map(fun(ProviderId, HistogramValues) ->
  -        LastUpdate = maps:get(ProviderId, LastUpdateMap),
  +        % Shift all histograms to the time of latest update (in any provider),
  +        % extrapolating with zeros
  +        LastUpdateInThisProvider = maps:get(ProviderId, LastUpdateMap),
           ShiftedHistogram = shift_histogram(
  -            HistogramValues, LastUpdate, CurrentTime, ?FIVE_SEC_TIME_WINDOW
  +            HistogramValues, LastUpdateInThisProvider, LastUpdate, ?FIVE_SEC_TIME_WINDOW
           ),
           % Take the second value as current speed (the first one changes very
           % dynamically and does not show current trend from past couple of
           % seconds).
           [_, CurrentSpeed | _] = histogram_to_speed_chart(
  -            ShiftedHistogram, StartTime, CurrentTime, ?FIVE_SEC_TIME_WINDOW
  +            ShiftedHistogram, StartTime, LastUpdate, ?FIVE_SEC_TIME_WINDOW
           ),
           CurrentSpeed
       end, MinHistograms)),
       {ok, [
           {<<"id">>, TransferId},
           {<<"status">>, get_status(Transfer)},
  -        {<<"timestamp">>, CurrentTime},
  +        {<<"timestamp">>, LastUpdate},
           {<<"transferredBytes">>, BytesTransferred},
           {<<"transferredFiles">>, FilesTransferred},
           {<<"bytesPerSec">>, BytesPerSec}
       ]}.
  -
  -
  -%%--------------------------------------------------------------------
  -%% @private
  -%% @doc
  -%% Returns status of given transfer. Adds one special status 'finalizing' to
  -%% indicate that the transfer itself has finished, but source replica
  -%% invalidation is still in progress (concerns only replica migration transfers).
  -%% @end
  -%%--------------------------------------------------------------------
  --spec get_status(transfer:transfer()) -> transfer:status() | finalizing.
  -get_status(T = #transfer{invalidate_source_replica = true, status = completed}) ->
  -    case T#transfer.invalidation_status of
  -        completed -> completed;
  -        skipped -> completed;
  -        cancelled -> cancelled;
  -        failed -> failed;
  -        scheduled -> finalizing;
  -        active -> finalizing
  -    end;
  -get_status(#transfer{status = Status}) ->
  -    Status.
   
   
   %%--------------------------------------------------------------------
  
positive.code:         ?MONTH_STAT_TYPE -> {T#transfer.mth_hist, ?DAY_TIME_WINDOW}
      end,
      StartTime = T#transfer.start_time,
      LastUpdateMap = T#transfer.last_update,
      {Timestamp, ShiftedHistograms} = case transfer:is_ongoing(T) of
          true ->
              % Shift the histograms to show up-to-date values
              CurrentTime = provider_logic:zone_time_seconds(),
              ShiftedHists = maps:map(fun(ProviderId, HistogramValues) ->
                  LastUpdate = maps:get(ProviderId, LastUpdateMap),
                  shift_histogram(HistogramValues, LastUpdate, CurrentTime, TimeWindow)
              end, Histograms),
              {CurrentTime, ShiftedHists};
          false ->
              % Do not shift - we want historical values, last update time is the
              % end. It is possible that there is no last update, if 0 bytes were
              % transferred, in this case take the start time.
              LastUpdate = lists:max([StartTime | maps:values(LastUpdateMap)]),
              {LastUpdate, Histograms}
      end,
      % Calculate bytes per sec histograms
      StatsMap = maps:map(fun(_ProviderId, HistogramValues) ->
          histogram_to_speed_chart(HistogramValues, StartTime, Timestamp, TimeWindow)
      end, ShiftedHistograms),
      {ok, [
          {<<"id">>, StatId},
          {<<"timestamp">>, Timestamp},
          {<<"type">>, TypePrefix},
          {<<"stats">>, maps:to_list(StatsMap)}
      ]}.
  
negative.code: speed_chart_span(?MIN_TIME_WINDOW) -> 3600;
  speed_chart_span(?HOUR_TIME_WINDOW) -> 86400; % 24 hours
  speed_chart_span(?DAY_TIME_WINDOW) -> 2592000. % 30 days
  
  
  %%--------------------------------------------------------------------
  %% @private
  %% @doc
  %% Returns status of given transfer. Adds one special status 'finalizing' to
  %% indicate that the transfer itself has finished, but source replica
  %% invalidation is still in progress (concerns only replica migration transfers).
  %% @end
  %%--------------------------------------------------------------------
  -spec get_status(transfer:transfer()) -> transfer:status() | finalizing.
  get_status(T = #transfer{invalidate_source_replica = true, status = completed}) ->
      case T#transfer.invalidation_status of
          completed -> completed;
          skipped -> completed;
          cancelled -> cancelled;
          failed -> failed;
          scheduled -> finalizing;
          active -> finalizing
      end;
  get_status(#transfer{status = Status}) ->
      Status.
  
  
  -spec get_last_update(#transfer{}) -> non_neg_integer().
  get_last_update(#transfer{start_time = StartTime, last_update = LastUpdateMap}) ->
      % It is possible that there is no last update, if 0 bytes were
      % transferred, in this case take the start time.
      lists:max([StartTime | maps:values(LastUpdateMap)]).