プロジェクト

全般

プロフィール

Vote #81890

未完了

Wrong formatting of date in Time Entries

Admin Redmine さんがほぼ2年前に追加. ほぼ2年前に更新.

ステータス:
New
優先度:
通常
担当者:
-
カテゴリ:
Time tracking_13
開始日:
2022/05/09
期日:
進捗率:

0%

予定工数:
category_id:
13
version_id:
33
issue_org_id:
36897
author_id:
582905
assigned_to_id:
0
comments:
7
status_id:
1
tracker_id:
3
plus1:
0
affected_version:
closed_on:
affected_version_id:
ステータス-->[New]

説明

Date is formatted wrong at " – Time entries" ("7:60" instead of "8:00", for example). See screenshot.

This patch fixes it.


journals

I've encountered this in 4.0.6, but AFAIK this bugged part of code still not fixed in 5.0.0.
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
This whole thing can probably be simplified to just

<pre><code class="ruby">
def format_hours(hours)
return "" if hours.blank?

if Setting.timespan_format == 'minutes'
"%d:%02d" % (hours * 60).divmod(60)
else
l_number("%.2f", hours.to_f)
end
end
</code></pre>
--------------------------------------------------------------------------------
Probably yes.

But as far as I understood from how hours are displayed in Time entries, they need to be `.round`-ed (not just dropping the fractional part).
I.e. if you've spent 7:59:30 (7.991666666666667 hrs), for human it's 8:00 (we don't count seconds in Time entries). :)
Patch gives "8:00" too.

I think like this.

--------------------------------------------------------------------------------
Hmmm, with my version, trailing "seconds" indeed would just be cut off instead of being rounded. Thus, semantically @7:59:01@ and @7:59:59@ would both be shown as @"7:59"@ which is different from the current behavior.

If we round the minutes, we would again have to deal with the case of @7.99@ hours being rounded up to @"7:60"@ however.

Maybe this version could work then:

<pre><code class="ruby">
h, m = (hours * 60).divmod(60).map!(&:round)
if m == 60
h += 1
m = 0
end
"%d:%02d" % [h, m]
</code></pre>

The @if@ block could also be shortened to the equivalent one-liner:

<pre><code class="ruby">
h, m = h+1, 0 if m == 60
</code></pre>

In any case, we can be sure that after the first line, @m@ is an Integer between 0 and 60 (inclusive). If it was rounded up to @60@, we set to to @0@ and increase the hour by one in the @if@ block.

This should then be equivalent to the proposed version in the original patch, but with a little less math involved and a little bit more straight-forward.

At Planio, we run this code for some time now which is a mixture of both approaches:

<pre><code class="ruby">
h = hours.floor
m = ((hours - h) * 60).round
if m == 60
h += 1
m = 0
end
"%d:%02d" % [h, m]
</code></pre>

Here, the first two lines (which are the same as in Redmine core) return the exact same result as @h, m = (hours * 60).divmod(60).map!(&:round)@.
--------------------------------------------------------------------------------
Holger Just wrote:
> At Planio, we run this code for some time now which is a mixture of both approaches:
>
> <pre><code class="ruby">
h = hours.floor
m = ((hours - h) * 60).round
if m == 60
h += 1
m = 0
end
"%d:%02d" % [h, m]
</code></pre>
>
> Here, the first two lines (which are the same as in Redmine core) return the exact same result as @h, m = (hours * 60).divmod(60).map!(&:round)@.

Yes, I think we can go _this_ way. :)
--------------------------------------------------------------------------------
So, the adjusted patch.
--------------------------------------------------------------------------------


related_issues

relates,Closed,23996,Introduce a setting to change the display format of timespans to HH:MM

Admin Redmine さんがほぼ2年前に更新

  • カテゴリTime tracking_13 にセット
  • 対象バージョンCandidate for next minor release_33 にセット

他の形式にエクスポート: Atom PDF

いいね!0
いいね!0