S2OPC OPCUA Toolkit
p_time_c99.h
Go to the documentation of this file.
1 /*
2  * Licensed to Systerel under one or more contributor license
3  * agreements. See the NOTICE file distributed with this work
4  * for additional information regarding copyright ownership.
5  * Systerel licenses this file to you under the Apache
6  * License, Version 2.0 (the "License"); you may not use this
7  * file except in compliance with the License. You may obtain
8  * a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19 
20 #ifndef PIKEOS_TIME_H
21 #define PIKEOS_TIME_H
22 
23 #include <stdint.h>
24 #include <stdio.h>
25 
26 struct tm
27 {
28  int tm_sec;
29  int tm_min;
30  int tm_hour;
31  int tm_mday;
32  int tm_mon;
33  int tm_year;
34  int tm_wday;
35  int tm_yday;
36  int tm_isdst;
38  const char* __tm_zone;
39 };
40 
41 /* Represent time in second */
42 typedef int64_t time_t;
43 
44 /************************************************
45  * Public API *
46  *************************************************/
47 
48 size_t strftime(char* strBuffer, size_t maxSize, const char* format, const struct tm* pTime);
49 
50 /* MUSL implementation */
51 
52 time_t mktime(struct tm* tp);
53 
54 /* Timezone for the pikeos machine cannot be easily access, so we decide to not take in account Timezone.
55  * This mean that localtime_r and gmtime_r has the same behavior and will fill struct tm as if you were in UTC + 0.
56  * Impact in S2OPC code is minimal since absolute date time is only used to print logs. */
57 struct tm* localtime_r(const time_t* restrict t, struct tm* restrict tm);
58 struct tm* gmtime_r(const time_t* restrict t, struct tm* restrict tm);
59 struct tm* gmtime(const time_t* restrict t);
60 
61 /************************************************
62  * Internal API *
63  *************************************************/
64 
65 int __month_to_secs(int, int);
66 long long __year_to_secs(long long, int*);
67 long long __tm_to_secs(const struct tm*);
68 int __secs_to_tm(long long, struct tm*);
69 void __secs_to_zone(long long, int, int*, long*, long*, const char**);
70 
71 #endif // PIKEOS_TIME_H
__month_to_secs
int __month_to_secs(int, int)
tm::__tm_zone
const char * __tm_zone
Definition: p_time_c99.h:38
tm::tm_min
int tm_min
Definition: p_time_c99.h:29
strftime
size_t strftime(char *strBuffer, size_t maxSize, const char *format, const struct tm *pTime)
gmtime
struct tm * gmtime(const time_t *restrict t)
__year_to_secs
long long __year_to_secs(long long, int *)
tm::tm_wday
int tm_wday
Definition: p_time_c99.h:34
localtime_r
struct tm * localtime_r(const time_t *restrict t, struct tm *restrict tm)
tm::tm_sec
int tm_sec
Definition: p_time_c99.h:28
tm::tm_mon
int tm_mon
Definition: p_time_c99.h:32
time_t
int64_t time_t
Definition: p_time_c99.h:42
tm::tm_mday
int tm_mday
Definition: p_time_c99.h:31
tm::tm_hour
int tm_hour
Definition: p_time_c99.h:30
mktime
time_t mktime(struct tm *tp)
tm::tm_isdst
int tm_isdst
Definition: p_time_c99.h:36
tm::__tm_gmtoff
long __tm_gmtoff
Definition: p_time_c99.h:37
__secs_to_zone
void __secs_to_zone(long long, int, int *, long *, long *, const char **)
__tm_to_secs
long long __tm_to_secs(const struct tm *)
gmtime_r
struct tm * gmtime_r(const time_t *restrict t, struct tm *restrict tm)
tm
Definition: p_time_c99.h:27
tm::tm_year
int tm_year
Definition: p_time_c99.h:33
tm::tm_yday
int tm_yday
Definition: p_time_c99.h:35
__secs_to_tm
int __secs_to_tm(long long, struct tm *)