diff options
author | Takeshi Abe <tabe@fixedpoint.jp> | 2018-04-29 05:20:47 +0900 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2018-05-04 21:30:43 +0200 |
commit | 5103c6a405e93bb05018ab7c89e7e9446c740aaa (patch) | |
tree | 98b3b1705cfcd0eeb867cff94e8766f1978c287f /tools/inc | |
parent | 7b0ff01d1bf718c5b439b5cddfcdfe051271b28c (diff) |
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 <ci@libreoffice.org>
Reviewed-by: Eike Rathke <erack@redhat.com>
Diffstat (limited to 'tools/inc')
-rw-r--r-- | tools/inc/systemdatetime.hxx | 26 |
1 files changed, 26 insertions, 0 deletions
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 <sal/types.h> + +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: */ |