...
 
Commits (1)
  • Rob Swindell's avatar
    People don't like YYYY/MM/DD for entering birthdates · 9e6f9042
    Rob Swindell authored
    Can't say I don't blame them, it is a little unnatural. So instead, use either MM/DD/YYYY (the default) or DD/MM/YYYY (European date mode). This required the use of a new @-code: BDATEFMT and the update of a couple of text.dat lines (in next commit).
    9e6f9042
......@@ -577,6 +577,10 @@ const char* sbbs_t::atcode(char* sp, char* str, size_t maxlen, long* pmode, bool
return cfg.sys_misc&SM_EURODATE ? "DD/MM/YY" : "MM/DD/YY";
}
if(strcmp(sp, "BDATEFMT") == 0) {
return birthdate_format(&cfg);
}
if(!strcmp(sp,"TMSG")) {
l=0;
for(i=0;i<cfg.total_subs;i++)
......
......@@ -315,20 +315,16 @@ BOOL sbbs_t::newuser()
bputs(text[EnterYourSex]);
useron.sex=(char)getkeys("MF",0);
}
str[0] = 0;
while((cfg.uq&UQ_BIRTH) && online && text[EnterYourBirthday][0]) {
bprintf(text[EnterYourBirthday], "YYYY/MM/DD");
if(gettmplt(str, "nnnn/nn/nn", K_EDIT) < 10)
bprintf(text[EnterYourBirthday], birthdate_format(&cfg));
format_birthdate(&cfg, useron.birth, str, sizeof(str));
if(gettmplt(str, "nn/nn/nnnn", K_EDIT) < 10)
continue;
int age = getage(&cfg, str);
if(age >= 0 && age <= 200) {
SAFEPRINTF3(useron.birth, "%.4s%.2s%.2s", str, str + 5, str + 8);
int age = getage(&cfg, parse_birthdate(&cfg, str, tmp, sizeof(tmp)));
if(age >= 0 && age <= 200) { // TODO: Configurable min/max user age
SAFECOPY(useron.birth, tmp);
break;
}
SAFEPRINTF3(str, "%04u/%02u/%02u"
,getbirthyear(useron.birth)
,getbirthmonth(&cfg, useron.birth)
,getbirthday(&cfg, useron.birth));
}
if(!online) return(FALSE);
while(!(cfg.uq&UQ_NONETMAIL) && online && text[EnterNetMailAddress][0]) {
......
......@@ -834,6 +834,42 @@ int getage(scfg_t* cfg, const char *birth)
return age;
}
/****************************************************************************/
/* Converts from either MM/DD/YYYYY or DD/MM/YYYY to YYYYMMDD */
/****************************************************************************/
char* parse_birthdate(scfg_t* cfg, const char* birthdate, char* out, size_t maxlen)
{
if(cfg->sys_misc & SM_EURODATE)
safe_snprintf(out, maxlen, "%.4s%.2s%.2s", birthdate + 6, birthdate + 3, birthdate);
else
safe_snprintf(out, maxlen, "%.4s%.2s%.2s", birthdate + 6, birthdate, birthdate + 3);
return out;
}
/****************************************************************************/
/* Converts from user birth date to either MM/DD/YYYYY or DD/MM/YYYY */
/****************************************************************************/
char* format_birthdate(scfg_t* cfg, const char* birthdate, char* out, size_t maxlen)
{
if(maxlen < 1)
return NULL;
*out = '\0';
if(*birthdate) {
if(cfg->sys_misc & SM_EURODATE)
safe_snprintf(out, maxlen, "%02u/%02u/%04u"
,getbirthday(cfg, birthdate), getbirthmonth(cfg, birthdate), getbirthyear(birthdate));
else
safe_snprintf(out, maxlen, "%02u/%02u/%04u"
,getbirthmonth(cfg, birthdate), getbirthday(cfg, birthdate), getbirthyear(birthdate));
}
return out;
}
const char* birthdate_format(scfg_t* cfg)
{
return cfg->sys_misc&SM_EURODATE ? "DD/MM/YYYY" : "MM/DD/YYYY";
}
/****************************************************************************/
/****************************************************************************/
int opennodedat(scfg_t* cfg)
......
......@@ -87,6 +87,9 @@ DLLEXPORT int getbirthyear(const char* birthdate);
DLLEXPORT char* getbirthdstr(scfg_t*, const char* birthdate, char* buf, size_t);
DLLEXPORT char* getbirthmmddyy(scfg_t*, const char* birthdate, char* buf, size_t);
DLLEXPORT char* getbirthddmmyy(scfg_t*, const char* birthdate, char* buf, size_t);
DLLEXPORT char* parse_birthdate(scfg_t*, const char* birthdate, char* out, size_t);
DLLEXPORT char* format_birthdate(scfg_t*, const char* birthdate, char* out, size_t);
DLLEXPORT const char* birthdate_format(scfg_t*);
DLLEXPORT char* username(scfg_t*, int usernumber, char * str);
DLLEXPORT char* usermailaddr(scfg_t*, char* addr, const char* name);
DLLEXPORT int opennodedat(scfg_t*);
......
......@@ -101,8 +101,8 @@ void sbbs_t::useredit(int usernumber)
,user.level>useron.level && console&CON_R_ECHO
? "XXX-XXX-XXXX" : user.phone);
bprintf(text[UeditAddressBirthday]
,user.address,getage(&cfg,user.birth),user.sex,user.birth
,getbirthyear(user.birth), getbirthmonth(&cfg, user.birth), getbirthday(&cfg, user.birth));
,user.address,getage(&cfg,user.birth),user.sex
,format_birthdate(&cfg, user.birth, tmp, sizeof(tmp)));
bprintf(text[UeditLocationZipcode],user.location,user.zipcode);
bprintf(text[UeditNoteHandle],user.note,user.handle);
bprintf(text[UeditComputerModem],user.comp,user.modem);
......@@ -187,10 +187,10 @@ void sbbs_t::useredit(int usernumber)
putuserrec(&cfg,user.number,U_HANDLE,LEN_HANDLE,user.handle);
break;
case 'B':
bprintf(text[EnterYourBirthday], "YYYY/MM/DD");
SAFEPRINTF3(str, "%04u/%02u/%02u", getbirthyear(user.birth), getbirthmonth(&cfg, user.birth), getbirthday(&cfg, user.birth));
if(gettmplt(str, "nnnn/nn/nn", kmode) == 10) {
SAFEPRINTF3(user.birth, "%.4s%.2s%.2s", str, str + 5, str + 8);
bprintf(text[EnterYourBirthday], birthdate_format(&cfg));
format_birthdate(&cfg, user.birth, str, sizeof(str));
if(gettmplt(str, "nn/nn/nnnn", kmode) == 10) {
parse_birthdate(&cfg, str, user.birth, sizeof(user.birth));
putuserrec(&cfg,user.number,U_BIRTH,LEN_BIRTH,user.birth);
}
break;
......