Tracker Import from csv does not import date and time properly
- Status
- Open
- Subject
- Tracker Import from csv does not import date and time properly
- Version
- 3.x
4.x
5.x
6.x
7.x
8.x - Category
- Error
- Usability
- Feature
- Import-Export
Trackers - Submitted by
- Beestje
- Lastmod by
- Beestje
- Rating
- Description
Tested in version 3.3 and 7:
Importing tracker items through CSV does not properly process the date field.My exported CSV contains e.g. "24/12/2010 19:55"
The imported data only contains "24/12/2010" The time has been left out.incorrect code 3.3Copy to clipboard# Version 3.3 Line 1697 } elseif ($field['type'] == 'f' || $field['type'] == 'j') { if ($dateFormat == 'mm/dd/yyyy') { list($m, $d, $y) = split('/', $data[$i]); $data[$i] = $tikilib->make_time(0, 0, 0, $m, $d, $y); } elseif ($dateFormat == 'dd/mm/yyyy') { list($d, $m, $y) = split('/', $data[$i]); $data[$i] = $tikilib->make_time(0, 0, 0, $m, $d, $y); } }
Replaced by following code :correct code 3.3Copy to clipboardelseif ($field['type'] == 'f' || $field['type'] == 'j') { $l = strlen($data[$i]); switch ($l) { case ($l == 10): # Field does not contain the time if ($dateFormat == 'mm/dd/yyyy') { list($m, $d, $y) = explode('/', $data[$i]); $data[$i] = $tikilib->make_time(0, 0, 0, $m, $d, $y); } elseif ($dateFormat == 'dd/mm/yyyy') { list($d, $m, $y) = explode('/', $data[$i]); $data[$i] = $tikilib->make_time(0, 0, 0, $m, $d, $y); } break; case ($l == 16): # Field contains HH:MM list($fd, $ft) = explode(' ', $data[$i]); if ($dateFormat == 'mm/dd/yyyy') { list($m, $d, $y) = explode('/', $fd); list($hh, $mm) = explode(':', $ft); $data[$i] = $tikilib->make_time($hh, $mm, 0, $m, $d, $y); } elseif ($dateFormat == 'dd/mm/yyyy') { list($d, $m, $y) = explode('/', $fd); list($hh, $mm) = explode(':', $ft); $data[$i] = $tikilib->make_time($hh, $mm, 0, $m, $d, $y); } break; case ($l == 19): # Field contains HH:MM:SS list($fd, $ft) = explode(' ', $data[$i]); if ($dateFormat == 'mm/dd/yyyy') { list($m, $d, $y) = explode('/', $fd); list($hh, $mm) = explode(':', $ft); $data[$i] = $tikilib->make_time($hh, $mm, $ss, $m, $d, $y); } elseif ($dateFormat == 'dd/mm/yyyy') { list($d, $m, $y) = explode('/', $fd); list($hh, $mm) = explode(':', $ft); $data[$i] = $tikilib->make_time($hh, $mm, $ss, $m, $d, $y); } break; } }
The same for the latest version 8.3Incorrect code 8.3Copy to clipboardcase 'f': case 'j': if ($dateFormat == 'mm/dd/yyyy') { list($m, $d, $y) = preg_split('#/#', $data[$i]); $data[$i] = $tikilib->make_time(0, 0, 0, $m, $d, $y); } elseif ($dateFormat == 'dd/mm/yyyy') { list($d, $m, $y) = preg_split('#/#', $data[$i]); $data[$i] = $tikilib->make_time(0, 0, 0, $m, $d, $y); } elseif ($dateFormat == 'yyyy-mm-dd') { list($y, $m, $d) = preg_split('#-#', $data[$i]); $data[$i] = $tikilib->make_time(0, 0, 0, $m, $d, $y); } break; }
Correct code v8.3Copy to clipboard# Line 1730 case 'f': case 'j': $l = strlen($data[$i]); switch ($l) { case ($l == 10): # Field does not contain the time if ($dateFormat == 'mm/dd/yyyy') { list($m, $d, $y) = explode('/', $data[$i]); $data[$i] = $tikilib->make_time(0, 0, 0, $m, $d, $y); } elseif ($dateFormat == 'dd/mm/yyyy') { list($d, $m, $y) = explode('/', $data[$i]); $data[$i] = $tikilib->make_time(0, 0, 0, $m, $d, $y); } elseif ($dateFormat == 'yyyy-mm-dd') { list($y, $m, $d) = explode('-', $data[$i]); $data[$i] = $tikilib->make_time(0, 0, 0, $m, $d, $y); } break; case ($l == 16): # Field contains HH:MM list($fd, $ft) = explode(' ', $data[$i]); list($hh, $mm) = explode(':', $ft); if ($dateFormat == 'mm/dd/yyyy') { list($m, $d, $y) = explode('/', $fd); $data[$i] = $tikilib->make_time($hh, $mm, 0, $m, $d, $y); } elseif ($dateFormat == 'dd/mm/yyyy') { list($d, $m, $y) = explode('/', $fd); $data[$i] = $tikilib->make_time($hh, $mm, 0, $m, $d, $y); } elseif ($dateFormat == 'yyyy-mm-dd') { list($y, $m, $d) = explode('-', $fd); $data[$i] = $tikilib->make_time($hh, $mm, 0, $m, $d, $y); } break; case ($l == 19): # Field contains HH:MM:SS list($fd, $ft) = explode(' ', $data[$i]); list($hh, $mm, $ss) = explode(':', $ft); if ($dateFormat == 'mm/dd/yyyy') { list($m, $d, $y) = explode('/', $fd); $data[$i] = $tikilib->make_time($hh, $mm, $ss, $m, $d, $y); } elseif ($dateFormat == 'dd/mm/yyyy') { list($d, $m, $y) = explode('/', $fd); $data[$i] = $tikilib->make_time($hh, $mm, $ss, $m, $d, $y); } elseif ($dateFormat == 'yyyy-mm-dd') { list($y, $m, $d) = explode('-', $fd); $data[$i] = $tikilib->make_time($hh, $mm, $ss, $m, $d, $y); } break; } break;- Workaround
Correct code for v3.3 is posted in the description.
Still working on the solution for v7.... Will be available later today (22/02/2012)
Edit :
Checked for the problem on latest stable version: Problem still exists in v 8.3
I Added the proper code into the description.
ATTENTION :
- I have no PHP skills whatsoever.
- Only tested the solution for version 3.3
- Solution for version 8.3 has not been tested and needs to be revised!!!Edit 2 :
- replaced split and preg_split functions with the explode() function, as split() is EOL and preg_split() is not as fast as explode and regular expressions are not needed.- Importance
- 7
- Easy to solve?
- 7
- Priority
- 49
- Demonstrate Bug on Tiki 19+
-
This bug has been demonstrated on show2.tiki.org
Please demonstrate your bug on show2.tiki.org
Show.tiki.org is not configured properlyThe public/private keys configured to connect to show2.tiki.org were not accepted. Please make sure you are using RSA keys. Thanks.
- Demonstrate Bug (older Tiki versions)
-
This bug has been demonstrated on show.tikiwiki.org
Please demonstrate your bug on show.tikiwiki.org
Show.tiki.org is not configured properlyThe public/private keys configured to connect to show.tikiwiki.org were not accepted. Please make sure you are using RSA keys. Thanks.
- Ticket ID
- 4167
- Created
- Wednesday 22 February, 2012 13:17:39 UTC
by Beestje - LastModif
- Wednesday 22 February, 2012 16:01:06 UTC