FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
f_ut_utime.c
Go to the documentation of this file.
1 // $Id: f_ut_utime.c 581 2010-02-18 12:49:52Z 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/timeb.h>
57 #include <sys/types.h>
58 #endif
59 #include <stdio.h>
60 #include <string.h>
61 #include <time.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  CHARS c_allmon[37] = "JanFebMarAprMayJunJulAugSepOctNovDec";
70  CHARS c_mon[4];
71  CHARS* pc_mon;
72 
73  if (l_sec == 0) {
74  strcpy(pc_time, "no valid date");
75 #ifdef VMS
76  return (1);
77 #else
78  return (0);
79 #endif
80  }
81  *pc_time = 0;
82  ftime(&tp);
83  if (l_sec > 0) {
84  tp.time = l_sec;
85  /*
86  #ifdef VMS
87  tp.time = l_sec + 7200;
88  #endif
89  */
90 #ifdef xxxLynx
91  tp.time = l_sec + 86400; /* one day */
92 #endif
93  tp.millitm = l_msec;
94  }
95 #ifdef xxxLynx
96  localtime_r(&st_time, &tp.time);
97  if (st_time.tm_mon > 2 && st_time.tm_mon < 9) { /* daylight saving ? */
98  tp.time += 3600;
99  localtime_r(&st_time, &tp.time);
100  }
101 #else
102  st_time = *localtime(&tp.time);
103 #endif
104  pc_mon = (CHARS*)&c_allmon;
105  pc_mon += (st_time.tm_mon * 3);
106  strncpy(c_mon, pc_mon, 3);
107  c_mon[3] = '\0';
108  if (st_time.tm_year < 100)
109  sprintf(pc_time,
110  "%02d-%s-19%02d %02d:%02d:%02d.%02d",
111  st_time.tm_mday,
112  c_mon,
113  st_time.tm_year,
114  st_time.tm_hour,
115  st_time.tm_min,
116  st_time.tm_sec,
117  l_msec / 10);
118  else
119  sprintf(pc_time,
120  "%02d-%s-20%02d %02d:%02d:%02d.%02d",
121  st_time.tm_mday,
122  c_mon,
123  st_time.tm_year - 100,
124  st_time.tm_hour,
125  st_time.tm_min,
126  st_time.tm_sec,
127  l_msec / 10);
128 #ifdef VMS
129  return (1);
130 #else
131  return (0);
132 #endif
133 }
int INTS4
Definition: typedefs.h:21
INTS4 f_ut_utime(INTS4, INTS4, CHARS *)
Definition: f_ut_utime.c:63
char CHARS
Definition: typedefs.h:15