OpenRadioss 2025.1.11
OpenRadioss project
Loading...
Searching...
No Matches
timediff.c
Go to the documentation of this file.
1//Copyright> OpenRadioss
2//Copyright> Copyright (C) 1986-2025 Altair Engineering Inc.
3//Copyright>
4//Copyright> This program is free software: you can redistribute it and/or modify
5//Copyright> it under the terms of the GNU Affero General Public License as published by
6//Copyright> the Free Software Foundation, either version 3 of the License, or
7//Copyright> (at your option) any later version.
8//Copyright>
9//Copyright> This program is distributed in the hope that it will be useful,
10//Copyright> but WITHOUT ANY WARRANTY; without even the implied warranty of
11//Copyright> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12//Copyright> GNU Affero General Public License for more details.
13//Copyright>
14//Copyright> You should have received a copy of the GNU Affero General Public License
15//Copyright> along with this program. If not, see <https://www.gnu.org/licenses/>.
16//Copyright>
17//Copyright>
18//Copyright> Commercial Alternative: Altair Radioss Software
19//Copyright>
20//Copyright> As an alternative to this open-source version, Altair also offers Altair Radioss
21//Copyright> software under a commercial license. Contact Altair to discuss further if the
22//Copyright> commercial version may interest you: https://www.altair.com/radioss/.
23#include <stdio.h>
24#include <stdlib.h>
25#include <time.h>
26#define _FCALL
27
28#ifdef _WIN64
29 #include <memory.h>
30#else
31 #include <string.h>
32#endif
33
34void strptime_impl(char* date, struct tm *tm);
35/* ------------------------------------------------------------
36 time_difference : get the difference between 2 dates in UTC
37 ----------------------------------------------------------- */
38void c_time_difference(char* time_string,int * time_string_len, int * difference)
39{
40 char * c_time_string;
41 int i;
42 time_t now,now_utc,dummy_time;
43 double tdiff;
44 struct tm *tm_dum,*tm_now;
45 char datestring[32], curtime[32];
46
47 c_time_string = malloc(*time_string_len+1);
48 for (i=0;i<*time_string_len;i++) c_time_string[i]=time_string[i];
49 c_time_string[*time_string_len]='\0';
50
51
52/* Current Time in UTC */
53 time( &now );
54 strftime(datestring, 32, "%Y-%m-%dT%H:%M:%S", gmtime( &now ));
55 tm_now = (struct tm*)malloc(sizeof (struct tm));
56 strptime_impl(datestring,tm_now);
57 now_utc=mktime(tm_now);
58
59/* convert time in header*/
60 tm_dum = malloc(sizeof (struct tm));
61 strptime_impl(c_time_string,tm_dum);
62 dummy_time= mktime(tm_dum);
63 tdiff=difftime(dummy_time,now_utc);
64
65 if (tdiff > 0 ){
66 * difference = 1;
67 }else{
68 * difference = -1;
69
70 }
71// *difference=(int) tdiff;
72// printf("c_time_string: %s\n",c_time_string);
73// printf("Datestring : %s\n",datestring);
74// printf("DIFFERENCE: %lf \n",tdiff);
75// printf("Integer difference: %i \n", * difference);
76// fflush(stdout);
77}
78
79void c_time_difference_(char* time_string,int * time_string_len, int * difference){
80 c_time_difference(time_string,time_string_len, difference);
81}
82
83void _FCALL C_TIME_DIFFERENCE(char* time_string,int * time_string_len, int * difference){
84 c_time_difference(time_string,time_string_len, difference);
85}
86
87void strptime_impl(char* date, struct tm *tm)
88{
89 int year, month, day, hour, min, sec ;
90
91 memset(tm,0,sizeof(struct tm));
92
93 sscanf(date,"%d-%d-%dT%d:%d:%d",&year,&month,&day,&hour,&min,&sec );
94 tm->tm_year = year - 1900;
95 tm->tm_mon = month-1;
96 tm->tm_mday = day;
97 tm->tm_hour = hour;
98 tm->tm_min = min;
99 tm->tm_sec = sec;
100
101}
102
#define min(a, b)
Definition macros.h:20
#define _FCALL
void _FCALL C_TIME_DIFFERENCE(char *time_string, int *time_string_len, int *difference)
Definition timediff.c:83
void strptime_impl(char *date, struct tm *tm)
Definition timediff.c:87
void c_time_difference_(char *time_string, int *time_string_len, int *difference)
Definition timediff.c:79
void c_time_difference(char *time_string, int *time_string_len, int *difference)
Definition timediff.c:38