From 6706f6a58e5ae09ea7cf3b1433eee4f8372a630e Mon Sep 17 00:00:00 2001 From: MassiveAtoms Date: Sat, 20 Jul 2019 10:33:19 -0300 Subject: [PATCH] timme functs, not incorporated yet --- Query.cpp | 46 ++++++++++++++++++++++++++++++---------------- headers/Query.h | 4 ++++ main.cpp | 2 +- 3 files changed, 35 insertions(+), 17 deletions(-) diff --git a/Query.cpp b/Query.cpp index 7dd237d..dfc2524 100644 --- a/Query.cpp +++ b/Query.cpp @@ -83,6 +83,36 @@ int query_role_customer(int id){ //------------------------------- parkspot info + +pair create_month_period(int month, int year) { + std::time_t t = std::time(0); + std::tm* date = std::localtime(&t); + date->tm_year = year - 1900; + date->tm_mday = 1; + date->tm_mon = month - 1; + pair period; + period.first = mktime(date); + date->tm_mon = month; + period.second = mktime(date); + return period; +} + +pair create_week_period(int day, int month, int year){ + std::time_t t = std::time(0); + std::tm* date = std::localtime(&t); + date->tm_year = year - 1900; + date->tm_mday = day; + date->tm_mon = month - 1; + date->tm_hour = 0; + date->tm_min = 0; + pair period; + period.first = mktime(date); + period.second = period.first + 604800; // plus 7 days in seconds + return period; +} + +// -- parkspots info, report gen + Park_spot query_parkspot_with_id(int id, vector& parkspots) { for (Park_spot& i : parkspots) { if (i.id == id) { @@ -163,19 +193,3 @@ void current_status_parkspots(vector& spots) { } } -// -------------- paroking spots - -// vector populate_spots(){ -// vector spots; -// SQLite::Statement query(data::db, "SELECT * FROM Park_spot WHERE id > -// 0;"); -// // query.bind(1, 2); -// while (query.executeStep()) { -// int id = query.getColumn(0); -// int taken = query.getColumn(1); -// int cid = query.getColumn(2); -// // park_customers.push_back(query_customer_with_id(cid)); -// spots.push_back({id, taken, cid}); -// } -// return spots; -// } \ No newline at end of file diff --git a/headers/Query.h b/headers/Query.h index 5401990..1b4ef9e 100644 --- a/headers/Query.h +++ b/headers/Query.h @@ -3,6 +3,7 @@ #pragma once #include "Park_spot.h" +using std::pair; /*these are the functions that search the database and create objects from it. @@ -65,4 +66,7 @@ void reports_from_parkspot(int spotid, bool weekly = false); void reports_from_allparkspots(bool weekly = false); void current_status_parkspots(vector& spots); + +pair create_month_period(int month, int year) ; +pair create_week_period(int day, int month, int year); #endif // CUSTOMER_H diff --git a/main.cpp b/main.cpp index 7b1b50d..52a582a 100644 --- a/main.cpp +++ b/main.cpp @@ -76,4 +76,4 @@ vector populate_spots() { spots.push_back({id, taken, cid, vtype}); } return spots; -} \ No newline at end of file +}