From 80853afd732aba126caa138ac421b036d2005f8d Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Thu, 23 Aug 2018 18:04:07 +0200 Subject: Add startOfDay() and endOfDay() methods to QDate These methods give the first and last QDateTime values in the given day, for a given time-zone or time-spec. These are usually the relevant midnight, or the millisecond before, except when time-zone transitions (typically DST changes) skip it, when care is needed to select the right moment. Adapted some code to make use of the new API, eliminating some old cruft from qdatetimeparser_p.h in the process. [ChangeLog][QtCore][QDate] Added startOfDay() and endOfDay() methods to provide a QDateTime at the start and end of a given date, taking account of any time skipped by transitions, e.g. a DST spring-forward, which can lead to a day starting at 01:00 or ending just before 23:00. Task-number: QTBUG-64485 Change-Id: I3dd7a34bedfbec8f8af00c43d13f50f99346ecd0 Reviewed-by: Thiago Macieira --- src/corelib/doc/snippets/code/src_corelib_tools_qdatetime.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/corelib/doc/snippets/code/src_corelib_tools_qdatetime.cpp') diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qdatetime.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qdatetime.cpp index 3ecb67a48f..a477e91548 100644 --- a/src/corelib/doc/snippets/code/src_corelib_tools_qdatetime.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_tools_qdatetime.cpp @@ -128,7 +128,7 @@ qDebug("Time elapsed: %d ms", t.elapsed()); //! [11] QDateTime now = QDateTime::currentDateTime(); -QDateTime xmas(QDate(now.date().year(), 12, 25), QTime(0, 0)); +QDateTime xmas(QDate(now.date().year(), 12, 25).startOfDay()); qDebug("There are %d seconds to Christmas", now.secsTo(xmas)); //! [11] -- cgit v1.2.3