FreeBASIC
0.91.0
Main Page
Data Structures
Files
File List
Globals
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
12
fb_ErrorSetNum
(
FB_RTERROR_OK
);
13
14
switch
( interval_type ) {
15
case
FB_TIME_INTERVAL_YEAR
:
16
fb_hDateDecodeSerial
( serial, &year,
NULL
,
NULL
);
17
result = year;
18
break
;
19
case
FB_TIME_INTERVAL_QUARTER
:
20
fb_hDateDecodeSerial
( serial,
NULL
, &month,
NULL
);
21
result = ((month - 1) / 3) + 1;
22
break
;
23
case
FB_TIME_INTERVAL_MONTH
:
24
fb_hDateDecodeSerial
( serial,
NULL
, &month,
NULL
);
25
result = month;
26
break
;
27
case
FB_TIME_INTERVAL_DAY_OF_YEAR
:
28
fb_hDateDecodeSerial
( serial, &year, &month, &day );
29
result =
fb_hGetDayOfYearEx
( year, month, day );
30
break
;
31
case
FB_TIME_INTERVAL_DAY
:
32
fb_hDateDecodeSerial
( serial,
NULL
,
NULL
, &day );
33
result = day;
34
break
;
35
case
FB_TIME_INTERVAL_WEEKDAY
:
36
result =
fb_Weekday
( serial, first_day_of_week );
37
break
;
38
case
FB_TIME_INTERVAL_WEEK_OF_YEAR
:
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
;
44
case
FB_TIME_INTERVAL_HOUR
:
45
fb_hTimeDecodeSerial
( serial, &hour,
NULL
,
NULL
,
FALSE
);
46
result = hour;
47
break
;
48
case
FB_TIME_INTERVAL_MINUTE
:
49
fb_hTimeDecodeSerial
( serial,
NULL
, &minute,
NULL
,
FALSE
);
50
result = minute;
51
break
;
52
case
FB_TIME_INTERVAL_SECOND
:
53
fb_hTimeDecodeSerial
( serial,
NULL
,
NULL
, &second,
FALSE
);
54
result = second;
55
break
;
56
case
FB_TIME_INTERVAL_INVALID
:
57
default
:
58
fb_ErrorSetNum
(
FB_RTERROR_ILLEGALFUNCTIONCALL
);
59
break
;
60
}
61
62
return
result;
63
}
rtlib
time_datepart.c
Generated on Thu Jan 23 2014 19:40:14 for FreeBASIC by
1.8.4