< previous page page_102 next page >

Page 102
Listing 5.13 time_24_to_12()
/* tm2_tm12.c
   +-------------------------------------------+
   |   Copyright (C) 1995 by Lance W. Latham.  |
   |         All rights reserved.              |
   +-------------------------------------------+
   This routine converts a twenty-four hour clock time into its equivalent
   twelve hour clock time.


   INPUTS:
   1. time, pointer to a TIME_INFO structure, containing the time to be
      converted.


   OUTPUTS:
   1. Returned by routine, a TIME_12 structure containing the twelve
      hour clock equivalent of the input time.


   NOTES:
   1. Both 12-hour and 24-hour clock time systems assume the HMS
      (hour-minute-second) format.
   2. Use the 'format_time_12 ()' function to display twelve hour clock
      times.
   3. This routine does not validate the input. Use the routine in this
      series, 'valid_time_24 ()' for that purpose.
*/
#include "timeinfo.h"
#include "time_12.h"
struct TIME_12 time_24_to_12 (struct TIME_INFO *time)
{
   struct TIME_12 t12;
   t12.hours = time->hours;
   t12.minutes = time->minutes;
   t12.seconds = time->seconds;
   t12.ap = 'A';
   if (t12.hours < 12)
      {
      if (t12.hours == 0)
         t12.hours = 12;
      }
   else
      {
      t12.ap = 'P';
      if (t12.hours > 12)
         t12.hours -= 12;
      }
   return (t12);
}

 
< previous page page_102 next page >