Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. Help me please!

Help me please!

Scheduled Pinned Locked Moved The Weird and The Wonderful
phpvisual-studiocomhelp
16 Posts 9 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    leppie
    wrote on last edited by
    #1

    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

    D L C D S 7 Replies Last reply
    0
    • L leppie

      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

      D Offline
      D Offline
      Dan Neely
      wrote on last edited by
      #2

      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

      L P 2 Replies Last reply
      0
      • D Dan Neely

        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

        L Offline
        L Offline
        leppie
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • D Dan Neely

          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

          P Offline
          P Offline
          PIEBALDconsult
          wrote on last edited by
          #4

          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.

          L 2 Replies Last reply
          0
          • P PIEBALDconsult

            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.

            L Offline
            L Offline
            leppie
            wrote on last edited by
            #5

            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

            P 1 Reply Last reply
            0
            • P PIEBALDconsult

              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.

              L Offline
              L Offline
              leppie
              wrote on last edited by
              #6

              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

              P 1 Reply Last reply
              0
              • L leppie

                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

                P Offline
                P Offline
                PIEBALDconsult
                wrote on last edited by
                #7

                D'oh! Of course, silly me.

                1 Reply Last reply
                0
                • L leppie

                  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

                  P Offline
                  P Offline
                  PIEBALDconsult
                  wrote on last edited by
                  #8

                  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...

                  L 1 Reply Last reply
                  0
                  • P PIEBALDconsult

                    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...

                    L Offline
                    L Offline
                    leppie
                    wrote on last edited by
                    #9

                    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 now

                    P 1 Reply Last reply
                    0
                    • L leppie

                      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

                      L Offline
                      L Offline
                      Lutoslaw
                      wrote on last edited by
                      #10

                      Amazing, 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.

                      1 Reply Last reply
                      0
                      • L leppie

                        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 now

                        P Offline
                        P Offline
                        PIEBALDconsult
                        wrote on last edited by
                        #11

                        These were values from the card swipe, not entered in a GUI.

                        1 Reply Last reply
                        0
                        • L leppie

                          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

                          C Offline
                          C Offline
                          Chris Maunder
                          wrote on last edited by
                          #12

                          Oh dear :D

                          cheers, Chris Maunder

                          CodeProject.com : C++ MVP

                          1 Reply Last reply
                          0
                          • L leppie

                            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

                            D Offline
                            D Offline
                            darkelv
                            wrote on last edited by
                            #13

                            leppie wrote:

                            Int32 YearNow = Convert.ToInt16(DateTime.Now.Year.ToString().Substring(2, 2));

                            Int32 YearNow = Convert.ToInt16("20" + DateTime.Now.Year.ToString().Substring(2, 2)); Fixed ;p

                            1 Reply Last reply
                            0
                            • L leppie

                              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

                              S Offline
                              S Offline
                              Super Lloyd
                              wrote on last edited by
                              #14

                              Here you go[^]! That can solve your problem! ;P

                              1 Reply Last reply
                              0
                              • L leppie

                                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

                                J Offline
                                J Offline
                                Jeremy Tierman
                                wrote on last edited by
                                #15

                                People will start worring about the end of the world again in Y2.1K :doh:

                                1 Reply Last reply
                                0
                                • L leppie

                                  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

                                  T Offline
                                  T Offline
                                  The Cake of Deceit
                                  wrote on last edited by
                                  #16

                                  leppie 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.

                                  1 Reply Last reply
                                  0
                                  Reply
                                  • Reply as topic
                                  Log in to reply
                                  • Oldest to Newest
                                  • Newest to Oldest
                                  • Most Votes


                                  • Login

                                  • Don't have an account? Register

                                  • Login or register to search.
                                  • First post
                                    Last post
                                  0
                                  • Categories
                                  • Recent
                                  • Tags
                                  • Popular
                                  • World
                                  • Users
                                  • Groups