libtime++: Date and time calculation

◆ time_read()

int time_read ( time_Ts Date,
const char *  String 
)

Definition at line 37 of file ctime_read.c.

References time_Ts::doy, EXIT_FAILURE, EXIT_SUCCESS, time_Ts::hour, time_Ts::micsec, time_Ts::milsec, time_Ts::minute, RETURNERROR, time_Ts::second, time_clear(), time_fullyear(), time_norm(), time_setdoy(), and time_Ts::year.

Referenced by libtime::TBaseClassTime::string_read(), and ttime_read().

38 {
39  double sec;
40  const char *ptr;
41  char cmilmicsec[7];
42  integer day, month, milmicsec;
43  int i;
44 
45  time_clear(Date);
46  ptr=String;
47 
48  ptr=strpbrk(ptr, "0123456789");
49  RETURNERROR((ptr==NULL), "time_read", \
50  "year is missing", EXIT_FAILURE)
51  Date->year=strtol(ptr, &ptr, 10);
52 
53  ptr=strpbrk(ptr, "0123456789");
54  RETURNERROR((ptr==NULL), "time_read", \
55  "month is missing", EXIT_FAILURE)
56  month=strtol(ptr, &ptr, 10);
57 
58  ptr=strpbrk(ptr, "0123456789");
59  RETURNERROR((ptr==NULL), "time_read", \
60  "day is missing", EXIT_FAILURE)
61  day=strtol(ptr, &ptr, 10);
62 
63  ptr=strpbrk(ptr, "0123456789");
64  if (ptr!=NULL) {
65  Date->hour=strtol(ptr, &ptr, 10);
66  ptr=strpbrk(ptr, "0123456789");
67  }
68  if (ptr!=NULL) {
69  Date->minute=strtol(ptr, &ptr, 10);
70  ptr=strpbrk(ptr, "0123456789");
71  }
72  if (ptr!=NULL) {
73  Date->second=strtol(ptr, &ptr, 10);
74  ptr=strpbrk(ptr, "0123456789");
75  }
76  if (ptr!=NULL) {
77  for(i=0; i<6; i++) {
78  if (ptr!=NULL) {
79  if (isdigit(ptr[i])) {
80  cmilmicsec[i]=ptr[i];
81  } else {
82  ptr=NULL;
83  cmilmicsec[i]='0';
84  }
85  } else {
86  cmilmicsec[i]='0';
87  }
88  cmilmicsec[6]='\0';
89  }
90  milmicsec=strtol(cmilmicsec, &ptr, 10);
91  Date->milsec=(integer)(milmicsec/1000);
92  Date->micsec=milmicsec-(Date->milsec*1000);
93  }
94 
95  if ((month>0 && Date->year>0) || month>0)
96  {
97  time_fullyear(&Date->year);
98  time_setdoy(day, month, Date);
99  }
100  else
101  {
102  Date->doy=day;
103  }
104 
105  time_norm(Date);
106  return(EXIT_SUCCESS);
107 } /* time_read */
#define RETURNERROR(EXPR, SUB, STR, CODE)
Definition: libtime.h:96
integer milsec
Definition: libtime.h:127
integer minute
Definition: libtime.h:125
integer hour
Definition: libtime.h:124
integer doy
Definition: libtime.h:123
void time_setdoy(timeint day, timeint month, time_Ts *Pdate)
Definition: ctime_setdoy.c:36
void time_clear(time_Ts *Pdate)
Definition: ctime_clear.c:33
void time_norm(time_Ts *Pdate)
Definition: ctime_norm.c:33
void time_fullyear(timeint *year)
integer second
Definition: libtime.h:126
long int integer
Definition: libtime.h:64
integer year
Definition: libtime.h:122
#define EXIT_SUCCESS
Definition: libtime.h:86
#define EXIT_FAILURE
Definition: libtime.h:91
integer micsec
Definition: libtime.h:128
Here is the call graph for this function:
Here is the caller graph for this function: