FreeBASIC  0.91.0
time_decodesertime.c
Go to the documentation of this file.
1 /* functions to decode a serial time number */
2 
3 #include "fb.h"
4 
5 /*:::::*/
6 FBCALL void fb_hTimeDecodeSerial ( double serial,
7  int *pHour, int *pMinute, int *pSecond,
8  int use_qb_hack )
9 {
10  int hour, minute, second;
11  double dblFixValue = fb_FIXDouble( serial );
12 
13  serial -= dblFixValue;
14  if( fb_hSign( serial ) == -1 ) {
15  if( use_qb_hack ) {
16  /* Test for both 0.0 and -0.0 because FPUs may handle this as
17  * different values ... */
18  if( dblFixValue==0.0 || dblFixValue==-0.0 ) {
19  /* QB quirk ! */
20  serial = -serial;
21  } else {
22  serial += 1.0l;
23  }
24  } else {
25  serial += 1.0l;
26  }
27  }
28 
29  /* The inaccuracies of the IEEE floating point data types ... */
30  serial += 0.000000001l;
31 
32  serial *= 24.0l;
33  hour = (int) serial;
34  serial -= hour;
35  serial *= 60.0l;
36  minute = (int) serial;
37  serial -= minute;
38  serial *= 60.0l;
39  second = (int) serial;
40 
41  if( pHour )
42  *pHour = hour;
43  if( pMinute )
44  *pMinute = minute;
45  if( pSecond )
46  *pSecond = second;
47 }
48 
49 FBCALL int fb_Hour( double serial )
50 {
51  int hour;
52  fb_hTimeDecodeSerial( serial, &hour, NULL, NULL, TRUE );
53  return hour;
54 }
55 
56 FBCALL int fb_Minute( double serial )
57 {
58  int minute;
59  fb_hTimeDecodeSerial( serial, NULL, &minute, NULL, TRUE );
60  return minute;
61 }
62 
63 FBCALL int fb_Second( double serial )
64 {
65  int second;
66  fb_hTimeDecodeSerial( serial, NULL, NULL, &second, TRUE );
67  return second;
68 }