[dev] [horde-patch] csv import: guess date format
Francois Marier
francois at nit.ca
Thu Jul 29 15:48:35 PDT 2004
Here's a Horde patch that attempts to guess the date format
automatically.
It also sets to true the default value of the "first line contains
field titles" option. This is probably a good idea since data
exported by Horde and Outlook is like that. Unless these are not the
most common sources, it makes sense to make it the default.
Francois
-------------- next part --------------
diff -rpuN -X ../ignorelist ../build/horde/templates/data/csvinfo.inc horde/templates/data/csvinfo.inc
--- ../build/horde/templates/data/csvinfo.inc Tue Sep 16 19:08:08 2003
+++ horde/templates/data/csvinfo.inc Thu Jul 29 18:35:00 2004
@@ -17,7 +17,7 @@
<?php echo _("Here is the beginning of the file:") ?><br />
<pre><?php echo htmlspecialchars($_SESSION['import_data']['first_lines']) ?></pre>
<label for="header"><?php echo _("Does the first row contain the field names? If yes, check this box:") ?></label>
- <input id="header" type="checkbox" name="header" value="1" /><br />
+ <input id="header" type="checkbox" name="header" value="1" checked/><br />
<?php echo _("What is the delimiter character?") ?>
<input type="text" name="sep" size="1" value="<?php echo htmlspecialchars($_SESSION['import_data']['sep']) ?>" /><br />
<?php if (array_key_exists('quote', $_SESSION['import_data'])): ?>
diff -rpuN -X ../ignorelist ../build/horde/templates/data/date.inc horde/templates/data/date.inc
--- ../build/horde/templates/data/date.inc Fri Nov 22 13:09:41 2002
+++ horde/templates/data/date.inc Thu Jul 29 18:38:19 2004
@@ -12,6 +12,23 @@ if (strpos($date['values'][$i], '/') !==
} else {
$del = "";
}
+
+// Try to guess the date format as much as possible
+if (!empty($del) && isset($date['values']) && isset($date['values'][$i])) {
+ $parts = explode($del, $date['values'][$i]);
+ if (count($parts) >= 3) {
+ $form = 'mdy';
+ if ((strlen($parts[0]) == 4) || ($parts[0] > 31)) {
+ $form = 'ymd';
+ if ($parts[1] > 12) {
+ $form = 'ydm';
+ }
+ } elseif ($parts[0] > 12) {
+ $form = 'dmy';
+ }
+ }
+}
+
?>
<tr>
<td><?php echo _("Select the date delimiter:") ?></td>
@@ -27,10 +44,10 @@ if (strpos($date['values'][$i], '/') !==
<td><?php echo _("Select the date format:") ?></td>
<td>
<select name="format[<?php echo $key ?>]">
- <option value="mday/month/year"><?php echo _("DD") . $del . _("MM") . $del . _("YY") ?></option>
- <option value="month/mday/year"><?php echo _("MM") . $del . _("DD") . $del . _("YY") ?></option>
- <option value="year/month/mday"><?php echo _("YY") . $del . _("MM") . $del . _("DD") ?></option>
- <option value="year/mday/month"><?php echo _("YY") . $del . _("DD") . $del . _("MM") ?></option>
+ <option value="mday/month/year"<?php echo $form == 'dmy' ? ' selected="selected"' : '' ?>><?php echo _("DD") . $del . _("MM") . $del . _("YY") ?></option>
+ <option value="month/mday/year"<?php echo $form == 'mdy' ? ' selected="selected"' : '' ?>><?php echo _("MM") . $del . _("DD") . $del . _("YY") ?></option>
+ <option value="year/month/mday"<?php echo $form == 'ymd' ? ' selected="selected"' : '' ?>><?php echo _("YY") . $del . _("MM") . $del . _("DD") ?></option>
+ <option value="year/mday/month"<?php echo $form == 'ydm' ? ' selected="selected"' : '' ?>><?php echo _("YY") . $del . _("DD") . $del . _("MM") ?></option>
</select>
</td>
</tr>
More information about the dev
mailing list