IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 23, 2005, 9:13:00 PM (21 years ago)
Author:
eugene
Message:

added valid time ranges and elements of Njobs, status

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/lib.data/convert.c

    r2598 r4602  
    11# include "convert.h"
     2# define _XOPEN_SOURCE /* glibc2 needs this */
     3# include <time.h>
     4
     5char *strptime(const char *s, const char *format, struct tm *tm);
     6
    27 
    38int hh_hms (double hh, int *hr, int *mn, double *sc) {
     
    160165
    161166  return (status);
     167}
     168
     169/***** convert 00:00:00 or 00:00 to 0 - 86400 ****/
     170int hms_to_sec (char *string, time_t *second) {
     171 
     172  char *p;
     173  struct tm time;
     174
     175  p = strptime (string, "%H:%M:%S", &time);
     176  if (p != NULL) goto valid;
     177
     178  p = strptime (string, "%H:%M", &time);
     179  if (p != NULL) goto valid;
     180
     181  return (FALSE);
     182   
     183valid:
     184  if (*p) return (FALSE);
     185  *second = time.tm_hour*3600 + time.tm_min*60 + time.tm_sec;
     186  return (TRUE);
     187}
     188
     189/***** convert Mon[@00:00:00] or 00:00 to 0 - 86400*7 ****/
     190int day_to_sec (char *string, time_t *second) {
     191 
     192  char *p;
     193  struct tm time;
     194
     195  bzero (&time, sizeof(time));
     196  p = strptime (string, "%A@%H:%M:%S", &time);
     197  if (p != NULL) goto valid;
     198
     199  p = strptime (string, "%A@%H:%M", &time);
     200  if (p != NULL) goto valid;
     201
     202  p = strptime (string, "%A@%H", &time);
     203  if (p != NULL) goto valid;
     204
     205  p = strptime (string, "%A", &time);
     206  if (p != NULL) goto valid;
     207
     208  return (FALSE);
     209
     210valid:
     211  if (*p) return (FALSE);
     212  *second = time.tm_wday*86400 + time.tm_hour*3600 + time.tm_min*60 + time.tm_sec;
     213  return (TRUE);
    162214}
    163215
Note: See TracChangeset for help on using the changeset viewer.