ProviewR Programmer's Reference Manual  V6.1.4
co_time.h
Go to the documentation of this file.
1 /*
2  * ProviewR Open Source Process Control.
3  * Copyright (C) 2005-2025 SSAB EMEA AB.
4  *
5  * This file is part of ProviewR.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation, either version 2 of
10  * the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with ProviewR. If not, see <http://www.gnu.org/licenses/>
19  *
20  * Linking ProviewR statically or dynamically with other modules is
21  * making a combined work based on ProviewR. Thus, the terms and
22  * conditions of the GNU General Public License cover the whole
23  * combination.
24  *
25  * In addition, as a special exception, the copyright holders of
26  * ProviewR give you permission to, from the build function in the
27  * ProviewR Configurator, combine ProviewR with modules generated by the
28  * ProviewR PLC Editor to a PLC program, regardless of the license
29  * terms of these modules. You may copy and distribute the resulting
30  * combined work under the terms of your choice, provided that every
31  * copy of the combined work is accompanied by a complete copy of
32  * the source code of ProviewR (the version used to produce the
33  * combined work), being distributed under the terms of the GNU
34  * General Public License plus this exception.
35  */
36 
37 #ifndef co_time_h
38 #define co_time_h
39 
40 #include "pwr.h"
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 /* co_time.h -- Time utilities
47 
48  This include file contains definitions and function prototypes
49  needed to use time functions.
50 
51  time_AtoFormAscii replaces co_TimeToAsc and
52  time_FormAsciiToA replaces co_AscToTime from Comator Lib. */
53 
54 #include <time.h>
55 
56 typedef unsigned int time_tClock;
57 typedef pwr_tTime time_tOs;
59 
72 typedef enum {
74  = 0,
77  = 2,
79  = 3,
85 
86 typedef enum {
87  time_ePeriod_,
88  time_ePeriod_UserDefined,
89  time_ePeriod_OneSecond,
90  time_ePeriod_10Seconds,
91  time_ePeriod_OneMinute,
92  time_ePeriod_10Minutes,
93  time_ePeriod_OneHour,
94  time_ePeriod_OneDay,
95  time_ePeriod_OneWeek,
96  time_ePeriod_OneMonth,
97  time_ePeriod_OneYear,
98  time_ePeriod_LastSecond,
99  time_ePeriod_Last10Seconds,
100  time_ePeriod_LastMinute,
101  time_ePeriod_Last10Minutes,
102  time_ePeriod_LastHour,
103  time_ePeriod_Today,
104  time_ePeriod_Yesterday,
105  time_ePeriod_ThisWeek,
106  time_ePeriod_LastWeek,
107  time_ePeriod_ThisMonth,
108  time_ePeriod_LastMonth,
109  time_ePeriod_ThisYear,
110  time_ePeriod_AllTime,
111  time_ePeriod__
112 } time_ePeriod;
113 
114 #define SWE 0
115 #define GB 1
116 
117 #define SECOND 0
118 #define HUNDRED 1
119 #define MINUTE 2
120 
121 #if defined(OS_MACOS)
122 #define CLOCK_REALTIME 1
123 #define CLOCK_MONOTONIC 2
124 typedef int clockid_t;
125 
126 int clock_gettime(clockid_t clockid, struct timespec* ts);
127 
128 int clock_getres(clockid_t clockid, struct timespec* tp);
129 #endif
130 
137 int time_IsNull(pwr_tTime* t1);
138 pwr_tTime* time_Aabs(pwr_tTime*, pwr_tTime*);
139 pwr_tTime* time_Aadd(pwr_tTime*, pwr_tTime*, pwr_tDeltaTime*);
140 pwr_tTime* time_Aadd_NE(pwr_tTime*, pwr_tTime*, pwr_tDeltaTime*);
141 int time_Acomp(pwr_tTime*, pwr_tTime*);
142 int time_Acomp_NE(pwr_tTime*, pwr_tTime*);
143 pwr_tDeltaTime* time_Adiff(pwr_tDeltaTime*, pwr_tTime*, pwr_tTime*);
144 pwr_tDeltaTime* time_Adiff_NE(pwr_tDeltaTime*, pwr_tTime*, pwr_tTime*);
145 pwr_tTime* time_Aneg(pwr_tTime*, pwr_tTime*);
146 pwr_tTime* time_Asub(pwr_tTime*, pwr_tTime*, pwr_tDeltaTime*);
147 pwr_tTime* time_Asub_NE(pwr_tTime*, pwr_tTime*, pwr_tDeltaTime*);
156 
159 pwr_tStatus time_DtoAscii(pwr_tDeltaTime*, int, char*, int);
160 pwr_tStatus time_AtoAscii(pwr_tTime*, time_eFormat, char*, int);
162 pwr_tStatus time_AsciiToA(const char*, pwr_tTime*);
163 pwr_tStatus time_TmToAscii(struct tm*, time_eFormat, char*, int);
164 pwr_tStatus time_AsciiToTm(const char*, struct tm*);
165 pwr_tStatus time_FormAsciiToA(const char*, short, short, pwr_tTime*);
166 void time_AtoFormAscii(pwr_tTime*, short, short, char[], int);
168 
173 
175 time_tClock time_Clock(pwr_tStatus*, pwr_tDeltaTime*);
176 time_tOs* time_Os(pwr_tStatus*, time_tOs*);
179 time_tOs* time_AtoOs(pwr_tStatus*, time_tOs*, pwr_tTime*);
180 time_tOs* time_DtoOs(pwr_tStatus*, time_tOs*, pwr_tDeltaTime*);
182 void time_Sleep(float time);
183 int time_GetTime(pwr_tTime* ts);
184 int time_GetTimeMonotonic(pwr_tTime* ts);
185 char* time_GetTimeAscii(time_eFormat format);
186 int time_PeriodPreviousMonth(pwr_tTime* time, pwr_tTime* from, pwr_tTime* to);
187 int time_PeriodPreviousWeek(pwr_tTime* time, pwr_tTime* from, pwr_tTime* to);
188 void time_PreviousDayBreak(pwr_tTime* time, pwr_tTime* daybreak);
189 void time_Period(time_ePeriod period, pwr_tTime* from, pwr_tTime* to,
190  pwr_tTime* center, int daybreak);
191 void time_PreviousPeriod(time_ePeriod period, pwr_tTime* prev_from,
192  pwr_tTime* prev_to, pwr_tTime* from, pwr_tTime* to);
193 void time_NextPeriod(time_ePeriod period, pwr_tTime* prev_from,
194  pwr_tTime* prev_to, pwr_tTime* from, pwr_tTime* to);
195 int time_PeriodZoomIn(time_ePeriod* period);
196 int time_PeriodZoomOut(time_ePeriod* period);
197 int time_PrintA(const char* format, pwr_tTime* ts);
198 pwr_tFloat32 time_AdiffToFloat(pwr_tTime* t, pwr_tTime* s);
199 
203 #ifdef __cplusplus
204 }
205 #endif
206 
207 #endif
time_eFormat
Time string format.
Definition: co_time.h:72
@ time_eFormat_NumDateAndTime
Date and time format, 2005-01-01 00:00:00.
Definition: co_time.h:78
@ time_eFormat_ComprDateAndTime
Date and time compressed format, 70-01-01 00:00:00.
Definition: co_time.h:76
@ time_eFormat_TimeAndDate
Time and date format, 01:00:00 30/01/87.
Definition: co_time.h:83
@ time_eFormat_Time
Display time only 01:00:00.00.
Definition: co_time.h:75
@ time_eFormat_FileDateAndTime
Date and time format, 20050101_000000.
Definition: co_time.h:80
@ time_eFormat_DateAndTime
Display date and time, 01-JAN-1970 01:00:00.00.
Definition: co_time.h:73
@ time_eFormat_FileDate
Date format, 20050101.
Definition: co_time.h:81
@ time_eFormat_DateAndTimeLoc
Display date and time with local month.
Definition: co_time.h:82
pwr_tStatus time_AsciiToA(const char *, pwr_tTime *)
Convert ascii time to timespec.
Definition: co_time.c:999
pwr_tDeltaTime * time_Float64ToD(pwr_tDeltaTime *, pwr_tFloat64)
Convert double to time.
Definition: co_time.c:1316
int time_IsNull(pwr_tTime *t1)
Test if time is Null.
Definition: co_time.c:177
pwr_tDeltaTime * time_ClockToD(pwr_tStatus *, pwr_tDeltaTime *, time_tClock)
Convert clock time to delta time.
Definition: co_time.c:1387
pwr_tStatus time_AsciiToD(const char *, pwr_tDeltaTime *)
Convert ascii to timespec.
Definition: co_time.c:928
pwr_tDeltaTime * time_Dneg(pwr_tDeltaTime *, pwr_tDeltaTime *)
Negate a delta time,.
Definition: co_time.c:690
pwr_tDeltaTime * time_FloatToD(pwr_tDeltaTime *, pwr_tFloat32)
Convert float to time.
Definition: co_time.c:1293
pwr_tStatus time_DtoAscii(pwr_tDeltaTime *, int, char *, int)
Convert a delta time to ascii string.
Definition: co_time.c:819
int time_GetTimeMonotonic(pwr_tTime *ts)
Get current monotonic time.
Definition: co_time.c:1440
pwr_tDeltaTime * time_Dadd(pwr_tDeltaTime *, pwr_tDeltaTime *, pwr_tDeltaTime *)
Add two delta times, the result is also delta.
Definition: co_time.c:547
int time_GetTime(pwr_tTime *ts)
Get current time.
Definition: co_time.c:1427
pwr_tDeltaTime * time_Dsub(pwr_tDeltaTime *, pwr_tDeltaTime *, pwr_tDeltaTime *)
Subtract two delta times.
Definition: co_time.c:750
pwr_tTime * time_Aadd_NE(pwr_tTime *, pwr_tTime *, pwr_tDeltaTime *)
Add an absolute time and a delta time.
Definition: co_time.c:240
pwr_tStatus time_AsciiToTm(const char *, struct tm *)
Convert timestring to struct.
Definition: co_time.c:1079
pwr_tDeltaTime * time_ZeroD(pwr_tDeltaTime *)
Zero a delta time.
Definition: co_time.c:1403
int time_PeriodPreviousWeek(pwr_tTime *time, pwr_tTime *from, pwr_tTime *to)
Calculate start and end time for previous week.
Definition: co_time.c:1622
time_tClock time_DtoClock(pwr_tStatus *, pwr_tDeltaTime *)
Convert delta time to clock time.
Definition: co_time.c:1379
int time_Dcomp(pwr_tDeltaTime *, pwr_tDeltaTime *)
Compare two delta times.
Definition: co_time.c:629
pwr_tDeltaTime * time_Dabs_NE(pwr_tDeltaTime *, pwr_tDeltaTime *)
Take the absolute walue of a delta time.
Definition: co_time.c:516
pwr_tDeltaTime * time_MsToD(pwr_tDeltaTime *, pwr_tInt32)
Convert millisec to timespec.
Definition: co_time.c:1275
pwr_tDeltaTime * time_Dadd_NE(pwr_tDeltaTime *, pwr_tDeltaTime *, pwr_tDeltaTime *)
Add two delta times, the result is also delta.
Definition: co_time.c:584
int time_PrintA(const char *format, pwr_tTime *ts)
Print an absolute time. The format should contain s.
Definition: co_time.c:2211
pwr_tTime * time_Asub(pwr_tTime *, pwr_tTime *, pwr_tDeltaTime *)
Subtract a delta time from a time,.
Definition: co_time.c:408
void time_PreviousDayBreak(pwr_tTime *time, pwr_tTime *daybreak)
Calculate previous daybreak.
Definition: co_time.c:1653
int time_Acomp_NE(pwr_tTime *, pwr_tTime *)
Compare two timespecs.
Definition: co_time.c:312
char * time_GetTimeAscii(time_eFormat format)
Get current time in ascii.
Definition: co_time.c:920
pwr_tDeltaTime * time_Adiff_NE(pwr_tDeltaTime *, pwr_tTime *, pwr_tTime *)
Subtract a time from a time,.
Definition: co_time.c:373
pwr_tStatus time_AtoAscii(pwr_tTime *, time_eFormat, char *, int)
Convert timespec to ascii.
Definition: co_time.c:878
pwr_tFloat64 time_DToFloat64(pwr_tFloat64 *, pwr_tDeltaTime *)
Convert time to Float64.
Definition: co_time.c:1360
pwr_tDeltaTime * time_Dabs(pwr_tDeltaTime *, pwr_tDeltaTime *)
Take the absolute walue of a delta time.
Definition: co_time.c:484
int time_Acomp(pwr_tTime *, pwr_tTime *)
Compare two timespecs.
Definition: co_time.c:282
int time_Dcomp_NE(pwr_tDeltaTime *, pwr_tDeltaTime *)
Compare two delta times.
Definition: co_time.c:660
pwr_tDeltaTime * time_Adiff(pwr_tDeltaTime *, pwr_tTime *, pwr_tTime *)
Subtract a time from a time,.
Definition: co_time.c:339
pwr_tDeltaTime * time_Dsub_NE(pwr_tDeltaTime *, pwr_tDeltaTime *, pwr_tDeltaTime *)
Subtract two delta times.
Definition: co_time.c:786
pwr_tFloat32 time_DToFloat(pwr_tFloat32 *, pwr_tDeltaTime *)
Convert time to Float32.
Definition: co_time.c:1340
pwr_tStatus time_TmToAscii(struct tm *, time_eFormat, char *, int)
Convert time struct to string.
Definition: co_time.c:1046
pwr_tFloat32 time_AdiffToFloat(pwr_tTime *t, pwr_tTime *s)
Subtract a time from a time and return the differens.
Definition: co_time.c:2225
pwr_tTime * time_Asub_NE(pwr_tTime *, pwr_tTime *, pwr_tDeltaTime *)
Subtract a delta time from a time,.
Definition: co_time.c:444
pwr_tTime * time_Aadd(pwr_tTime *, pwr_tTime *, pwr_tDeltaTime *)
Add an absolute time and a delta time.
Definition: co_time.c:199
pwr_tDeltaTime * time_Dneg_NE(pwr_tDeltaTime *, pwr_tDeltaTime *)
Negate a delta time,.
Definition: co_time.c:721
Basic type definitions. This include file contains the Proview basic type definitions.
double pwr_tFloat64
64-bit float.
Definition: pwr.h:135
int pwr_tInt32
32-bit integer type.
Definition: pwr.h:159
int pwr_tStatus
Status type.
Definition: pwr.h:284
float pwr_tFloat32
32-bit float.
Definition: pwr.h:131
Delta time type.
Definition: pwr.h:369