timec

TimeC -- convert compressed time to ASCII time and date

BOOL timec(bintime, chartime)

unsigned short bintime[3]

char chartime[24]

PURPOSE

This function takes the compressed time in bintime and converts it to an ASCII string in the form YYYY-MMM-DD HH:MM:SS.MMM.

INPUTS

bintime

compressed binary time

OUTPUTS

chartime

ASCII time

This routine returns false if bintime contains an invalid date or time. Chartime is defined only if the routine returns true.

PARACODE

BOOL timec (bintime, chartime) unsigned short bintime [3] ; /* binary time */ char chartime[24] ; /* yyyy-mmm-dd hh:mm:ss.sss */ set chartime to ????-???-?? ??:??:??.??? year = bintime[2] >> (15+1+7) AND NOT (NOT ZERO << 7) imonth = bintime[2] >> (8+1-4) AND NOT (NOT ZERO << 4) day = bintime[2] >> (4+1-5) AND NOT (NOT ZERO << 5) year = year + 1900 milliseconds = bintime[1] * 32768 + bintime[0] hours = milliseconds / 1000 / 60 / 60 minutes = (milliseconds / 1000 / 60) MODULO 60 seconds = (milliseconds / 1000) MODULO 60 milsecs = milliseconds MODULO 1000 if 1900 <= year <= 2027 then put year into chartime string else ok = NO if 1 <= imonth <= 12 case imonth of 1 : month = Jan 2 : month = Feb . . . 12 : month = Dec put month into chartime string else ok = NO if 01 <= day <= 31 then put day into chartime string else ok = NO if 00 <= hours <= 99 then put hours into chartime string else ok = NO if 00 <= minutes <=59 then put minutes into chartime string else ok = NO if 000 <= milsecs <= 999 then put milsecs into chartime string else ok = NO return OK

CODE

/* * Module summary: * timec - Convert time from binary to character form. * * */ #include #include "air.h" BOOLE timec (bintime, outtime) TIMEBT bintime ; /* binary time */ TIMECT outtime ; /* yyyy-mmm-dd hh:mm:ss.sss */ { short year, imonth, day, hours, minutes, seconds, milsecs ; long milliseconds ; /* milliseconds since midnight */ char month[3] ; /* month as mmm */ BOOLE ok ; char chartime[25] ; /* yyyy-mmm-dd hh:mm:ss.sss + NUL*/ ok = YES ; strncpy (chartime, "????-???-?? ??:??:??.???", 24) ; year = bintime[2] >> (15+1-7) & ~(~0 << 7) ; imonth = bintime[2] >> (8+1-4) & ~(~0 << 4) ; day = bintime[2] >> (4+1-5) & ~(~0 << 5) ; year += 1900 ; milliseconds = (long) bintime[1] * 32768 + bintime[0] ; hours = milliseconds / 1000 / 60 / 60 ; minutes = (milliseconds / 1000 / 60) % 60 ; seconds = (milliseconds / 1000) % 60 ; milsecs = milliseconds % 1000 ; ok = YES ; if ( 1900 <= year && year <= 2027) { sprintf (chartime, "%0*u", 4, year) ; strncpy (&chartime[4], "-", 1) ; } else ok = NO ; if ( 1 <= imonth && imonth <= 12 ) { if (imonth == 1) strncpy(month, "Jan", 3) ; else if (imonth == 2) strncpy(month, "Feb", 3) ; else if (imonth == 3) strncpy(month, "Mar", 3) ; else if (imonth == 4) strncpy(month, "Apr", 3) ; else if (imonth == 5) strncpy(month, "May", 3) ; else if (imonth == 6) strncpy(month, "Jun", 3) ; else if (imonth == 7) strncpy(month, "Jul", 3) ; else if (imonth == 8) strncpy(month, "Aug", 3) ; else if (imonth == 9) strncpy(month, "Sep", 3) ; else if (imonth == 10) strncpy(month, "Oct", 3) ; else if (imonth == 11) strncpy(month, "Nov", 3) ; else if (imonth == 12) strncpy(month, "Dec", 3) ; sprintf (&chartime[5], "%*s", 3, month) ; strncpy (&chartime[8], "-", 1) ; } else ok = YES ; if (01 <= day && day <= 31) { sprintf (&chartime[9], "%0*u", 2, day) ; strncpy (&chartime[11], " ", 1) ; } else ok = NO ; if (00 <= hours && hours <= 99) { sprintf (&chartime[12], "%0*u", 2, hours) ; strncpy (&chartime[14], ":", 1) ; } else ok = NO ; if (00 <= minutes && minutes <= 59) { sprintf (&chartime[15], "%0*u", 2, minutes) ; strncpy (&chartime[17], ":", 1) ; } else ok = NO ; if (00 <= seconds && seconds <= 59) { sprintf (&chartime[18], "%0*u", 2, seconds) ; strncpy (&chartime[20], ".", 1) ; } else ok = NO ; if (000 <= milsecs && milsecs <= 999) sprintf (&chartime[21], "%0*u", 3, milsecs) ; else ok = NO ; if (ok) { strncpy (outtime, chartime, 24) ; } return (ok) ; }