Defect #31637

CSV and PDF export don't respect Time span format

Added by Teko Teleko over 1 year ago. Updated 9 days ago.

Status:ConfirmedStart date:
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:Time tracking
Target version:4.2.0
Resolution: Affected version:3.4.2

Description

In Spent time section I have issues displaying the hours in standard time format, but when I export to CSV the hours are displayed in decimal format.

For example: I have a issue with 00:45h (standard), but in the CSV file I have 0.75 (decimal).

How can I export with standard time format?

I'm using the Bitnami Redmine Stack and this are my Redmine configurations:
Environment:
Redmine version 3.4.2.stable
Ruby version 2.3.4-p301 (2017-03-30) [x86_64-linux]
Rails version 4.2.8
Environment production
Database adapter Mysql2
SCM:
Subversion 1.9.7
Cvs 1.12.13
Filesystem
Redmine plugins:
redmine_checklists 3.1.15
redmine_custom_css 0.1.6

0001-Fix-csv-format-of-hours.patch Magnifier (2.38 KB) Seiei Miyagi, 2020-07-23 09:22

0001-Fix-timespan-format-of-PDF-download.patch Magnifier (2.82 KB) Seiei Miyagi, 2020-07-23 10:22

History

#1 Updated by Go MAEDA over 1 year ago

  • Category set to Time tracking

#3 Updated by Go MAEDA 5 months ago

I think the exported CSV file should follow the "time span format" as well. Probably users who want to see the time in "00:45" format on the screen want to see in the same format in the CSV file.

#4 Updated by Seiei Miyagi 4 months ago

PDF export has same bug

#5 Updated by Seiei Miyagi 4 months ago

  • File 0001-Fix-csv-format-of-hours.patch added

I wrote a patch with Kusukawa and Mattani

#6 Updated by Marius BALTEANU 4 months ago

Seiei Miyagi wrote:

I wrote a patch with Kusukawa and Mattani

Thanks for writing the patch. Can you add a new test or new assertions to existing tests?

#7 Updated by Seiei Miyagi 4 months ago

Marius BALTEANU wrote:

Seiei Miyagi wrote:

I wrote a patch with Kusukawa and Mattani

Thanks for writing the patch. Can you add a new test or new assertions to existing tests?

I added a test.

#8 Updated by Seiei Miyagi 4 months ago

  • File 0001-Fix-timespan-format-of-PDF-download.patch added

I also write a patch for PDF download timespan format.
Should I create a new ticket for that?

#9 Updated by Seiei Miyagi 4 months ago

Seiei Miyagi wrote:

I also write a patch for PDF download timespan format.
Should I create a new ticket for that?

I updated the patch, added a test for IssuesPdfHelper too.

#10 Updated by Go MAEDA 4 months ago

  • Subject changed from Problem with time format on CSV export to CSV and PDF export of Problem with time format on CSV export

Thank you for posting the patches but issues_pdf_test.rb fails.

Error:
IssuesPdfHelperTest#test_fetch_row_values_should_round_float_values:
NoMethodError: undefined method `format_hours' for #<IssuesPdfHelperTest:0x00007fcaf3326b60>
    lib/redmine/export/pdf/issues_pdf_helper.rb:389:in `block in fetch_row_values'
    lib/redmine/export/pdf/issues_pdf_helper.rb:376:in `collect'
    lib/redmine/export/pdf/issues_pdf_helper.rb:376:in `fetch_row_values'
    test/unit/lib/redmine/export/pdf/issues_pdf_test.rb:36:in `test_fetch_row_values_should_round_float_values'

bin/rails test test/unit/lib/redmine/export/pdf/issues_pdf_test.rb:28

Maybe we have to add include Redmine::I18n as follows, don't we?

diff --git a/lib/redmine/export/pdf/issues_pdf_helper.rb b/lib/redmine/export/pdf/issues_pdf_helper.rb
index b49691695..8dcd52245 100644
--- a/lib/redmine/export/pdf/issues_pdf_helper.rb
+++ b/lib/redmine/export/pdf/issues_pdf_helper.rb
@@ -21,6 +21,8 @@ module Redmine
   module Export
     module PDF
       module IssuesPdfHelper
+        include Redmine::I18n
+
         # Returns a PDF string of a single issue
         def issue_to_pdf(issue, assoc={})
           pdf = ITCPDF.new(current_language)

#11 Updated by Go MAEDA 4 months ago

  • Subject changed from CSV and PDF export of Problem with time format on CSV export to CSV and PDF export don't respect Time span format

#12 Updated by Go MAEDA 4 months ago

  • File deleted (0001-Fix-csv-format-of-hours.patch)

#13 Updated by Go MAEDA 4 months ago

  • File deleted (0001-Fix-timespan-format-of-PDF-download.patch)

#14 Updated by Go MAEDA 4 months ago

  • Target version set to Candidate for next major release

Go MAEDA wrote:

Thank you for posting the patches but issues_pdf_test.rb fails.

[...]

Maybe we have to add include Redmine::I18n as follows, don't we?

[...]

Sorry, I applied the older patch. The latest patch has no problem. The patches work fine now.

#15 Updated by Go MAEDA 4 months ago

  • Target version changed from Candidate for next major release to 4.2.0

Setting the target version to 4.2.0.

#16 Updated by Go MAEDA 4 months ago

The patch 0001-Fix-csv-format-of-hours.patch breaks an existing test:

Failure:
IssuesControllerTest#test_index_csv_fr [/Users/maeda/redmines/redmine-trunk/test/functional/issues_controller_test.rb:1064]:
"24;1234,50;test_index_csv_fr" not found in "["#;Temps estim\xE9;Sujet", "24;1234.50;test_index_csv_fr"]" 

bin/rails test test/functional/issues_controller_test.rb:1048

#17 Updated by Go MAEDA 4 months ago

  • Target version changed from 4.2.0 to Candidate for next major release

Go MAEDA wrote:

The patch 0001-Fix-csv-format-of-hours.patch breaks an existing test:

[...]

It is because the suggested patch does not take general_csv_decimal_separator (source:branches/4.1-stable/config/locales/en.yml#L148) into account. After applying the patch, "." is always used as a decimal separator for time values ignoring general_csv_decimal_separator.

#18 Updated by Go MAEDA 2 months ago

  • Target version deleted (Candidate for next major release)

#19 Updated by Go MAEDA 2 months ago

  • Status changed from New to Confirmed

#20 Updated by Mizuki ISHIKAWA 27 days ago

Go MAEDA wrote:

Go MAEDA wrote:

The patch 0001-Fix-csv-format-of-hours.patch breaks an existing test:

[...]

It is because the suggested patch does not take general_csv_decimal_separator (source:branches/4.1-stable/config/locales/en.yml#L148) into account. After applying the patch, "." is always used as a decimal separator for time values ignoring general_csv_decimal_separator.

The following changes should fix it.

diff --git a/app/helpers/queries_helper.rb b/app/helpers/queries_helper.rb
index 6271334ae..54aec4f24 100644
--- a/app/helpers/queries_helper.rb
+++ b/app/helpers/queries_helper.rb
@@ -267,7 +267,7 @@ module QueriesHelper
     when :attachments
       value.to_a.map {|a| a.filename}.join("\n")
     when :hours, :estimated_hours, :total_estimated_hours, :spent_hours, :total_spent_hours
-      format_hours(value)
+      format_hours(value).gsub('.', l(:general_csv_decimal_separator))
     else
       format_object(value, false) do |value|
         case value.class.name

#21 Updated by Go MAEDA 15 days ago

  • Target version set to Candidate for next major release

#22 Updated by Go MAEDA 9 days ago

  • Target version changed from Candidate for next major release to 4.2.0

Setting the target version to 4.2.0.

Also available in: Atom PDF