mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
CSV import: support for user specified date format
Signed-off-by: Miika Turkia <miika.turkia@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
43f9112420
commit
a83c674139
2 changed files with 41 additions and 6 deletions
|
@ -720,6 +720,8 @@ int DiveLogImportDialog::setup_csv_params(QStringList r, char **params, int pnr)
|
|||
{
|
||||
params[pnr++] = strdup("dateField");
|
||||
params[pnr++] = intdup(r.indexOf(tr("Date")));
|
||||
params[pnr++] = strdup("datefmt");
|
||||
params[pnr++] = intdup(ui->DateFormat->currentIndex());
|
||||
params[pnr++] = strdup("timeField");
|
||||
params[pnr++] = intdup(r.indexOf(tr("Sample time")));
|
||||
params[pnr++] = strdup("depthField");
|
||||
|
@ -821,7 +823,7 @@ void DiveLogImportDialog::on_buttonBox_accepted()
|
|||
sample->tts.seconds *= 60;
|
||||
}
|
||||
} else {
|
||||
char *params[41];
|
||||
char *params[43];
|
||||
int pnr = 0;
|
||||
|
||||
pnr = setup_csv_params(r, params, pnr);
|
||||
|
@ -888,7 +890,7 @@ void DiveLogImportDialog::on_buttonBox_accepted()
|
|||
|
||||
parse_manual_file(fileNames[i].toUtf8().data(), params, pnr - 1);
|
||||
} else {
|
||||
char *params[41];
|
||||
char *params[43];
|
||||
int pnr = 0;
|
||||
|
||||
pnr = setup_csv_params(r, params, pnr);
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
<xsl:include href="commonTemplates.xsl"/>
|
||||
<xsl:strip-space elements="*"/>
|
||||
<xsl:param name="dateField" select="dateField"/>
|
||||
<xsl:param name="datefmt" select="datefmt"/>
|
||||
<xsl:param name="timeField" select="timeField"/>
|
||||
<xsl:param name="depthField" select="depthField"/>
|
||||
<xsl:param name="tempField" select="tempField"/>
|
||||
|
@ -43,10 +44,42 @@
|
|||
<xsl:attribute name="date">
|
||||
<xsl:choose>
|
||||
<xsl:when test="$dateField >= 0">
|
||||
<xsl:variable name="indate">
|
||||
<xsl:call-template name="getFieldByIndex">
|
||||
<xsl:with-param name="index" select="$dateField"/>
|
||||
<xsl:with-param name="line" select="substring-after(substring-after(., $lf), $lf)"/>
|
||||
</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="translate(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="translate(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="translate(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))"/>
|
||||
|
|
Loading…
Add table
Reference in a new issue