[INTERPRETER]

* BUG: Using "AM/PM" in date format does not confuse next date to string
  conversions anymore.


git-svn-id: svn://localhost/gambas/trunk@3900 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
Benoît Minisini 2011-06-26 19:09:17 +00:00
parent b831031745
commit e7d183d12a
3 changed files with 12 additions and 14 deletions

View file

@ -146,8 +146,6 @@ DATE_SERIAL *DATE_split(VALUE *value)
nday = value->_date.date; nday = value->_date.date;
nmsec = value->_date.time; nmsec = value->_date.time;
//fprintf(stderr, "DATE_split: (%d %d)\n", nday, nmsec);
if (nday > 0) if (nday > 0)
nmsec += date_timezone * 1000; nmsec += date_timezone * 1000;

View file

@ -1207,19 +1207,20 @@ static void add_date_token(DATE_SERIAL *date, char *token, int count)
} }
bool LOCAL_format_date(DATE_SERIAL *date, int fmt_type, const char *fmt, int len_fmt, char **str, int *len_str) bool LOCAL_format_date(const DATE_SERIAL *date, int fmt_type, const char *fmt, int len_fmt, char **str, int *len_str)
{ {
DATE_SERIAL vdate;
char c; char c;
bool esc; bool esc;
int pos; int pos;
int pos_ampm = -1; int pos_ampm = -1;
struct tm date_tm; struct tm date_tm;
char real_hour = 0;
char token; char token;
int token_count; int token_count;
local_current = &LOCAL_local; local_current = &LOCAL_local;
vdate = *date;
switch(fmt_type) switch(fmt_type)
{ {
@ -1283,11 +1284,10 @@ bool LOCAL_format_date(DATE_SERIAL *date, int fmt_type, const char *fmt, int len
if (strncasecmp(&fmt[pos], "am/pm", 5) == 0) if (strncasecmp(&fmt[pos], "am/pm", 5) == 0)
{ {
pos_ampm = pos; pos_ampm = pos;
real_hour = date->hour; if (vdate.hour > 12)
if (date->hour >= 12) vdate.hour -= 12;
date->hour -= 12; else if (vdate.hour == 0)
if (date->hour == 0) vdate.hour = 12;
date->hour = 12;
break; break;
} }
} }
@ -1318,7 +1318,7 @@ bool LOCAL_format_date(DATE_SERIAL *date, int fmt_type, const char *fmt, int len
date_tm.tm_sec = date->sec; date_tm.tm_sec = date->sec;
date_tm.tm_min = date->min; date_tm.tm_min = date->min;
date_tm.tm_hour = real_hour; date_tm.tm_hour = date->hour;
date_tm.tm_mday = 1; date_tm.tm_mday = 1;
date_tm.tm_mon = 0; date_tm.tm_mon = 0;
date_tm.tm_year = 0; date_tm.tm_year = 0;
@ -1333,7 +1333,7 @@ bool LOCAL_format_date(DATE_SERIAL *date, int fmt_type, const char *fmt, int len
{ {
if (c != token) if (c != token)
{ {
add_date_token(date, &token, token_count); add_date_token(&vdate, &token, token_count);
if (token == 'h' && c == 'm') if (token == 'h' && c == 'm')
c = 'n'; c = 'n';
@ -1345,7 +1345,7 @@ bool LOCAL_format_date(DATE_SERIAL *date, int fmt_type, const char *fmt, int len
} }
else else
{ {
add_date_token(date, &token, token_count); add_date_token(&vdate, &token, token_count);
if (esc) if (esc)
put_char(c); put_char(c);
else if (c == '/') else if (c == '/')
@ -1357,7 +1357,7 @@ bool LOCAL_format_date(DATE_SERIAL *date, int fmt_type, const char *fmt, int len
} }
} }
add_date_token(date, &token, token_count); add_date_token(&vdate, &token, token_count);
/* on retourne le r<>ultat */ /* on retourne le r<>ultat */

View file

@ -108,7 +108,7 @@ EXTERN char LOCAL_first_day_of_week;
void LOCAL_init(void); void LOCAL_init(void);
void LOCAL_exit(void); void LOCAL_exit(void);
bool LOCAL_format_number(double number, int fmt_type, const char *fmt, int len_fmt, char **str, int *len_str, bool local); bool LOCAL_format_number(double number, int fmt_type, const char *fmt, int len_fmt, char **str, int *len_str, bool local);
bool LOCAL_format_date(DATE_SERIAL *date, int fmt_type, const char *fmt, int len_fmt, char **str, int *len_str); bool LOCAL_format_date(const DATE_SERIAL *date, int fmt_type, const char *fmt, int len_fmt, char **str, int *len_str);
const char *LOCAL_get_lang(void); const char *LOCAL_get_lang(void);
void LOCAL_set_lang(const char *lang); void LOCAL_set_lang(const char *lang);
const char *LOCAL_gettext(const char *msgid); const char *LOCAL_gettext(const char *msgid);