< previous page page_101 next page >

Page 101
Listing 5.12 time_12_to_24()
/* tm12_2tm.c
   +-------------------------------------------+
   |   Copyright (C) 1995 by Lance W. Latham.  |
   |         All rights reserved.              |
   +-------------------------------------------+
   This routine converts a twelve hour clock time into its equivalent
   SCDTL twenty-four hour clock time.
   INPUTS:
   1. t12, pointer to a TIME_12 structure containing the time to be
      converted.
   OUTPUTS:
   1. Returned by routine, a TIME_INFO structure containing the SCDTL
      twenty-four hour clock equivalent of the input time.
   NOTES:
   1. Both the 12-hour and 24-hour time systems assume a format of HMS
      (hour-minute-second).
   2. Use the 'format_time_12 ()' function to display twelve hour clock
      times.
   3. This routine reverses the operation performed by the routine
      'time_24_to_12 ()' in this series.
   4. This routine does not validate the inputs. Moreover, the SCDTL
      system does not provide a routine for validating times expressed
      with the TIME_12 structure.
*/
#include "timeinfo.h"
#include "time_12.h"
struct TIME_INFO time_12_to_24 (struct TIME_12 *t12)
{
   struct TIME_INFO time;


   time.hours = t12->hours;
   time.minutes = t12->minutes;
   time.seconds = t12->seconds;


   if (t12->ap == 'A')
      {
      if (time.hours == 12)
         time.hours = 0;
      }
   else
      {
      if (time.hours < 12)
         time.hours += 12;
      }
   return (time);
}

 
< previous page page_101 next page >