Skip to content

Commit

Permalink
Add Java Epoch format conversion
Browse files Browse the repository at this point in the history
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 46ec019
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/ColumnDisplayFormatDialog.cpp
Expand Up @@ -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));
Expand Down Expand Up @@ -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.

Copy link
@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")
Expand Down

0 comments on commit 46ec019

Please sign in to comment.