Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use system date format #63

Merged
merged 2 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions src/CBLocale.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ class Locale {
status_t StringToDate(const char* instring, time_t& date);
void NumberToCurrency(const Fixed& number, BString& string);

void SetDateFormat(const date_format& format);

date_format DateFormat(void) const { return fDateFormat; }

void SetCurrencySymbol(const char* symbol);

const char* CurrencySymbol(void) const { return fCurrencySymbol.String(); }
Expand All @@ -54,10 +50,6 @@ class Locale {

uint8 CurrencyDecimalPlace(void) const { return fCurrencyDecimalPlace; }

void SetDateSeparator(const char* symbol);

const char* DateSeparator(void) const { return fDateSeparator.String(); }

void SetDST(const bool& value);

bool UseDST(void) const { return fUseDST; }
Expand All @@ -69,14 +61,10 @@ class Locale {
status_t ConstructDateStringMDY(const char* in, BString& out);
status_t ConstructDateStringDMY(const char* in, BString& out);

// Like BeFinancial, we just use two different date formats: mmddyyyy (0) and
// ddmmyyyy (1)
date_format fDateFormat;
BString fCurrencySymbol;
bool fPrefixSymbol;
BString fCurrencySeparator;
BString fCurrencyDecimal;
BString fDateSeparator;
uint8 fCurrencyDecimalPlace;
bool fUseDST;
};
Expand All @@ -86,7 +74,6 @@ void ShowBug(const char* string);
void GetVersionString(BString& string);
void CapitalizeEachWord(BString& string);
const char* GetCurrencyOnlyMask(void);
const char* GetDateOnlyMask(void);
void IllegalCharsToEntities(BString* string);

#endif
28 changes: 8 additions & 20 deletions src/Database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,11 +558,11 @@ Database::SetAccountLocale(const uint32& accountid, const Locale& data)
command << accountid << ";";
CppSQLite3Query query = DBQuery(command.String(), "Database::SetAccountLocale:find accountid");

// Todo: remove table columns for date format
if (query.eof()) {
command << "insert into accountlocale values(" << accountid << ",'"
<< (data.DateFormat() == DATE_DMY ? "ddmmyyyy" : "mmddyyyy") << "','"
<< data.DateSeparator() << "','" << data.CurrencySymbol() << "','"
<< data.CurrencySeparator() << "','" << data.CurrencyDecimal() << "','"
command << "insert into accountlocale values(" << accountid << ",'ddmmyyyy','/','"
<< data.CurrencySymbol() << "','" << data.CurrencySeparator() << "','"
<< data.CurrencyDecimal() << "','"
<< (data.IsCurrencySymbolPrefix() ? "true" : "false") << "');";
DBCommand(command.String(), "Database::SetAccountLocale:insert into accountlocale");
UNLOCK;
Expand All @@ -572,13 +572,12 @@ Database::SetAccountLocale(const uint32& accountid, const Locale& data)
query.finalize();

// This already has the locale data in the table, so we'll just update it and return
command << "update accountlocale set dateformat = '"
<< (data.DateFormat() == 1 ? "ddmmyyyy" : "mmddyyyy")
<< "' where accountid = " << accountid << ";";
command << "update accountlocale set dateformat = 'ddmmyyyy' where accountid = " << accountid
<< ";";
DBCommand(command.String(), "Database::SetAccountLocale:update dateformat");

command << "update accountlocale set dateseparator = '" << data.DateSeparator()
<< "' where accountid = " << accountid << ";";
command << "update accountlocale set dateseparator = '/' where accountid = " << accountid
<< ";";
DBCommand(command.String(), "Database::SetAccountLocale:update dateseparator");

command << "update accountlocale set currencysymbol = '" << data.CurrencySymbol()
Expand Down Expand Up @@ -615,8 +614,6 @@ Database::LocaleForAccount(const uint32& id)
}

BString temp = query.getStringField(1);
locale.SetDateFormat((temp.Compare("ddmmyyyy") == 0) ? DATE_DMY : DATE_MDY);
locale.SetDateSeparator(query.getStringField(2));
locale.SetCurrencySymbol(query.getStringField(3));
locale.SetCurrencySeparator(query.getStringField(4));
locale.SetCurrencyDecimal(query.getStringField(5));
Expand All @@ -633,13 +630,6 @@ Database::SetDefaultLocale(const Locale& data)
BString command;

// This already has the locale data in the table, so we'll just update it and return
command << "update defaultlocale set dateformat = '"
<< (data.DateFormat() == DATE_MDY ? "mmddyyyy" : "ddmmyyyy") << "';";
DBCommand(command.String(), "Database::SetAccountLocale:update dateformat");

command << "update defaultlocale set dateseparator = '" << data.DateSeparator() << "';";
DBCommand(command.String(), "Database::SetAccountLocale:update dateseparator");

command << "update defaultlocale set currencysymbol = '" << data.CurrencySymbol() << "';";
DBCommand(command.String(), "Database::SetAccountLocale:update currencysymbol");

Expand Down Expand Up @@ -672,8 +662,6 @@ Database::GetDefaultLocale(void)
}

BString temp = query.getStringField(0);
locale.SetDateFormat((temp.Compare("ddmmyyyy") == 0) ? DATE_DMY : DATE_MDY);
locale.SetDateSeparator(query.getStringField(1));
locale.SetCurrencySymbol(query.getStringField(2));
locale.SetCurrencySeparator(query.getStringField(3));
locale.SetCurrencyDecimal(query.getStringField(4));
Expand Down
13 changes: 2 additions & 11 deletions src/DateBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,6 @@ DateBoxFilter::KeyFilter(const int32& key, const int32& mod)
box->TextView()->SelectAll();
TextControl()->Invoke();
return B_SKIP_MESSAGE;
} else if (keystring == "-") {
if (strlen(box->Text()) > 0)
box->fCurrentDate = DecrementDateByDay(box->fCurrentDate);
gDefaultLocale.DateToString(box->fCurrentDate, string);
box->SetText(string.String());
box->TextView()->SelectAll();
TextControl()->Invoke();
return B_SKIP_MESSAGE;
} else if (key == B_PAGE_UP) {
if (strlen(box->Text()) > 0) {
if (mod & B_SHIFT_KEY)
Expand Down Expand Up @@ -106,9 +98,8 @@ DateBox::DateBox(const char* name, const char* label, const char* text, BMessage
SetFilter(new DateBoxFilter(this));
fCurrentDate = GetCurrentDate();

const char date_disallowed[] =
"`~!@#$%^&*()_=QWERTYUIOP{[}]|\\ASDFGHJKL;:'\""
"ZXCVBNM,.<>?qwertyuiopasdfghjklzxcvbnm";
const char date_disallowed[] = "`~!@#$%^&*()_=QWERTYUIOP{[}]|\\ASDFGHJKL;:'\""
"ZXCVBNM,<>?qwertyuiopasdfghjklzxcvbnm";
int32 i = 0;
while (date_disallowed[i]) {
TextView()->DisallowChar(date_disallowed[i]);
Expand Down
Loading
Loading