Avoid potential negative array index access to cached text.
[LibreOffice.git] / include / osl / time.h
blobf2f5b7a4f8edc29cf659b15954d8d3dd0fbd076a
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 .
21 * This file is part of LibreOffice published API.
24 #ifndef INCLUDED_OSL_TIME_H
25 #define INCLUDED_OSL_TIME_H
27 #include "sal/config.h"
29 #if defined LIBO_INTERNAL_ONLY
30 #if defined __cplusplus
31 #include <chrono>
32 #endif
33 #endif
35 #include "sal/saldllapi.h"
36 #include "sal/types.h"
38 #ifdef _WIN32
39 # pragma pack(push, 8)
40 #endif
42 /** Time since Jan-01-1970
44 @warning sal_uInt32 TimeValue::Seconds is only large enough for representing dates until year
45 2106.
48 #if defined LIBO_INTERNAL_ONLY && defined __cplusplus
50 struct TimeValue {
51 TimeValue() = default;
53 constexpr TimeValue(sal_uInt32 seconds, sal_uInt32 nanoseconds):
54 Seconds(seconds), Nanosec(nanoseconds) {}
56 template<typename Rep, typename Period> constexpr
57 TimeValue(std::chrono::duration<Rep, Period> const & duration):
58 Seconds(
59 std::chrono::duration_cast<std::chrono::nanoseconds>(
60 duration).count() / 1000000000),
61 Nanosec(
62 std::chrono::duration_cast<std::chrono::nanoseconds>(
63 duration).count() % 1000000000)
66 sal_uInt32 Seconds;
67 sal_uInt32 Nanosec;
70 #else
72 #ifdef __cplusplus
73 extern "C" {
74 #endif
76 typedef struct {
77 sal_uInt32 Seconds;
78 sal_uInt32 Nanosec;
79 } TimeValue;
81 #ifdef __cplusplus
83 #endif
85 #endif
87 #if defined(_WIN32)
88 # pragma pack(pop)
89 #endif
91 #ifdef __cplusplus
92 extern "C" {
93 #endif
95 typedef struct _oslDateTime
97 /** contains the nanoseconds
99 sal_uInt32 NanoSeconds;
101 /** contains the seconds (0-59).
103 sal_uInt16 Seconds;
105 /** contains the minutes (0-59).
107 sal_uInt16 Minutes;
109 /** contains the hour (0-23).
111 sal_uInt16 Hours;
113 /** is the day of month (1-31).
115 sal_uInt16 Day;
117 /** is the day of week (0-6 , 0 : Sunday).
119 sal_uInt16 DayOfWeek;
121 /** is the month of year (1-12).
123 sal_uInt16 Month;
125 /** is the year.
127 sal_Int16 Year;
129 } oslDateTime;
132 /** Get the current system time as TimeValue.
133 @retval false if any error occurs.
135 SAL_DLLPUBLIC sal_Bool SAL_CALL osl_getSystemTime(
136 TimeValue* pTimeVal );
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
143 @return sal_False if any error occurs else sal_True.
145 SAL_DLLPUBLIC sal_Bool SAL_CALL osl_getDateTimeFromTimeValue(
146 const TimeValue* pTimeVal, oslDateTime* pDateTime );
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
153 @return sal_False if any error occurs else sal_True.
155 SAL_DLLPUBLIC sal_Bool SAL_CALL osl_getTimeValueFromDateTime(
156 const oslDateTime* pDateTime, TimeValue* pTimeVal );
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
163 @return sal_False if any error occurs else sal_True.
165 SAL_DLLPUBLIC sal_Bool SAL_CALL osl_getLocalTimeFromSystemTime(
166 const TimeValue* pSystemTimeVal, TimeValue* pLocalTimeVal );
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
173 @return sal_False if any error occurs else sal_True.
175 SAL_DLLPUBLIC sal_Bool SAL_CALL osl_getSystemTimeFromLocalTime(
176 const TimeValue* pLocalTimeVal, TimeValue* pSystemTimeVal );
179 /** Get the value of the global timer
180 @return current timer value in milliseconds
183 SAL_DLLPUBLIC sal_uInt32 SAL_CALL osl_getGlobalTimer(void);
185 #ifdef __cplusplus
187 #endif
189 #endif // INCLUDED_OSL_TIME_H
191 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */