FreeBASIC  0.91.0
time_datepart.c
Go to the documentation of this file.
1 /* datepart function */
2 
3 #include "fb.h"
4 
5 /*:::::*/
6 FBCALL int fb_DatePart( FBSTRING *interval, double serial, int first_day_of_week, int first_day_of_year )
7 {
8  int result = 0;
9  int year, month, day, hour, minute, second;
10  int interval_type = fb_hTimeGetIntervalType( interval );
11 
13 
14  switch ( interval_type ) {
16  fb_hDateDecodeSerial ( serial, &year, NULL, NULL );
17  result = year;
18  break;
20  fb_hDateDecodeSerial ( serial, NULL, &month, NULL );
21  result = ((month - 1) / 3) + 1;
22  break;
24  fb_hDateDecodeSerial ( serial, NULL, &month, NULL );
25  result = month;
26  break;
28  fb_hDateDecodeSerial ( serial, &year, &month, &day );
29  result = fb_hGetDayOfYearEx( year, month, day );
30  break;
32  fb_hDateDecodeSerial ( serial, NULL, NULL, &day );
33  result = day;
34  break;
36  result = fb_Weekday( serial, first_day_of_week );
37  break;
39  fb_hDateDecodeSerial ( serial, &year, NULL, NULL );
40  result = fb_hGetWeekOfYear( year, serial, first_day_of_year, first_day_of_week );
41  if( result < 0 )
42  result = fb_hGetWeekOfYear( year - 1, serial, first_day_of_year, first_day_of_week );
43  break;
45  fb_hTimeDecodeSerial ( serial, &hour, NULL, NULL, FALSE );
46  result = hour;
47  break;
49  fb_hTimeDecodeSerial ( serial, NULL, &minute, NULL, FALSE );
50  result = minute;
51  break;
53  fb_hTimeDecodeSerial ( serial, NULL, NULL, &second, FALSE );
54  result = second;
55  break;
57  default:
59  break;
60  }
61 
62  return result;
63 }