Skip to content

Commit e7157db

Browse files
authored
Merge pull request #173 from minorsecond/hotfix-purchase-date
Update ItemPurchaseDate on row selection
2 parents 55d6fd0 + e44da75 commit e7157db

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/main.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <string>
88
#include <vector>
99
#include <cmath>
10-
#include <QDebug>
10+
#include <iomanip>
1111

1212
MainWindow::MainWindow(QWidget *parent) {
1313
ui.setupUi(this);
@@ -256,8 +256,14 @@ void MainWindow::populate_fields(Item item) {
256256
bool usedInLastSixMonths = item.usedInLastSixMonths;
257257
std::string notes = item.notes;
258258

259-
std::string date_from_db = std::to_string(purchase_day) + "/" + std::to_string(purchase_month) + "/" + std::to_string(purchase_year);
259+
std::ostringstream month_padded;
260+
std::ostringstream day_padded;
261+
month_padded << std::setw(2) << std::setfill('0') << purchase_month;
262+
day_padded << std::setw(2) << std::setfill('0') << purchase_day;
263+
264+
std::string date_from_db = day_padded.str() + "/" + month_padded.str() + "/" + std::to_string(purchase_year);
260265
QDate date = QDate::fromString(QString::fromUtf8(date_from_db.c_str()), "dd/MM/yyyy");
266+
std::cout << "Date: " << date_from_db << std::endl;
261267

262268
ui.ItemName->setText(QString::fromStdString(item_name));
263269
ui.ItemCategory->setCurrentText(QString::fromStdString(item_category));

0 commit comments

Comments
 (0)