Permalink
Browse files

Add Java Epoch format conversion

Java epoch is measured in milliseconds from unix 0; conversion is a
(roundabout, best I could find) way to convert milliseconds into a
SQLite datetime while keeping millisecond resolution.

Easier alternative would be column_name / 1000, but loses _some_
theoretical resolution.
  • Loading branch information...
Grif392 authored and MKleusberg committed Sep 10, 2017
1 parent ae8df56 commit 46ec0197193ad127103f7d8408895e7c4f76fc67
Showing with 3 additions and 0 deletions.
  1. +3 −0 src/ColumnDisplayFormatDialog.cpp
@@ -20,6 +20,7 @@ ColumnDisplayFormatDialog::ColumnDisplayFormatDialog(const QString& colname, QSt
ui->comboDisplayFormat->addItem(tr("Octal number"), "octal");
ui->comboDisplayFormat->addItem(tr("Round number"), "round");
ui->comboDisplayFormat->addItem(tr("Unix epoch to date"), "epoch");
ui->comboDisplayFormat->addItem(tr("Java epoch (milliseconds) to date"), "javaEpoch");
ui->comboDisplayFormat->addItem(tr("Upper case"), "upper");
ui->comboDisplayFormat->addItem(tr("Windows DATE to date"), "winDate");
ui->labelDisplayFormat->setText(ui->labelDisplayFormat->text().arg(column_name));
@@ -61,6 +62,8 @@ void ColumnDisplayFormatDialog::updateSqlCode()
ui->editDisplayFormat->setText("upper(" + sqlb::escapeIdentifier(column_name) + ")");
else if(format == "epoch")
ui->editDisplayFormat->setText("datetime(" + sqlb::escapeIdentifier(column_name) + ", 'unixepoch')");
else if(format == "javaEpoch")
ui->editDisplayFormat->setText("strftime('%Y-%m-%d %H:%M:%S.', " + sqlb::escapeIdentifier(column_name) + "/1000, 'unixepoch') || (" + sqlb::escapeIdentifier(column_name) + "%1000)");

This comment has been minimized.

@dutchcop

dutchcop Feb 21, 2018

Why not use strftime('%Y-%m-%d %H:%M:%f', ... (note the %f flag for fractionals) and use a non-integer division (e.g. * 0.001 or / 1000.0)?

This comment has been minimized.

@justinclift

justinclift Feb 21, 2018

Member

Sounds reasonable to me, though I'm not a C++ developer any more. Would you be ok to create a Pull Request with the suggested code change? 😄

else if(format == "winDate")
ui->editDisplayFormat->setText("datetime ('1899-12-30', " + sqlb::escapeIdentifier(column_name) + " || \" days\" )");
else if(format == "appleDate")

0 comments on commit 46ec019

Please sign in to comment.