Help me please!
-
I have crap like the following scattered all over my code base!!!! I am spending more time rewriting absurd code than getting stuff done! :sigh:
Int32 YearNow = Convert.ToInt16(DateTime.Now.Year.ToString().Substring(2, 2));
Int32 MonthNow = Convert.ToInt16(DateTime.Now.Month.ToString());xacc.ide - now with IronScheme support
IronScheme - 1.0 alpha 2 out now -
I have crap like the following scattered all over my code base!!!! I am spending more time rewriting absurd code than getting stuff done! :sigh:
Int32 YearNow = Convert.ToInt16(DateTime.Now.Year.ToString().Substring(2, 2));
Int32 MonthNow = Convert.ToInt16(DateTime.Now.Month.ToString());xacc.ide - now with IronScheme support
IronScheme - 1.0 alpha 2 out nowThe month one should be a simple search/replace:
Convert.ToInt16(DateTime.Now.Month.ToString())
->DateTime.Now.Month
I'm not sure off the top of my head if there's a 2 year date or not? If not just mod100 it. As always confirm each change manually to make sure the IDE doesn't change something you don't want fooled with.Otherwise [Microsoft is] toast in the long term no matter how much money they've got. They would be already if the Linux community didn't have it's head so firmly up it's own command line buffer that it looks like taking 15 years to find the desktop. -- Matthew Faithfull
-
The month one should be a simple search/replace:
Convert.ToInt16(DateTime.Now.Month.ToString())
->DateTime.Now.Month
I'm not sure off the top of my head if there's a 2 year date or not? If not just mod100 it. As always confirm each change manually to make sure the IDE doesn't change something you don't want fooled with.Otherwise [Microsoft is] toast in the long term no matter how much money they've got. They would be already if the Linux community didn't have it's head so firmly up it's own command line buffer that it looks like taking 15 years to find the desktop. -- Matthew Faithfull
I know what the correct way of doing these :) My problem is that a lot of the code is written in the ToString() style :( This was a simple sample. I am tempted to submit some longer snippets to TheDailyWTF.
xacc.ide - now with IronScheme support
IronScheme - 1.0 alpha 2 out now -
The month one should be a simple search/replace:
Convert.ToInt16(DateTime.Now.Month.ToString())
->DateTime.Now.Month
I'm not sure off the top of my head if there's a 2 year date or not? If not just mod100 it. As always confirm each change manually to make sure the IDE doesn't change something you don't want fooled with.Otherwise [Microsoft is] toast in the long term no matter how much money they've got. They would be already if the Linux community didn't have it's head so firmly up it's own command line buffer that it looks like taking 15 years to find the desktop. -- Matthew Faithfull
Depending on how the values are used, "Omit needless local variables" may apply as well. At worst, you may need one local DateTime, but probably not a separate variable for each field. <I'mJustSayin'> This is where the C pre-processor really comes into its own;
# define YearNow (System.DateTime.Now.Year % 100)
</I'mJustSayin'> But, of course one should not use two-digit years anyway. -
Depending on how the values are used, "Omit needless local variables" may apply as well. At worst, you may need one local DateTime, but probably not a separate variable for each field. <I'mJustSayin'> This is where the C pre-processor really comes into its own;
# define YearNow (System.DateTime.Now.Year % 100)
</I'mJustSayin'> But, of course one should not use two-digit years anyway.PIEBALDconsult wrote:
This is where the C pre-processor really comes into its own; # define YearNow (System.DateTime.Now.Year % 100)
How about:
int YearNow {get { return DateTime.Now.Year % 100; }}
Dont need a macro ;P
xacc.ide - now with IronScheme support
IronScheme - 1.0 alpha 2 out now -
Depending on how the values are used, "Omit needless local variables" may apply as well. At worst, you may need one local DateTime, but probably not a separate variable for each field. <I'mJustSayin'> This is where the C pre-processor really comes into its own;
# define YearNow (System.DateTime.Now.Year % 100)
</I'mJustSayin'> But, of course one should not use two-digit years anyway.PIEBALDconsult wrote:
But, of course one should not use two-digit years anyway.
This code is a part of a 'just as bad' bigger section. It compares the expiry date of a credit card with today's date. Needless to say it uses the same style of Reductio ad absurdum[^] logic.
xacc.ide - now with IronScheme support
IronScheme - 1.0 alpha 2 out now -
PIEBALDconsult wrote:
This is where the C pre-processor really comes into its own; # define YearNow (System.DateTime.Now.Year % 100)
How about:
int YearNow {get { return DateTime.Now.Year % 100; }}
Dont need a macro ;P
xacc.ide - now with IronScheme support
IronScheme - 1.0 alpha 2 out nowD'oh! Of course, silly me.
-
PIEBALDconsult wrote:
But, of course one should not use two-digit years anyway.
This code is a part of a 'just as bad' bigger section. It compares the expiry date of a credit card with today's date. Needless to say it uses the same style of Reductio ad absurdum[^] logic.
xacc.ide - now with IronScheme support
IronScheme - 1.0 alpha 2 out nowThere was a problem I had to fix in similar code a few years ago. The credit card validation code compared the year, and if it was greater than the current year it didn't bother checking the month. Seems reasonable, right? But some of the cards we encountered had 00 for the month...
-
There was a problem I had to fix in similar code a few years ago. The credit card validation code compared the year, and if it was greater than the current year it didn't bother checking the month. Seems reasonable, right? But some of the cards we encountered had 00 for the month...
-
I have crap like the following scattered all over my code base!!!! I am spending more time rewriting absurd code than getting stuff done! :sigh:
Int32 YearNow = Convert.ToInt16(DateTime.Now.Year.ToString().Substring(2, 2));
Int32 MonthNow = Convert.ToInt16(DateTime.Now.Month.ToString());xacc.ide - now with IronScheme support
IronScheme - 1.0 alpha 2 out nowAmazing, indeed.
leppie wrote:
Int32 YearNow = Convert.ToInt16(DateTime.Now.Year.ToString().Substring(2, 2));
OK, someone doesn't know what modulo is.
leppie wrote:
Int32 MonthNow = Convert.ToInt16(DateTime.Now.Month.ToString());
Sorry, I don't get it. It's just... strange?
Greetings - Gajatko Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.
-
PIEBALDconsult wrote:
But some of the cards we encountered had 00 for the month...
Ouch! I will have to investigate (dont think we even have that option in the dropdown ;P )
xacc.ide - now with IronScheme support
IronScheme - 1.0 alpha 2 out nowThese were values from the card swipe, not entered in a GUI.
-
I have crap like the following scattered all over my code base!!!! I am spending more time rewriting absurd code than getting stuff done! :sigh:
Int32 YearNow = Convert.ToInt16(DateTime.Now.Year.ToString().Substring(2, 2));
Int32 MonthNow = Convert.ToInt16(DateTime.Now.Month.ToString());xacc.ide - now with IronScheme support
IronScheme - 1.0 alpha 2 out now -
I have crap like the following scattered all over my code base!!!! I am spending more time rewriting absurd code than getting stuff done! :sigh:
Int32 YearNow = Convert.ToInt16(DateTime.Now.Year.ToString().Substring(2, 2));
Int32 MonthNow = Convert.ToInt16(DateTime.Now.Month.ToString());xacc.ide - now with IronScheme support
IronScheme - 1.0 alpha 2 out now -
I have crap like the following scattered all over my code base!!!! I am spending more time rewriting absurd code than getting stuff done! :sigh:
Int32 YearNow = Convert.ToInt16(DateTime.Now.Year.ToString().Substring(2, 2));
Int32 MonthNow = Convert.ToInt16(DateTime.Now.Month.ToString());xacc.ide - now with IronScheme support
IronScheme - 1.0 alpha 2 out nowHere you go[^]! That can solve your problem! ;P
-
I have crap like the following scattered all over my code base!!!! I am spending more time rewriting absurd code than getting stuff done! :sigh:
Int32 YearNow = Convert.ToInt16(DateTime.Now.Year.ToString().Substring(2, 2));
Int32 MonthNow = Convert.ToInt16(DateTime.Now.Month.ToString());xacc.ide - now with IronScheme support
IronScheme - 1.0 alpha 2 out nowPeople will start worring about the end of the world again in Y2.1K :doh:
-
I have crap like the following scattered all over my code base!!!! I am spending more time rewriting absurd code than getting stuff done! :sigh:
Int32 YearNow = Convert.ToInt16(DateTime.Now.Year.ToString().Substring(2, 2));
Int32 MonthNow = Convert.ToInt16(DateTime.Now.Month.ToString());xacc.ide - now with IronScheme support
IronScheme - 1.0 alpha 2 out nowleppie wrote:
I have crap like the following scattered all over my code base!!!! I am spending more time rewriting absurd code than getting stuff done! Int32 YearNow = Convert.ToInt16(DateTime.Now.Year.ToString().Substring(2, 2));Int32 MonthNow = Convert.ToInt16(DateTime.Now.Month.ToString());
Weird. Very Weird. You're converting an Int32 to a string which becomes an Int16 and that gets promoted to an Int32? :wtf:
People using Windows XP are still living in 2001.