Skip to content

Commit

Permalink
Remove date format references
Browse files Browse the repository at this point in the history
  • Loading branch information
dospuntos committed May 26, 2024
1 parent 719176d commit 4928e3c
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 87 deletions.
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
5 changes: 2 additions & 3 deletions src/DateBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,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
40 changes: 10 additions & 30 deletions src/Locale.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include "App.h"
#include "CBLocale.h"
#include <AppFileInfo.h>
#include <Catalog.h>
#include <DateFormat.h>
Expand All @@ -11,8 +13,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "App.h"
#include "CBLocale.h"

#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "Locale"
Expand All @@ -34,11 +34,12 @@ Locale::operator!=(const Locale& other) const
bool
Locale::operator==(const Locale& other) const
{
if (fDateFormat != other.fDateFormat || fCurrencySymbol != other.fCurrencySymbol ||
fPrefixSymbol != other.fPrefixSymbol || fCurrencySeparator != other.fCurrencySeparator ||
fCurrencyDecimal != other.fCurrencyDecimal || fDateSeparator != other.fDateSeparator ||
fCurrencyDecimalPlace != other.fCurrencyDecimalPlace || fUseDST != other.fUseDST)
if (fCurrencySymbol != other.fCurrencySymbol || fPrefixSymbol != other.fPrefixSymbol
|| fCurrencySeparator != other.fCurrencySeparator
|| fCurrencyDecimal != other.fCurrencyDecimal
|| fCurrencyDecimalPlace != other.fCurrencyDecimalPlace || fUseDST != other.fUseDST) {
return false;
}
return true;
}

Expand All @@ -47,15 +48,11 @@ Locale::Flatten(BFile* file)
{
BString str("\t<Locale>\n");

if (fDateFormat == DATE_MDY)
str << "\t\t<DateFormat Value=\"mmddyyyy\" />\n";
else
str << "\t\t<DateFormat Value=\"ddmmyyyy\" />\n";
str << "\t\t<DateFormat Value=\"ddmmyyyy\" />\n";

str << "\t\t<CurrencySymbol Value=\"" << fCurrencySymbol << "\" />\n";
str << "\t\t<CurrencyDecimal Value=\"" << fCurrencyDecimal << "\" />\n";
str << "\t\t<CurrencySeparator Value=\"" << fCurrencySeparator << "\" />\n";
str << "\t\t<DateSeparator Value=\"" << fDateSeparator << "\" />\n";

if (!fPrefixSymbol)
str << "\t\t<CurrencySuffixFlag />\n";
Expand Down Expand Up @@ -165,7 +162,7 @@ Locale::DateToString(time_t date, BString& string)
status_t
Locale::StringToDate(const char* instring, time_t& date)
{
if (!instring || (fDateFormat != DATE_MDY && fDateFormat != DATE_DMY))
if (!instring)
return B_BAD_VALUE;

BDateFormat dateFormatter;
Expand Down Expand Up @@ -209,16 +206,15 @@ Locale::NumberToCurrency(const Fixed& number, BString& string)
void
Locale::SetDefaults(void)
{
fDateFormat = DATE_MDY;
fCurrencySymbol = "$";
fPrefixSymbol = true;
fCurrencySeparator = ",";
fCurrencyDecimal = ".";
fDateSeparator = "/";
fCurrencyDecimalPlace = 2;
fUseDST = false;
}


void
ShowAlert(const char* header, const char* message, alert_type type)
{
Expand Down Expand Up @@ -345,11 +341,6 @@ CapitalizeEachWord(BString& string)
string.UnlockBuffer();
}

void
Locale::SetDateFormat(const date_format& format)
{
fDateFormat = format;
}

void
Locale::SetCurrencySymbol(const char* symbol)
Expand Down Expand Up @@ -384,12 +375,6 @@ Locale::SetCurrencyDecimalPlace(const uint8& place)
fCurrencyDecimalPlace = place;
}

void
Locale::SetDateSeparator(const char* symbol)
{
if (symbol)
fDateSeparator = symbol;
}

void
Locale::SetDST(const bool& value)
Expand All @@ -405,11 +390,6 @@ GetCurrencyOnlyMask(void)
"à¡™∞ô¶•«»–≠œ∑鮆øπ‘¬å∫∂ƒ©Ωfi∆◊æäñ≈ç√ßñµ…÷";
}

const char*
GetDateOnlyMask(void)
{
return "`~!@#$%^&*()_=QWERTYUIOP{[}]|\\ASDFGHJKL;:'\"ZXCVBNM,.<>?qwertyuiopasdfghjklzxcvbnm";
}

void
IllegalCharsToEntities(BString* string)
Expand Down
14 changes: 4 additions & 10 deletions src/NetWorthReport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "TimeSupport.h"

#include <Catalog.h>
#include <FormattingConventions.h>


#undef B_TRANSLATION_CONTEXT
Expand Down Expand Up @@ -64,16 +65,9 @@ ReportWindow::ComputeNetWorth(void)
char rowtitle[128];
struct tm* timestruct = localtime(&subtotal_start);

BString formatstring;
if (gCurrentLocale.DateFormat() == DATE_MDY) {
formatstring << "%m" << gCurrentLocale.DateSeparator() << "%d"
<< gCurrentLocale.DateSeparator() << "%Y";
} else {
formatstring << "%d" << gCurrentLocale.DateSeparator() << "%m"
<< gCurrentLocale.DateSeparator() << "%Y";
}
strftime(rowtitle, 128, formatstring.String(), timestruct);
accountgrid.SetRowTitle(subtotal_index, rowtitle);
BString datestring;
gDefaultLocale.DateToString(subtotal_start, datestring);
accountgrid.SetRowTitle(subtotal_index, datestring);

int length = strlen(rowtitle);
if (length > longestnamelength) {
Expand Down
13 changes: 2 additions & 11 deletions src/PrefWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,7 @@
#define M_EDIT_OPTIONS 'edop'

// PrefView
enum {
M_DMY_FORMAT = 'dmyf',
M_MDY_FORMAT,
M_NEW_DATE_SEPARATOR,

M_NEW_CURRENCY_SYMBOL,
M_NEW_CURRENCY_SEPARATOR,
M_NEW_CURRENCY_DECIMAL,
M_TOGGLE_PREFIX
};
enum { M_NEW_CURRENCY_SYMBOL, M_NEW_CURRENCY_SEPARATOR, M_NEW_CURRENCY_DECIMAL, M_TOGGLE_PREFIX };


PrefWindow::PrefWindow(const BRect& frame)
Expand Down Expand Up @@ -102,7 +93,7 @@ CurrencyPrefView::CurrencyPrefView(const char* name, Locale* locale, const int32
fLocale = gDefaultLocale;

BBox* fCurrencyBox = new BBox("CurrencyBox");
fCurrencyBox->SetLabel(B_TRANSLATE("Default account settings:"));
fCurrencyBox->SetLabel(B_TRANSLATE("Currency"));

BString curstr;
fLocale.CurrencyToString(fSampleAmount, curstr);
Expand Down

0 comments on commit 4928e3c

Please sign in to comment.