GSI Object Oriented Online Offline (Go4)  GO4-6.2.0
 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 2867 2020-05-18 16:23:49Z 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 fuer 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 
53 #include <stdio.h>
54 #include <string.h>
55 #include "f_ut_time.h"
56 
57 INTS4 f_ut_utime(INTS4 l_sec, INTS4 l_msec, CHARS *pc_time)
58 {
59  // struct timeb tp;
60  struct timespec tp;
61  struct tm st_time;
62 #ifndef WIN32
63  struct tm buf_time;
64 #endif
65  CHARS c_allmon[37]="JanFebMarAprMayJunJulAugSepOctNovDec";
66  CHARS c_mon[4];
67  CHARS *pc_mon;
68 
69  if(l_sec == 0) {
70  strcpy(pc_time,"no valid date");
71  return(0);
72  }
73  *pc_time=0;
74  if (l_sec < 0) {
75  clock_gettime(CLOCK_REALTIME, &tp);
76  l_msec = tp.tv_nsec / 1000000;
77  } else {
78  tp.tv_sec = l_sec;
79  }
80 #ifdef WIN32
81  st_time=*localtime(&tp.tv_sec);
82 #else
83  st_time = *localtime_r(&tp.tv_sec, &buf_time);
84 #endif
85  pc_mon = (CHARS *) &c_allmon;
86  pc_mon += (st_time.tm_mon * 3);
87  strncpy(c_mon,pc_mon,3);
88  c_mon[3]='\0';
89  if(st_time.tm_year < 100)
90  sprintf(pc_time,"%02d-%s-19%02d %02d:%02d:%02d.%02d"
91  ,st_time.tm_mday
92  ,c_mon
93  ,st_time.tm_year
94  ,st_time.tm_hour
95  ,st_time.tm_min
96  ,st_time.tm_sec
97  ,l_msec/10);
98  else
99  sprintf(pc_time,"%02d-%s-20%02d %02d:%02d:%02d.%02d"
100  ,st_time.tm_mday
101  ,c_mon
102  ,st_time.tm_year-100
103  ,st_time.tm_hour
104  ,st_time.tm_min
105  ,st_time.tm_sec
106  ,l_msec/10);
107  return(0);
108 }
int INTS4
Definition: typedefs.h:28
INTS4 f_ut_utime(INTS4 l_sec, INTS4 l_msec, CHARS *pc_time)
Definition: f_ut_utime.c:57
char CHARS
Definition: typedefs.h:21