Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / include / osl / time.h
blob6755dba210d49dc838ec5b28b8e3fbd64bb06f21
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_OSL_TIME_H
21 #define INCLUDED_OSL_TIME_H
23 #include <sal/config.h>
25 #if defined LIBO_INTERNAL_ONLY && defined __cplusplus
26 #include <chrono>
27 #endif
29 #include <sal/saldllapi.h>
30 #include <sal/types.h>
32 #ifdef SAL_W32
33 # pragma pack(push, 8)
34 #endif
36 /* Time since Jan-01-1970 */
38 #if defined LIBO_INTERNAL_ONLY && defined __cplusplus
40 struct TimeValue {
41 TimeValue() = default;
43 constexpr TimeValue(sal_uInt32 seconds, sal_uInt32 nanoseconds):
44 Seconds(seconds), Nanosec(nanoseconds) {}
46 template<typename Rep, typename Period> constexpr
47 TimeValue(std::chrono::duration<Rep, Period> const & duration):
48 Seconds(
49 std::chrono::duration_cast<std::chrono::nanoseconds>(
50 duration).count() / 1000000000),
51 Nanosec(
52 std::chrono::duration_cast<std::chrono::nanoseconds>(
53 duration).count() % 1000000000)
56 sal_uInt32 Seconds;
57 sal_uInt32 Nanosec;
60 #else
62 #ifdef __cplusplus
63 extern "C" {
64 #endif
66 typedef struct {
67 sal_uInt32 Seconds;
68 sal_uInt32 Nanosec;
69 } TimeValue;
71 #ifdef __cplusplus
73 #endif
75 #endif
77 #if defined(SAL_W32)
78 # pragma pack(pop)
79 #endif
81 #ifdef __cplusplus
82 extern "C" {
83 #endif
85 typedef struct _oslDateTime
87 /** contains the nanoseconds .
89 sal_uInt32 NanoSeconds;
91 /** contains the seconds (0-59).
93 sal_uInt16 Seconds;
95 /** contains the minutes (0-59).
97 sal_uInt16 Minutes;
99 /** contains the hour (0-23).
101 sal_uInt16 Hours;
103 /** is the day of month (1-31).
105 sal_uInt16 Day;
107 /** is the day of week (0-6 , 0 : Sunday).
109 sal_uInt16 DayOfWeek;
111 /** is the month of year (1-12).
113 sal_uInt16 Month;
115 /** is the year.
117 sal_Int16 Year;
119 } oslDateTime;
122 /** Get the current system time as TimeValue.
123 @retval false if any error occurs.
125 SAL_DLLPUBLIC sal_Bool SAL_CALL osl_getSystemTime(
126 TimeValue* pTimeVal );
129 /** Get the GMT from a TimeValue and fill a struct oslDateTime
130 @param[in] pTimeVal TimeValue
131 @param[out] pDateTime On success it receives a struct oslDateTime
133 @return sal_False if any error occurs else sal_True.
135 SAL_DLLPUBLIC sal_Bool SAL_CALL osl_getDateTimeFromTimeValue(
136 const TimeValue* pTimeVal, oslDateTime* pDateTime );
139 /** Get the GMT from a oslDateTime and fill a TimeValue
140 @param[in] pDateTime oslDateTime
141 @param[out] pTimeVal On success it receives a TimeValue
143 @return sal_False if any error occurs else sal_True.
145 SAL_DLLPUBLIC sal_Bool SAL_CALL osl_getTimeValueFromDateTime(
146 const oslDateTime* pDateTime, TimeValue* pTimeVal );
149 /** Convert GMT to local time
150 @param[in] pSystemTimeVal system time to convert
151 @param[out] pLocalTimeVal On success it receives the local time
153 @return sal_False if any error occurs else sal_True.
155 SAL_DLLPUBLIC sal_Bool SAL_CALL osl_getLocalTimeFromSystemTime(
156 const TimeValue* pSystemTimeVal, TimeValue* pLocalTimeVal );
159 /** Convert local time to GMT
160 @param[in] pLocalTimeVal local time to convert
161 @param[out] pSystemTimeVal On success it receives the system time
163 @return sal_False if any error occurs else sal_True.
165 SAL_DLLPUBLIC sal_Bool SAL_CALL osl_getSystemTimeFromLocalTime(
166 const TimeValue* pLocalTimeVal, TimeValue* pSystemTimeVal );
169 /** Get the value of the global timer
170 @return current timer value in milli seconds
173 SAL_DLLPUBLIC sal_uInt32 SAL_CALL osl_getGlobalTimer(void);
175 #ifdef __cplusplus
177 #endif
179 #endif // INCLUDED_OSL_TIME_H
181 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */