GSI Object Oriented Online Offline (Go4)  GO4-5.3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
f_ut_utime.c
Go to the documentation of this file.
1 // $Id: f_ut_utime.c 1355 2015-01-27 14:28:43Z linev $
2 //-----------------------------------------------------------------------
3 // The GSI Online Offline Object Oriented (Go4) Project
4 // Experiment Data Processing at EE department, GSI
5 //-----------------------------------------------------------------------
6 // Copyright (C) 2000- GSI Helmholtzzentrum für Schwerionenforschung GmbH
7 // Planckstr. 1, 64291 Darmstadt, Germany
8 // Contact: http://go4.gsi.de
9 //-----------------------------------------------------------------------
10 // This software can be used under the license agreements as stated
11 // in Go4License.txt file which is part of the distribution.
12 //-----------------------------------------------------------------------
13 
14 #include "f_ut_utime.h"
15 
16 /*****************+***********+****************************************/
17 /* */
18 /* GSI, Gesellschaft fuer Schwerionenforschung mbH */
19 /* Postfach 11 05 52 */
20 /* D-64220 Darmstadt */
21 /* */
22 /*1+ C Procedure *************+****************************************/
23 /* */
24 /*+ Module : f_ut_utime */
25 /* */
26 /*--------------------------------------------------------------------*/
27 /*+ CALLING : char * = f_ut_utime(l_sec,l_msec,char *pc_time) */
28 /*--------------------------------------------------------------------*/
29 /* */
30 /*+ PURPOSE : Returns date/time string in VMS format */
31 /* day-month-year hours:min:sec.00 */
32 /* */
33 /*+ ARGUMENTS : */
34 /* */
35 /*+ l_sec : Seconds as returned from ftime function */
36 /*+ l_msec : Milliseconds */
37 /*+ pc_time : Address of string (23 characters) */
38 /* */
39 /*2+Implementation************+****************************************/
40 /*+ Utility : util */
41 /*+ File name : f_ut_utime.c */
42 /*+ Home direct.: path */
43 /*+ Declaration : char *f_ut_utime(char *); */
44 /*+ Version : 1.01 */
45 /*+ Author : H.G.Essel */
46 /*+ Created : 24-Mar-1994 */
47 /*+ Object libr.: */
48 /*+ Updates : Date Purpose */
49 /*- 14-apr-97 : POSIX now OK on Lynx /HE */
50 /* gcc -mposix4d9 -mthreads -DLynx */
51 /*1- C Procedure *************+****************************************/
52 #ifdef Lynx
53 #include <sys/types.h>
54 #include <timeb.h>
55 #else
56 #include <sys/types.h>
57 #include <sys/timeb.h>
58 #endif
59 #include <stdio.h>
60 #include <time.h>
61 #include <string.h>
62 
63 INTS4 f_ut_utime(INTS4 l_sec, INTS4 l_msec, CHARS *pc_time)
64 {
65 
66  time_t t_time;
67  struct timeb tp;
68  struct tm st_time;
69  struct tm buf_time;
70  CHARS c_allmon[37]="JanFebMarAprMayJunJulAugSepOctNovDec";
71  CHARS c_mon[4];
72  CHARS *pc_mon;
73 
74  if(l_sec == 0)
75  {
76  strcpy(pc_time,"no valid date");
77 #ifdef VMS
78  return(1);
79 #else
80  return(0);
81 #endif
82  }
83  *pc_time=0;
84  ftime(&tp);
85  if(l_sec > 0)
86  {
87  tp.time = l_sec;
88 /*
89 #ifdef VMS
90  tp.time = l_sec + 7200;
91 #endif
92 */
93 #ifdef Lynx
94  tp.time = l_sec + 86400; /* one day */
95 #endif
96  tp.millitm = l_msec;
97  }
98 #ifdef Lynx
99  localtime_r(&st_time,&tp.time);
100  if(st_time.tm_mon > 2 && st_time.tm_mon < 9) /* daylight saving ? */
101  {
102  tp.time+=3600;
103  localtime_r(&st_time,&tp.time);
104  }
105 #else
106 #ifdef WIN32
107  st_time=*localtime(&tp.time);
108 #else
109  st_time = *localtime_r(&tp.time, &buf_time);
110 #endif
111 #endif
112  pc_mon = (CHARS *) &c_allmon;
113  pc_mon += (st_time.tm_mon * 3);
114  strncpy(c_mon,pc_mon,3);
115  c_mon[3]='\0';
116  if(st_time.tm_year < 100)
117  sprintf(pc_time,"%02d-%s-19%02d %02d:%02d:%02d.%02d"
118  ,st_time.tm_mday
119  ,c_mon
120  ,st_time.tm_year
121  ,st_time.tm_hour
122  ,st_time.tm_min
123  ,st_time.tm_sec
124  ,l_msec/10);
125  else
126  sprintf(pc_time,"%02d-%s-20%02d %02d:%02d:%02d.%02d"
127  ,st_time.tm_mday
128  ,c_mon
129  ,st_time.tm_year-100
130  ,st_time.tm_hour
131  ,st_time.tm_min
132  ,st_time.tm_sec
133  ,l_msec/10);
134 #ifdef VMS
135  return(1);
136 #else
137  return(0);
138 #endif
139 }
int INTS4
Definition: typedefs.h:28
INTS4 f_ut_utime(INTS4 l_sec, INTS4 l_msec, CHARS *pc_time)
Definition: f_ut_utime.c:63
char CHARS
Definition: typedefs.h:21