/src/libreoffice/include/osl/time.h
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
20 | | /* |
21 | | * This file is part of LibreOffice published API. |
22 | | */ |
23 | | |
24 | | #ifndef INCLUDED_OSL_TIME_H |
25 | | #define INCLUDED_OSL_TIME_H |
26 | | |
27 | | #include "sal/config.h" |
28 | | |
29 | | #if defined LIBO_INTERNAL_ONLY |
30 | | #if defined __cplusplus |
31 | | #include <chrono> |
32 | | #endif |
33 | | #endif |
34 | | |
35 | | #include "sal/saldllapi.h" |
36 | | #include "sal/types.h" |
37 | | |
38 | | #ifdef _WIN32 |
39 | | # pragma pack(push, 8) |
40 | | #endif |
41 | | |
42 | | /** Time since Jan-01-1970 |
43 | | |
44 | | @warning sal_uInt32 TimeValue::Seconds is only large enough for representing dates until year |
45 | | 2106. |
46 | | */ |
47 | | |
48 | | #if defined LIBO_INTERNAL_ONLY && defined __cplusplus |
49 | | |
50 | | struct TimeValue { |
51 | | TimeValue() = default; |
52 | | |
53 | | constexpr TimeValue(sal_uInt32 seconds, sal_uInt32 nanoseconds): |
54 | 0 | Seconds(seconds), Nanosec(nanoseconds) {} |
55 | | |
56 | | template<typename Rep, typename Period> constexpr |
57 | | TimeValue(std::chrono::duration<Rep, Period> const & duration): |
58 | | Seconds( |
59 | 0 | std::chrono::duration_cast<std::chrono::nanoseconds>( |
60 | 0 | duration).count() / 1000000000), |
61 | | Nanosec( |
62 | 0 | std::chrono::duration_cast<std::chrono::nanoseconds>( |
63 | 0 | duration).count() % 1000000000) |
64 | 0 | {}Unexecuted instantiation: TimeValue::TimeValue<long long, std::__1::ratio<1l, 1000l> >(std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000l> > const&) Unexecuted instantiation: TimeValue::TimeValue<long long, std::__1::ratio<1l, 1l> >(std::__1::chrono::duration<long long, std::__1::ratio<1l, 1l> > const&) |
65 | | |
66 | | sal_uInt32 Seconds; |
67 | | sal_uInt32 Nanosec; |
68 | | }; |
69 | | |
70 | | #else |
71 | | |
72 | | #ifdef __cplusplus |
73 | | extern "C" { |
74 | | #endif |
75 | | |
76 | | typedef struct { |
77 | | sal_uInt32 Seconds; |
78 | | sal_uInt32 Nanosec; |
79 | | } TimeValue; |
80 | | |
81 | | #ifdef __cplusplus |
82 | | } |
83 | | #endif |
84 | | |
85 | | #endif |
86 | | |
87 | | #if defined(_WIN32) |
88 | | # pragma pack(pop) |
89 | | #endif |
90 | | |
91 | | #ifdef __cplusplus |
92 | | extern "C" { |
93 | | #endif |
94 | | |
95 | | typedef struct _oslDateTime |
96 | | { |
97 | | /** contains the nanoseconds |
98 | | */ |
99 | | sal_uInt32 NanoSeconds; |
100 | | |
101 | | /** contains the seconds (0-59). |
102 | | */ |
103 | | sal_uInt16 Seconds; |
104 | | |
105 | | /** contains the minutes (0-59). |
106 | | */ |
107 | | sal_uInt16 Minutes; |
108 | | |
109 | | /** contains the hour (0-23). |
110 | | */ |
111 | | sal_uInt16 Hours; |
112 | | |
113 | | /** is the day of month (1-31). |
114 | | */ |
115 | | sal_uInt16 Day; |
116 | | |
117 | | /** is the day of week (0-6 , 0 : Sunday). |
118 | | */ |
119 | | sal_uInt16 DayOfWeek; |
120 | | |
121 | | /** is the month of year (1-12). |
122 | | */ |
123 | | sal_uInt16 Month; |
124 | | |
125 | | /** is the year. |
126 | | */ |
127 | | sal_Int16 Year; |
128 | | |
129 | | } oslDateTime; |
130 | | |
131 | | |
132 | | /** Get the current system time as TimeValue. |
133 | | @retval false if any error occurs. |
134 | | */ |
135 | | SAL_DLLPUBLIC sal_Bool SAL_CALL osl_getSystemTime( |
136 | | TimeValue* pTimeVal ); |
137 | | |
138 | | |
139 | | /** Get the GMT from a TimeValue and fill a struct oslDateTime |
140 | | @param[in] pTimeVal TimeValue |
141 | | @param[out] pDateTime On success it receives a struct oslDateTime |
142 | | |
143 | | @return sal_False if any error occurs else sal_True. |
144 | | */ |
145 | | SAL_DLLPUBLIC sal_Bool SAL_CALL osl_getDateTimeFromTimeValue( |
146 | | const TimeValue* pTimeVal, oslDateTime* pDateTime ); |
147 | | |
148 | | |
149 | | /** Get the GMT from a oslDateTime and fill a TimeValue |
150 | | @param[in] pDateTime oslDateTime |
151 | | @param[out] pTimeVal On success it receives a TimeValue |
152 | | |
153 | | @return sal_False if any error occurs else sal_True. |
154 | | */ |
155 | | SAL_DLLPUBLIC sal_Bool SAL_CALL osl_getTimeValueFromDateTime( |
156 | | const oslDateTime* pDateTime, TimeValue* pTimeVal ); |
157 | | |
158 | | |
159 | | /** Convert GMT to local time |
160 | | @param[in] pSystemTimeVal system time to convert |
161 | | @param[out] pLocalTimeVal On success it receives the local time |
162 | | |
163 | | @return sal_False if any error occurs else sal_True. |
164 | | */ |
165 | | SAL_DLLPUBLIC sal_Bool SAL_CALL osl_getLocalTimeFromSystemTime( |
166 | | const TimeValue* pSystemTimeVal, TimeValue* pLocalTimeVal ); |
167 | | |
168 | | |
169 | | /** Convert local time to GMT |
170 | | @param[in] pLocalTimeVal local time to convert |
171 | | @param[out] pSystemTimeVal On success it receives the system time |
172 | | |
173 | | @return sal_False if any error occurs else sal_True. |
174 | | */ |
175 | | SAL_DLLPUBLIC sal_Bool SAL_CALL osl_getSystemTimeFromLocalTime( |
176 | | const TimeValue* pLocalTimeVal, TimeValue* pSystemTimeVal ); |
177 | | |
178 | | |
179 | | /** Get the value of the global timer |
180 | | @return current timer value in milliseconds |
181 | | */ |
182 | | |
183 | | SAL_DLLPUBLIC sal_uInt32 SAL_CALL osl_getGlobalTimer(void); |
184 | | |
185 | | #ifdef __cplusplus |
186 | | } |
187 | | #endif |
188 | | |
189 | | #endif // INCLUDED_OSL_TIME_H |
190 | | |
191 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |