From 5103c6a405e93bb05018ab7c89e7e9446c740aaa Mon Sep 17 00:00:00 2001 From: Takeshi Abe Date: Sun, 29 Apr 2018 05:20:47 +0900 Subject: tools: Avoid looking up system clock twice to get DateTime DateTime::DateTime(DateTimeInitSystem) had initialized Date and Time separately, which causes a slight possibility that it could get a wrong datetime with almost 24 hours delay when it went beyond midnight. E.g., the date part was of the previous day while the time part was 00:00:00.xxx of the next day. This also reduces duplicate code by sharing GetSystemDateTime(). Change-Id: I352d90f468f5cbc70e7936a337bed97365baa06c Reviewed-on: https://gerrit.libreoffice.org/53612 Tested-by: Jenkins Reviewed-by: Eike Rathke --- tools/inc/systemdatetime.hxx | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 tools/inc/systemdatetime.hxx (limited to 'tools/inc') diff --git a/tools/inc/systemdatetime.hxx b/tools/inc/systemdatetime.hxx new file mode 100644 index 000000000000..cc74eae61340 --- /dev/null +++ b/tools/inc/systemdatetime.hxx @@ -0,0 +1,26 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +#ifndef INCLUDED_TOOLS_INC_SYSTEMDATETIME_H +#define INCLUDED_TOOLS_INC_SYSTEMDATETIME_H + +#include + +constexpr sal_Int64 SEC_MASK = SAL_CONST_INT64(1000000000); +constexpr sal_Int64 MIN_MASK = SAL_CONST_INT64(100000000000); +constexpr sal_Int64 HOUR_MASK = SAL_CONST_INT64(10000000000000); + +/** Get current local timestamp. + Both pDate and pTime can be null. + Returns true if succeeded, false otherwse. + */ +bool GetSystemDateTime(sal_Int32* pDate, sal_Int64* pTime); + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ -- cgit v1.2.3