FreeBASIC  0.91.0
drv_intl_gettimeformat.c
Go to the documentation of this file.
1 /* get localized short TIME format */
2 
3 #include "../fb.h"
4 #include "fb_private_intl.h"
5 
6 int fb_DrvIntlGetTimeFormat( char *buffer, size_t len )
7 {
8  char achFormat[90], *pszFormat;
9  char achHourZero[8], *pszHourZero;
10  char achTimeMark[8], *pszTimeMark;
11  char achTimeMarkPos[8], *pszTimeMarkPos;
12  int use_timemark, timemark_prefix;
13  size_t i;
14 
15  DBG_ASSERT(buffer!=NULL);
16 
17  /* Can I use this? The problem is that it returns the date format
18  * with localized separators. */
19  pszFormat = fb_hGetLocaleInfo( LOCALE_USER_DEFAULT, LOCALE_STIMEFORMAT,
20  achFormat, sizeof(achFormat) - 1 );
21  if( pszFormat!=NULL ) {
22  size_t uiNameSize = strlen(pszFormat);
23  if( uiNameSize < len ) {
24  strcpy( buffer, pszFormat );
25  return TRUE;
26  } else {
27  return FALSE;
28  }
29  }
30 
31 
32  /* Fall back for Win95 and WinNT < 4.0 */
33  pszTimeMarkPos = fb_hGetLocaleInfo( LOCALE_USER_DEFAULT, LOCALE_ITIMEMARKPOSN,
34  achTimeMarkPos, sizeof(achTimeMarkPos) );
35  pszTimeMark = fb_hGetLocaleInfo( LOCALE_USER_DEFAULT, LOCALE_ITIME,
36  achTimeMark, sizeof(achTimeMark) );
37  pszHourZero = fb_hGetLocaleInfo( LOCALE_USER_DEFAULT, LOCALE_ITLZERO,
38  achHourZero, sizeof(achHourZero) );
39 
40  i = 0;
41 
42  use_timemark = ( pszTimeMark!=NULL && atoi( pszTimeMark )==1 );
43  timemark_prefix = ( pszTimeMarkPos!=NULL && atoi( pszTimeMarkPos )==1 );
44 
45  if( use_timemark && timemark_prefix ) {
46  strcpy( achFormat + i, "AM/PM " );
47  i += 6;
48  }
49 
50  if( pszHourZero!=NULL && atoi( pszHourZero )==1 ) {
51  if( !use_timemark ) {
52  strcpy( achFormat + i, "HH:" );
53  } else {
54  strcpy( achFormat + i, "hh:" );
55  }
56  i += 3;
57  }
58  strcpy( achFormat + i, "mm:ss" );
59  i += 5;
60 
61  if( use_timemark && !timemark_prefix ) {
62  strcpy( achFormat + i, " AM/PM" );
63  i += 6;
64  }
65 
66  if( len < (i+1) )
67  return FALSE;
68 
69  FB_MEMCPY(buffer, achFormat, i);
70  buffer[i] = 0;
71 
72  return TRUE;
73 }