anchor.diff:          ?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,
  +    LastUpdate = get_last_update(T),
       % Calculate bytes per sec histograms
       StatsMap = maps:map(fun(_ProviderId, HistogramValues) ->
  -        histogram_to_speed_chart(HistogramValues, StartTime, Timestamp, TimeWindow)
  -    end, ShiftedHistograms),
  +        histogram_to_speed_chart(HistogramValues, StartTime, LastUpdate, TimeWindow)
  +    end, Histograms),
       {ok, [
           {<<"id">>, StatId},
  -        {<<"timestamp">>, Timestamp},
  +        {<<"timestamp">>, LastUpdate},
           {<<"type">>, TypePrefix},
           {<<"stats">>, maps:to_list(StatsMap)}
       ]}.
  
positive.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
  
negative.code:         files_transferred = FilesTransferred,
          min_hist = MinHistograms
      }}} = transfer:get(TransferId),
      LastUpdate = get_last_update(Transfer),
      % No need to use actual start time, because only the newest measurements
      % are needed to calculate current speed.
      StartTime = LastUpdate - 2 * ?FIVE_SEC_TIME_WINDOW,
      BytesPerSec = maps:to_list(maps:map(fun(ProviderId, HistogramValues) ->
          % Shift all histograms to the time of latest update (in any provider),
          % extrapolating with zeros
          LastUpdateInThisProvider = maps:get(ProviderId, LastUpdateMap),
          ShiftedHistogram = shift_histogram(
              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, LastUpdate, ?FIVE_SEC_TIME_WINDOW
          ),
          CurrentSpeed
      end, MinHistograms)),
      {ok, [
          {<<"id">>, TransferId},
          {<<"status">>, get_status(Transfer)},
          {<<"timestamp">>, LastUpdate},
          {<<"transferredBytes">>, BytesTransferred},
          {<<"transferredFiles">>, FilesTransferred},
          {<<"bytesPerSec">>, BytesPerSec}
      ]}.
  
  
  %%--------------------------------------------------------------------
  