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. Gem... As time goes by..

Gem... As time goes by..

Scheduled Pinned Locked Moved The Weird and The Wonderful
ruby
35 Posts 22 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.
  • V Offline
    V Offline
    virang_21
    wrote on last edited by
    #1

    private string GetTime(string strShiftCode, string strTime)
    {
    string strReturn = "";

                switch (strTime)
                {
                    case "01":
                        strReturn = "AM";
                        break;
                    case "02":
                        strReturn = "AM";
                        break;
                    case "03":
                        strReturn = "AM";
                        break;
                    case "04":
                        strReturn = "AM";
                        break;
                    case "05":
                        strReturn = "AM";
                        break;
                    case "06":
                        strReturn = "AM";
                        break;
                    case "07":
                        strReturn = "AM";
                        break;
                    case "08":
                        strReturn = "AM";
                        break;
                    case "09":
                        strReturn = "AM";
                        break;
                    case "10":
                        strReturn = "AM";
                        break;
                    case "11":
                        strReturn = "AM";
                        break;
                    case "12":
                        strReturn = "PM";
                        break;
                    case "13":
                        strReturn = "PM";
                        break;
                    case "14":
                        strReturn = "PM";
                        break;
                    case "15":
                        strReturn = "PM";
                        break;
                    case "16":
                        strReturn = "PM";
                        break;
                    case "17":
                        strReturn = "PM";
                        break;
                    case "18":
                        strReturn = "PM";
                        break;
                    case "19":
                        strReturn = "PM
    
    L E R B 0 11 Replies Last reply
    0
    • V virang_21

      private string GetTime(string strShiftCode, string strTime)
      {
      string strReturn = "";

                  switch (strTime)
                  {
                      case "01":
                          strReturn = "AM";
                          break;
                      case "02":
                          strReturn = "AM";
                          break;
                      case "03":
                          strReturn = "AM";
                          break;
                      case "04":
                          strReturn = "AM";
                          break;
                      case "05":
                          strReturn = "AM";
                          break;
                      case "06":
                          strReturn = "AM";
                          break;
                      case "07":
                          strReturn = "AM";
                          break;
                      case "08":
                          strReturn = "AM";
                          break;
                      case "09":
                          strReturn = "AM";
                          break;
                      case "10":
                          strReturn = "AM";
                          break;
                      case "11":
                          strReturn = "AM";
                          break;
                      case "12":
                          strReturn = "PM";
                          break;
                      case "13":
                          strReturn = "PM";
                          break;
                      case "14":
                          strReturn = "PM";
                          break;
                      case "15":
                          strReturn = "PM";
                          break;
                      case "16":
                          strReturn = "PM";
                          break;
                      case "17":
                          strReturn = "PM";
                          break;
                      case "18":
                          strReturn = "PM";
                          break;
                      case "19":
                          strReturn = "PM
      
      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      In any case I would also look at all places where the function is called. There this unused parameter must be passed. It's better when you find out what this 'ShiftCode' may have been intended for.

      And from the clouds a mighty voice spoke:
      "Smile and be happy, for it could come worse!"

      And I smiled and was happy
      And it came worse.

      1 Reply Last reply
      0
      • V virang_21

        private string GetTime(string strShiftCode, string strTime)
        {
        string strReturn = "";

                    switch (strTime)
                    {
                        case "01":
                            strReturn = "AM";
                            break;
                        case "02":
                            strReturn = "AM";
                            break;
                        case "03":
                            strReturn = "AM";
                            break;
                        case "04":
                            strReturn = "AM";
                            break;
                        case "05":
                            strReturn = "AM";
                            break;
                        case "06":
                            strReturn = "AM";
                            break;
                        case "07":
                            strReturn = "AM";
                            break;
                        case "08":
                            strReturn = "AM";
                            break;
                        case "09":
                            strReturn = "AM";
                            break;
                        case "10":
                            strReturn = "AM";
                            break;
                        case "11":
                            strReturn = "AM";
                            break;
                        case "12":
                            strReturn = "PM";
                            break;
                        case "13":
                            strReturn = "PM";
                            break;
                        case "14":
                            strReturn = "PM";
                            break;
                        case "15":
                            strReturn = "PM";
                            break;
                        case "16":
                            strReturn = "PM";
                            break;
                        case "17":
                            strReturn = "PM";
                            break;
                        case "18":
                            strReturn = "PM";
                            break;
                        case "19":
                            strReturn = "PM
        
        E Offline
        E Offline
        Estys
        wrote on last edited by
        #3

        It's also wrong : "24" is "AM" :) Cheers

        If you can read this, you don't have Papyrus installed

        L R P K 4 Replies Last reply
        0
        • E Estys

          It's also wrong : "24" is "AM" :) Cheers

          If you can read this, you don't have Papyrus installed

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          And that again may also be wrong. Are the hours not enumerated 0 - 23, totally VB unfriendly?

          And from the clouds a mighty voice spoke:
          "Smile and be happy, for it could come worse!"

          And I smiled and was happy
          And it came worse.

          V E 2 Replies Last reply
          0
          • L Lost User

            And that again may also be wrong. Are the hours not enumerated 0 - 23, totally VB unfriendly?

            And from the clouds a mighty voice spoke:
            "Smile and be happy, for it could come worse!"

            And I smiled and was happy
            And it came worse.

            V Offline
            V Offline
            virang_21
            wrote on last edited by
            #5

            The application is used to monitor Robots in factory so may be hour 24 is AM for them... I don't speak Robolang yet ... :) :laugh:

            Zen and the art of software maintenance : rm -rf * Math is like love : a simple idea but it can get complicated.

            1 Reply Last reply
            0
            • L Lost User

              And that again may also be wrong. Are the hours not enumerated 0 - 23, totally VB unfriendly?

              And from the clouds a mighty voice spoke:
              "Smile and be happy, for it could come worse!"

              And I smiled and was happy
              And it came worse.

              E Offline
              E Offline
              Estys
              wrote on last edited by
              #6

              Yes, you and I (and probalby most people) would calculate that way. In the past I have once or twice seen the time expressed as 24:xx. Anyhoo, if you inspect the code you will see 11 AM's and 13 PM's. Cheers

              If you can read this, you don't have Papyrus installed

              L 1 Reply Last reply
              0
              • E Estys

                Yes, you and I (and probalby most people) would calculate that way. In the past I have once or twice seen the time expressed as 24:xx. Anyhoo, if you inspect the code you will see 11 AM's and 13 PM's. Cheers

                If you can read this, you don't have Papyrus installed

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                Time and dates can be hell, even if you have a decent framework at your disposal. If you do such things on the fly: Good luck.

                And from the clouds a mighty voice spoke:
                "Smile and be happy, for it could come worse!"

                And I smiled and was happy
                And it came worse.

                1 Reply Last reply
                0
                • V virang_21

                  private string GetTime(string strShiftCode, string strTime)
                  {
                  string strReturn = "";

                              switch (strTime)
                              {
                                  case "01":
                                      strReturn = "AM";
                                      break;
                                  case "02":
                                      strReturn = "AM";
                                      break;
                                  case "03":
                                      strReturn = "AM";
                                      break;
                                  case "04":
                                      strReturn = "AM";
                                      break;
                                  case "05":
                                      strReturn = "AM";
                                      break;
                                  case "06":
                                      strReturn = "AM";
                                      break;
                                  case "07":
                                      strReturn = "AM";
                                      break;
                                  case "08":
                                      strReturn = "AM";
                                      break;
                                  case "09":
                                      strReturn = "AM";
                                      break;
                                  case "10":
                                      strReturn = "AM";
                                      break;
                                  case "11":
                                      strReturn = "AM";
                                      break;
                                  case "12":
                                      strReturn = "PM";
                                      break;
                                  case "13":
                                      strReturn = "PM";
                                      break;
                                  case "14":
                                      strReturn = "PM";
                                      break;
                                  case "15":
                                      strReturn = "PM";
                                      break;
                                  case "16":
                                      strReturn = "PM";
                                      break;
                                  case "17":
                                      strReturn = "PM";
                                      break;
                                  case "18":
                                      strReturn = "PM";
                                      break;
                                  case "19":
                                      strReturn = "PM
                  
                  R Offline
                  R Offline
                  Robert Rohde
                  wrote on last edited by
                  #8

                  I agree that the original implementation is bad but beware that your fix could introduce some new issues. For example passing "2" will result in a different result than before ("AM" vs ""). This might even be Ok but passing "test" will generate an exception where the old implementation would just have returned an empty string. Robert

                  V 1 Reply Last reply
                  0
                  • R Robert Rohde

                    I agree that the original implementation is bad but beware that your fix could introduce some new issues. For example passing "2" will result in a different result than before ("AM" vs ""). This might even be Ok but passing "test" will generate an exception where the old implementation would just have returned an empty string. Robert

                    V Offline
                    V Offline
                    virang_21
                    wrote on last edited by
                    #9

                    I am not changing the existing app at the moment .. my job is to add fixes to the app if it fails but it is working OK since last 2 years and used as production app in factory to control robots...One of the developer responsible for its maintenance is leaving so all his projects are coming to me...Just for this app my approach is going to be " Hey Why change it if it is working " ... and there are at least 5 developers worked on it at different times with their own way of coding like the Gem I found... :(

                    Zen and the art of software maintenance : rm -rf * Math is like love : a simple idea but it can get complicated.

                    1 Reply Last reply
                    0
                    • V virang_21

                      private string GetTime(string strShiftCode, string strTime)
                      {
                      string strReturn = "";

                                  switch (strTime)
                                  {
                                      case "01":
                                          strReturn = "AM";
                                          break;
                                      case "02":
                                          strReturn = "AM";
                                          break;
                                      case "03":
                                          strReturn = "AM";
                                          break;
                                      case "04":
                                          strReturn = "AM";
                                          break;
                                      case "05":
                                          strReturn = "AM";
                                          break;
                                      case "06":
                                          strReturn = "AM";
                                          break;
                                      case "07":
                                          strReturn = "AM";
                                          break;
                                      case "08":
                                          strReturn = "AM";
                                          break;
                                      case "09":
                                          strReturn = "AM";
                                          break;
                                      case "10":
                                          strReturn = "AM";
                                          break;
                                      case "11":
                                          strReturn = "AM";
                                          break;
                                      case "12":
                                          strReturn = "PM";
                                          break;
                                      case "13":
                                          strReturn = "PM";
                                          break;
                                      case "14":
                                          strReturn = "PM";
                                          break;
                                      case "15":
                                          strReturn = "PM";
                                          break;
                                      case "16":
                                          strReturn = "PM";
                                          break;
                                      case "17":
                                          strReturn = "PM";
                                          break;
                                      case "18":
                                          strReturn = "PM";
                                          break;
                                      case "19":
                                          strReturn = "PM
                      
                      B Offline
                      B Offline
                      BobJanova
                      wrote on last edited by
                      #10

                      That is quite spectacularly bad. - Unused parameter - Misnamed function (it is getting the hour part suffix, not Time) - Using strings to manage date/time info, and relying on the exact string (i.e. 2 != 02) - Incorrect coding or non-standard representation (01-24 instead of 00-23) - Duplicating framework functionality (myDateTime.ToString("hh tt")) - Repeat code in case blocks instead of a single test for all included conditions Anyone spot any more?

                      I S L 3 Replies Last reply
                      0
                      • B BobJanova

                        That is quite spectacularly bad. - Unused parameter - Misnamed function (it is getting the hour part suffix, not Time) - Using strings to manage date/time info, and relying on the exact string (i.e. 2 != 02) - Incorrect coding or non-standard representation (01-24 instead of 00-23) - Duplicating framework functionality (myDateTime.ToString("hh tt")) - Repeat code in case blocks instead of a single test for all included conditions Anyone spot any more?

                        I Offline
                        I Offline
                        ii_noname_ii
                        wrote on last edited by
                        #11

                        I laughed out loud when I saw this one... Possibly the funniest function I've seen in the hall of shame.

                        1 Reply Last reply
                        0
                        • E Estys

                          It's also wrong : "24" is "AM" :) Cheers

                          If you can read this, you don't have Papyrus installed

                          R Offline
                          R Offline
                          Rajesh Anuhya
                          wrote on last edited by
                          #12

                          You never get "24" it's "00"

                          my Tip/Tricks[^] | "Rajesh-Puli" now "Rajesh-Anuhya"

                          E 1 Reply Last reply
                          0
                          • R Rajesh Anuhya

                            You never get "24" it's "00"

                            my Tip/Tricks[^] | "Rajesh-Puli" now "Rajesh-Anuhya"

                            E Offline
                            E Offline
                            Estys
                            wrote on last edited by
                            #13

                            That depends entirely on the input, we're not dealing with a real time format here. As said by others here, thse method is wrong in many respects. My comment denoted that there are 11 "AM" entries and 13 "PM" entries. So if "24" is input, the output should logically be "AM", not "PM". Cheers

                            If you can read this, you don't have Papyrus installed

                            1 Reply Last reply
                            0
                            • V virang_21

                              private string GetTime(string strShiftCode, string strTime)
                              {
                              string strReturn = "";

                                          switch (strTime)
                                          {
                                              case "01":
                                                  strReturn = "AM";
                                                  break;
                                              case "02":
                                                  strReturn = "AM";
                                                  break;
                                              case "03":
                                                  strReturn = "AM";
                                                  break;
                                              case "04":
                                                  strReturn = "AM";
                                                  break;
                                              case "05":
                                                  strReturn = "AM";
                                                  break;
                                              case "06":
                                                  strReturn = "AM";
                                                  break;
                                              case "07":
                                                  strReturn = "AM";
                                                  break;
                                              case "08":
                                                  strReturn = "AM";
                                                  break;
                                              case "09":
                                                  strReturn = "AM";
                                                  break;
                                              case "10":
                                                  strReturn = "AM";
                                                  break;
                                              case "11":
                                                  strReturn = "AM";
                                                  break;
                                              case "12":
                                                  strReturn = "PM";
                                                  break;
                                              case "13":
                                                  strReturn = "PM";
                                                  break;
                                              case "14":
                                                  strReturn = "PM";
                                                  break;
                                              case "15":
                                                  strReturn = "PM";
                                                  break;
                                              case "16":
                                                  strReturn = "PM";
                                                  break;
                                              case "17":
                                                  strReturn = "PM";
                                                  break;
                                              case "18":
                                                  strReturn = "PM";
                                                  break;
                                              case "19":
                                                  strReturn = "PM
                              
                              0 Offline
                              0 Offline
                              0bx
                              wrote on last edited by
                              #14

                              This is why you should never work past 24.01h.

                              Giraffes are not real.

                              1 Reply Last reply
                              0
                              • E Estys

                                It's also wrong : "24" is "AM" :) Cheers

                                If you can read this, you don't have Papyrus installed

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

                                ISO 8601 allows 24:00 as the end of the day, so it would be PM; AM starts at 00:00 (not that ISO 8601 recognizes AM/PM of course).

                                B S 2 Replies Last reply
                                0
                                • V virang_21

                                  private string GetTime(string strShiftCode, string strTime)
                                  {
                                  string strReturn = "";

                                              switch (strTime)
                                              {
                                                  case "01":
                                                      strReturn = "AM";
                                                      break;
                                                  case "02":
                                                      strReturn = "AM";
                                                      break;
                                                  case "03":
                                                      strReturn = "AM";
                                                      break;
                                                  case "04":
                                                      strReturn = "AM";
                                                      break;
                                                  case "05":
                                                      strReturn = "AM";
                                                      break;
                                                  case "06":
                                                      strReturn = "AM";
                                                      break;
                                                  case "07":
                                                      strReturn = "AM";
                                                      break;
                                                  case "08":
                                                      strReturn = "AM";
                                                      break;
                                                  case "09":
                                                      strReturn = "AM";
                                                      break;
                                                  case "10":
                                                      strReturn = "AM";
                                                      break;
                                                  case "11":
                                                      strReturn = "AM";
                                                      break;
                                                  case "12":
                                                      strReturn = "PM";
                                                      break;
                                                  case "13":
                                                      strReturn = "PM";
                                                      break;
                                                  case "14":
                                                      strReturn = "PM";
                                                      break;
                                                  case "15":
                                                      strReturn = "PM";
                                                      break;
                                                  case "16":
                                                      strReturn = "PM";
                                                      break;
                                                  case "17":
                                                      strReturn = "PM";
                                                      break;
                                                  case "18":
                                                      strReturn = "PM";
                                                      break;
                                                  case "19":
                                                      strReturn = "PM
                                  
                                  E Offline
                                  E Offline
                                  edmurphy99
                                  wrote on last edited by
                                  #16

                                  maybe the programmer was paid by the line

                                  1 Reply Last reply
                                  0
                                  • B BobJanova

                                    That is quite spectacularly bad. - Unused parameter - Misnamed function (it is getting the hour part suffix, not Time) - Using strings to manage date/time info, and relying on the exact string (i.e. 2 != 02) - Incorrect coding or non-standard representation (01-24 instead of 00-23) - Duplicating framework functionality (myDateTime.ToString("hh tt")) - Repeat code in case blocks instead of a single test for all included conditions Anyone spot any more?

                                    S Offline
                                    S Offline
                                    Stefan_Lang
                                    wrote on last edited by
                                    #17

                                    Some more: - no test to verify input value range or format (this would be neglectable if using correct types as you've already implied with your point 'Using strings') - using switch without default case - using hard coded strings for "AM" and "PM" - combining a yes/no test with an unrelated display functionality into one function (note that a test for AM and PM implies that a 24h format is being converted to a 12h format, and thus the test needs to be repeated in order to convert the number part!)

                                    1 Reply Last reply
                                    0
                                    • P PIEBALDconsult

                                      ISO 8601 allows 24:00 as the end of the day, so it would be PM; AM starts at 00:00 (not that ISO 8601 recognizes AM/PM of course).

                                      B Offline
                                      B Offline
                                      Brady Kelly
                                      wrote on last edited by
                                      #18

                                      Do 24:00 and 00:00 occur at the same time then, just different notations?

                                      P 1 Reply Last reply
                                      0
                                      • B Brady Kelly

                                        Do 24:00 and 00:00 occur at the same time then, just different notations?

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

                                        Yes, different notations for the same timepoint.

                                        L 1 Reply Last reply
                                        0
                                        • V virang_21

                                          private string GetTime(string strShiftCode, string strTime)
                                          {
                                          string strReturn = "";

                                                      switch (strTime)
                                                      {
                                                          case "01":
                                                              strReturn = "AM";
                                                              break;
                                                          case "02":
                                                              strReturn = "AM";
                                                              break;
                                                          case "03":
                                                              strReturn = "AM";
                                                              break;
                                                          case "04":
                                                              strReturn = "AM";
                                                              break;
                                                          case "05":
                                                              strReturn = "AM";
                                                              break;
                                                          case "06":
                                                              strReturn = "AM";
                                                              break;
                                                          case "07":
                                                              strReturn = "AM";
                                                              break;
                                                          case "08":
                                                              strReturn = "AM";
                                                              break;
                                                          case "09":
                                                              strReturn = "AM";
                                                              break;
                                                          case "10":
                                                              strReturn = "AM";
                                                              break;
                                                          case "11":
                                                              strReturn = "AM";
                                                              break;
                                                          case "12":
                                                              strReturn = "PM";
                                                              break;
                                                          case "13":
                                                              strReturn = "PM";
                                                              break;
                                                          case "14":
                                                              strReturn = "PM";
                                                              break;
                                                          case "15":
                                                              strReturn = "PM";
                                                              break;
                                                          case "16":
                                                              strReturn = "PM";
                                                              break;
                                                          case "17":
                                                              strReturn = "PM";
                                                              break;
                                                          case "18":
                                                              strReturn = "PM";
                                                              break;
                                                          case "19":
                                                              strReturn = "PM
                                          
                                          F Offline
                                          F Offline
                                          Fabio Franco
                                          wrote on last edited by
                                          #20

                                          Dude :doh: You got to be making that up!

                                          "To alcohol! The cause of, and solution to, all of life's problems" - Homer Simpson

                                          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