[info]en_dmitriid


Tigers, and lions, and bears, oh my!


WTF
happy
[info]dmitriid
As I promised, this entry will contain code I submitted to The Daily WTF. Of course, my code cannot even compete with the true gems of TheDailyWTF, but here goes...

We're using Symantec WinFax Pro. Among other things it provides a set of COM objects that allow a programmer to manipulate incoming/outgoing faxes, read their status, send faxes etc. One of the main objects is the CSDKLog object. It provides to quite important (no pun or irony intended) functions:

  BSTR GetMessageDate(BSTR MessageID)
  BSTR GetMessageTime(BSTR MessageID)
 

Note that these two functions return a BSTR (for those of you who are lucky not to know this it means Yet Another C++ String Class, Com-style). Ok, it's fine by me as long as this string contains some sort of standard code. Let's say "20062306" and "231451" for "11:14:51 PM, June 23rd, 2006". Yeah right. Both return a locale-formatted string. WTF you ask? Here's TF:

Let's take the aforementioned "11:14:51 PM, June 23rd, 2006". GetMessageDate and GetMessageTime return:
  US locale:    06/23/2006    11:14:51 РМ
  RU locale:    23.06.2006    23:14:51
 
and so on

At least three computers in our office have US Locale. The rest use identical (as far as date/time display is concerned) Ru and TR locales. What will a programmer do? He will do the following::
           static bool isUSDate(char* date)
	{
		std::string df(date);

		int i = df.find('/');

		return i > 0;
	}

	static int dayFromUSDate(char* date)
	{
		std::string df(date);

		df = df.substr(df.find('/') + 1);
		df = df.substr(0, df.find('/'));

		return atoi(df.c_str());
	}

	static int monthFromUSDate(char* date)
	{
		std::string df(date);

		df = df.substr(0, df.find('/'));

		return atoi(df.c_str());
	}

	static int yearFromUSDate(char* date)
	{
		std::string df(date);

		df = df.substr(df.find('/') + 1);
		df = df.substr(df.find('/') + 1);

		return atoi(df.c_str());
	}

	static int dayFromEuDate(char* date)
	{
		std::string df(date);

		df = df.substr(0, df.find('.'));

		return atoi(df.c_str());
	}
	static int monthFromEuDate(char* date)
	{
		std::string df(date);

		df = df.substr(df.find('.') + 1);
		df = df.substr(0, df.find('.'));

		return atoi(df.c_str());
	}
	static int yearFromEuDate(char* date)
	{
		std::string df(date);

		df = df.substr(df.find('.') + 1);
		df = df.substr(df.find('.') + 1);

		return atoi(df.c_str());
	}

	static int hourFromTime(char* date)
	{
		std::string df(date);

		df = df.substr(0, df.find(':'));

		return atoi(df.c_str());
	}

	static int minuteFromTime(char* date)
	{
		std::string df(date);

		df = df.substr(df.find(':') + 1);
		df = df.substr(0, df.find(':'));

		return atoi(df.c_str());
	}
	static int secondFromTime(char* date)
	{
		std::string df(date);

		df = df.substr(df.find(':') + 1);
		df = df.substr(df.find(':') + 1);

		df = df.substr(0, df.find(' ')); /* Brit/US AM/PM */
		df = df.substr(0, df.find('P'));
		df = df.substr(0, df.find('A'));

		return atoi(df.c_str());
	}
 


:))))))))))) What else could I do? I had deadlines, man....

Tags: , ,

Home