FreeBASIC  0.91.0
time_parsedatetime.c
Go to the documentation of this file.
1 /* parse a string containing a date and/or time */
2 
3 #include "fb.h"
4 #include <ctype.h>
5 
6 /*:::::*/
8  int *pDay, int *pMonth, int *pYear,
9  int *pHour, int *pMinute, int *pSecond,
10  int want_date, int want_time)
11 {
12 
13  const char *text;
14  int result = FALSE;
15  size_t length, text_len;
16 
17  text = s->data;
18  text_len = FB_STRSIZE( s );
19 
20  if( text == NULL ) {
21  return result;
22  }
23 
24  if( fb_hDateParse( text, text_len, pDay, pMonth, pYear, &length ) ) {
25  text += length;
26  text_len -= length;
27 
28  /* skip WS */
29  while( isspace( *text ) )
30  ++text, --text_len;
31  /* skip optional comma */
32  if( *text==',' )
33  ++text, --text_len;
34 
35  if( fb_hTimeParse( text, text_len, pHour, pMinute, pSecond, &length ) ) {
36  text += length;
37  text_len -= length;
38  result = TRUE;
39  } else if( !want_time ) {
40  result = TRUE;
41  }
42  } else if( fb_hTimeParse( text, text_len, pHour, pMinute, pSecond, &length ) ) {
43  text += length;
44  text_len -= length;
45 
46  /* skip WS */
47  while( isspace( *text ) )
48  ++text, --text_len;
49  /* skip optional comma */
50  if( *text==',' )
51  ++text, --text_len;
52 
53  if( fb_hDateParse( text, text_len, pDay, pMonth, pYear, &length ) ) {
54  text += length;
55  text_len -= length;
56  result = TRUE;
57  } else if( !want_date ) {
58  result = TRUE;
59  }
60  }
61 
62  if( result ) {
63  /* the rest of the text must consist of white spaces */
64  while( *text ) {
65  if( !isspace( *text++ ) ) {
66  result = FALSE;
67  break;
68  }
69  }
70  }
71 
72  return result;
73 }
74 
75 /*:::::*/
76 FBCALL int fb_DateParse( FBSTRING *s, int *pDay, int *pMonth, int *pYear )
77 {
78  return fb_DateTimeParse( s,
79  pDay, pMonth, pYear,
80  NULL, NULL, NULL,
81  TRUE, FALSE );
82 }
83 
84 /*:::::*/
85 FBCALL int fb_TimeParse( FBSTRING *s, int *pHour, int *pMinute, int *pSecond )
86 {
87  return fb_DateTimeParse( s,
88  NULL, NULL, NULL,
89  pHour, pMinute, pSecond,
90  FALSE, TRUE );
91 }