summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Miika Turkia <miika.turkia@gmail.com>2014-11-25 19:47:04 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-11-25 13:19:49 -0800
commit1b74947bf56a2ef3b38470044d991a75ed0c5e30 (patch)
treea4b63ce2d76ee024870d5b1dc8d6039f7b391702
parent3b3d8949f7b3aede87fd779b314c6604020cbd16 (diff)
downloadsubsurface-1b74947bf56a2ef3b38470044d991a75ed0c5e30.tar.gz
Allow user to select date format on manual CSV import
Signed-off-by: Miika Turkia <miika.turkia@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--dive.h2
-rw-r--r--file.c8
-rw-r--r--qt-ui/divelogimportdialog.cpp1
-rw-r--r--qt-ui/divelogimportdialog.ui72
-rw-r--r--xslt/manualcsv2xml.xslt41
5 files changed, 92 insertions, 32 deletions
diff --git a/dive.h b/dive.h
index 0ddc43f02..95f4d6f68 100644
--- a/dive.h
+++ b/dive.h
@@ -631,7 +631,7 @@ extern int parse_file(const char *filename);
extern int parse_csv_file(const char *filename, int time, int depth, int temp, int po2f, int cnsf, int ndlf, int ttsf, int stopdepthf, int pressuref, int sepidx, const char *csvtemplate, int units);
extern int parse_seabear_csv_file(const char *filename, int time, int depth, int temp, int po2f, int cnsf, int ndlf, int ttsf, int stopdepthf, int pressuref, int sepidx, const char *csvtemplate, int units);
extern int parse_txt_file(const char *filename, const char *csv);
-extern int parse_manual_file(const char *filename, int separator_index, int units, int number, int date, int time, int duration, int location, int gps, int maxdepth, int meandepth, int buddy, int notes, int weight, int tags);
+extern int parse_manual_file(const char *filename, int separator_index, int units, int dateformat, int number, int date, int time, int duration, int location, int gps, int maxdepth, int meandepth, int buddy, int notes, int weight, int tags);
extern int save_dives(const char *filename);
extern int save_dives_logic(const char *filename, bool select_only);
diff --git a/file.c b/file.c
index f6b415e76..e755b3ad4 100644
--- a/file.c
+++ b/file.c
@@ -943,11 +943,11 @@ int parse_seabear_csv_file(const char *filename, int timef, int depthf, int temp
return 0;
}
-int parse_manual_file(const char *filename, int sepidx, int units, int numberf, int datef, int timef, int durationf, int locationf, int gpsf, int maxdepthf, int meandepthf, int buddyf, int notesf, int weightf, int tagsf)
+int parse_manual_file(const char *filename, int sepidx, int units, int dateformat, int numberf, int datef, int timef, int durationf, int locationf, int gpsf, int maxdepthf, int meandepthf, int buddyf, int notesf, int weightf, int tagsf)
{
struct memblock mem;
int pnr = 0;
- char *params[33];
+ char *params[35];
char numberbuf[MAXCOLDIGITS];
char datebuf[MAXCOLDIGITS];
char timebuf[MAXCOLDIGITS];
@@ -962,6 +962,7 @@ int parse_manual_file(const char *filename, int sepidx, int units, int numberf,
char tagsbuf[MAXCOLDIGITS];
char separator_index[MAXCOLDIGITS];
char unit[MAXCOLDIGITS];
+ char datefmt[MAXCOLDIGITS];
time_t now;
struct tm *timep;
char curdate[9];
@@ -984,6 +985,7 @@ int parse_manual_file(const char *filename, int sepidx, int units, int numberf,
snprintf(tagsbuf, MAXCOLDIGITS, "%d", tagsf);
snprintf(separator_index, MAXCOLDIGITS, "%d", sepidx);
snprintf(unit, MAXCOLDIGITS, "%d", units);
+ snprintf(datefmt, MAXCOLDIGITS, "%d", dateformat);
time(&now);
timep = localtime(&now);
strftime(curdate, DATESTR, "%Y%m%d", timep);
@@ -1024,6 +1026,8 @@ int parse_manual_file(const char *filename, int sepidx, int units, int numberf,
params[pnr++] = separator_index;
params[pnr++] = "units";
params[pnr++] = unit;
+ params[pnr++] = "datefmt";
+ params[pnr++] = datefmt;
params[pnr++] = NULL;
if (filename == NULL)
diff --git a/qt-ui/divelogimportdialog.cpp b/qt-ui/divelogimportdialog.cpp
index 91c1d738e..8946e6a78 100644
--- a/qt-ui/divelogimportdialog.cpp
+++ b/qt-ui/divelogimportdialog.cpp
@@ -107,6 +107,7 @@ void DiveLogImportDialog::on_buttonBox_accepted()
parse_manual_file(fileNames[i].toUtf8().data(),
ui->ManualSeparator->currentIndex(),
ui->Units->currentIndex(),
+ ui->DateFormat->currentIndex(),
VALUE_IF_CHECKED(DiveNumber),
VALUE_IF_CHECKED(Date), VALUE_IF_CHECKED(Time),
VALUE_IF_CHECKED(Duration), VALUE_IF_CHECKED(Location),
diff --git a/qt-ui/divelogimportdialog.ui b/qt-ui/divelogimportdialog.ui
index 97b698901..accf3fe2a 100644
--- a/qt-ui/divelogimportdialog.ui
+++ b/qt-ui/divelogimportdialog.ui
@@ -296,6 +296,53 @@
<string>Manual dives</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_4">
+ <item row="0" column="1">
+ <widget class="QGroupBox" name="groupBox_5">
+ <property name="title">
+ <string>Field separator</string>
+ </property>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QComboBox" name="ManualSeparator"/>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item row="2" column="1">
+ <widget class="QGroupBox" name="groupBox_8">
+ <property name="toolTip">
+ <string>Choose day, month and year order for date format. The field separator can be any of the characters .-/.</string>
+ </property>
+ <property name="title">
+ <string>Date format</string>
+ </property>
+ <widget class="QComboBox" name="DateFormat">
+ <property name="geometry">
+ <rect>
+ <x>20</x>
+ <y>40</y>
+ <width>131</width>
+ <height>27</height>
+ </rect>
+ </property>
+ <item>
+ <property name="text">
+ <string>dd.mm.yyyy</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>mm/dd/yyyy</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>yyyy-mm-dd</string>
+ </property>
+ </item>
+ </widget>
+ </widget>
+ </item>
<item row="1" column="1">
<widget class="QGroupBox" name="groupBox_6">
<property name="title">
@@ -544,31 +591,6 @@
</layout>
</widget>
</item>
- <item row="0" column="1">
- <widget class="QGroupBox" name="groupBox_5">
- <property name="title">
- <string>Field separator</string>
- </property>
- <layout class="QHBoxLayout" name="horizontalLayout">
- <item>
- <widget class="QComboBox" name="ManualSeparator"/>
- </item>
- </layout>
- </widget>
- </item>
- <item row="2" column="1">
- <spacer name="verticalSpacer_2">
- <property name="orientation">
- <enum>Qt::Vertical</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>20</width>
- <height>40</height>
- </size>
- </property>
- </spacer>
- </item>
</layout>
</widget>
</widget>
diff --git a/xslt/manualcsv2xml.xslt b/xslt/manualcsv2xml.xslt
index 7e138d1e0..cbfb9ea14 100644
--- a/xslt/manualcsv2xml.xslt
+++ b/xslt/manualcsv2xml.xslt
@@ -18,6 +18,7 @@
<xsl:param name="buddyField" select="buddyField"/>
<xsl:param name="notesField" select="notesField"/>
<xsl:param name="weightField" select="weightField"/>
+ <xsl:param name="dateformat" select="dateformat"/>
<xsl:output method="xml" indent="yes"/>
<xsl:variable name="lf"><xsl:text>
@@ -79,10 +80,42 @@
<xsl:attribute name="date">
<xsl:choose>
<xsl:when test="$dateField >= 0">
- <xsl:call-template name="getFieldByIndex">
- <xsl:with-param name="index" select="$dateField"/>
- <xsl:with-param name="line" select="$line"/>
- </xsl:call-template>
+ <xsl:variable name="indate">
+ <xsl:call-template name="getFieldByIndex">
+ <xsl:with-param name="index" select="$dateField"/>
+ <xsl:with-param name="line" select="$line"/>
+ </xsl:call-template>
+ </xsl:variable>
+ <xsl:variable name="separator">
+ <xsl:choose>
+ <xsl:when test="substring-before($indate, '.') != ''">
+ <xsl:value-of select="'.'"/>
+ </xsl:when>
+ <xsl:when test="substring-before($indate, '-') != ''">
+ <xsl:value-of select="'-'"/>
+ </xsl:when>
+ <xsl:when test="substring-before($indate, '/') != ''">
+ <xsl:value-of select="'/'"/>
+ </xsl:when>
+ </xsl:choose>
+ </xsl:variable>
+ <xsl:choose>
+ <!-- dd.mm.yyyy -->
+ <xsl:when test="$datefmt = 0">
+ <xsl:value-of select="concat(substring-after(substring-after($indate, $separator), $separator), '-', substring-before(substring-after($indate, $separator), $separator), '-', substring-before($indate, $separator))"/>
+ </xsl:when>
+ <!-- mm.yy.yyyy -->
+ <xsl:when test="$datefmt = 1">
+ <xsl:value-of select="concat(substring-after(substring-after($indate, $separator), $separator), '-', substring-before($indate, $separator), '-', substring-before(substring-after($indate, $separator), $separator))"/>
+ </xsl:when>
+ <!-- yyyy.mm.dd -->
+ <xsl:when test="$datefmt = 2">
+ <xsl:value-of select="concat(substring-before($indate, $separator), '-', substring-before(substring-after($indate, $separator), $separator), '-', substring-after(substring-after($indate, $separator), $separator))"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="'1900-1-1'"/>
+ </xsl:otherwise>
+ </xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat(substring($date, 1, 4), '-', substring($date, 5, 2), '-', substring($date, 7, 2))"/>