У меня есть две такие переменные DateTime:
Код: Выделить всё
QDateTime startDateTime = QDateTime(QDate(2023,2,10), QTime(11,15,10));Код: Выделить всё
QDateTime endDateTime = QDateTime(QDate(2023,2,12), QTime(11,15,50));Код: Выделить всё
(2023,2,10)---(11,15,30)---(11,15,50)---(2023,2,11)---(11,15,30)---(11,15,50)---(2023,2,12)---(11,15,30)---(11,15,50)Затем я хочу сохранить весь результат в контейнере как
Код: Выделить всё
QMap finalRes,чтобы я мог получить к нему доступ через класс DiagramGenerator и отобразить его на оси.
Моя проблема в том, что моя реализация работает для заданной даты начала и окончания в вышеупомянутый пример, но для примеров, в которых дата окончанияQDate(2023,2,13),QDate(2023,2,14),or QDate(2023,2,11),it no longer works correctly. Either the stored dates will ten be fully out of range, or the end date will not be included anymore.
I am fully confused and I don't understand what I'm doing wrong. I appreciate any fixes and helps in advance.
Here's my code:
#include "MainWindow.h"
#include "ui_MainWindow.h"
#include
#include
#include
#include
#include
#include
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
QDateTime startDateTime = QDateTime(QDate(2023,2,10), QTime(0,0,0));
QDateTime endDateTime = QDateTime(QDate(2023,2,12), QTime(0,0,0)); //for cases 14, 11 as days it doesn't worl AT ALL!
int datesCount = startDateTime.date().daysTo(endDateTime.date()) +1; //Days in between
int secs = (QTime(0,0,0)).secsTo(QTime(23,59,59))+1; //All the 24 hours of the day into secs
unsigned int sec_offset = 0;
qDebug()
Источник: [url]https://stackoverflow.com/questions/78146311/sort-and-group-datetime-in-form-of-dates-and-then-their-in-between-times[/url]