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.
  • 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
              • 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
                #21

                The AM/PM suffix only makes sense on a 12-hour system, not a 24-hour clock. If you use an 24-hours based day, you already know whether the time is in the morning or evening. Otherwise, the 8 O'Clock needs the AM/PM suffix to discriminate between 8:00 (8 AM) and 20:00 (8 PM). It's a ridiculous format, and that mistake is as grave as the function is coded. It'd be best to use the date-format as specified in the users' settings, or to use a predefined format. Making up your own format requires owning a country.

                Bastard Programmer from Hell :suss:

                A 1 Reply Last reply
                0
                • L Lost User

                  The AM/PM suffix only makes sense on a 12-hour system, not a 24-hour clock. If you use an 24-hours based day, you already know whether the time is in the morning or evening. Otherwise, the 8 O'Clock needs the AM/PM suffix to discriminate between 8:00 (8 AM) and 20:00 (8 PM). It's a ridiculous format, and that mistake is as grave as the function is coded. It'd be best to use the date-format as specified in the users' settings, or to use a predefined format. Making up your own format requires owning a country.

                  Bastard Programmer from Hell :suss:

                  A Offline
                  A Offline
                  Albert Holguin
                  wrote on last edited by
                  #22

                  Eddy Vluggen wrote:

                  The AM/PM suffix only makes sense on a 12-hour system

                  true :thumbsup:

                  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?

                    L Offline
                    L Offline
                    Lilith C
                    wrote on last edited by
                    #23

                    BobJanova wrote:

                    Anyone spot any more?

                    No need to set a string to return from the function. A simple return "AM"; or return "PM"; would suffice.

                    I'm not a programmer but I play one at the office

                    B 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
                      
                      S Offline
                      S Offline
                      Spectre_001
                      wrote on last edited by
                      #24

                      Or... Assuming the string has only military time with no date:

                      string strReturn = DateTime.Parse(DateTime.MinValue.ToString("MM/dd/yyyy ") + strTime).ToString("tt");

                      If it has date and time:

                      string strReturn = DateTime.Parse(strTime).ToString("tt");

                      Kevin Rucker, Application Programmer QSS Group, Inc. United States Coast Guard OSC Kevin.D.Rucker@uscg.mil "Programming is an art form that fights back." -- Chad Hower

                      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
                        Eugene Lepekhin
                        wrote on last edited by
                        #25

                        your solution is different from original. What if the parameter string is not a number or number any other than one in switch? The original will return empty string while yours - eather throw or return PM instead.

                        V 1 Reply Last reply
                        0
                        • E Eugene Lepekhin

                          your solution is different from original. What if the parameter string is not a number or number any other than one in switch? The original will return empty string while yours - eather throw or return PM instead.

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

                          I know what you mean mate... the solution I put was just to show that whole function can be redundant. If I have to code it I will make sure of all exception and validations on client and server...

                          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
                            
                            M Offline
                            M Offline
                            Mark_Wallace
                            wrote on last edited by
                            #27

                            You should focus on making it future-proof.

                            I wanna be a eunuchs developer! Pass me a bread knife!

                            1 Reply Last reply
                            0
                            • P PIEBALDconsult

                              Yes, different notations for the same timepoint.

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

                              Same timepoint, but different datepoint ;)

                              G 1 Reply Last reply
                              0
                              • L Lost User

                                Same timepoint, but different datepoint ;)

                                G Offline
                                G Offline
                                GenJerDan
                                wrote on last edited by
                                #29

                                The Army (at least) took 2400 as the end of the day...and never acknowledged 0000 as existing. :p

                                So I rounded up my camel Just to ask him for a smoke He handed me a Lucky, I said "Hey, you missed the joke." My Mu[sic] My Films My Windows Programs, etc.

                                J 1 Reply Last reply
                                0
                                • G GenJerDan

                                  The Army (at least) took 2400 as the end of the day...and never acknowledged 0000 as existing. :p

                                  So I rounded up my camel Just to ask him for a smoke He handed me a Lucky, I said "Hey, you missed the joke." My Mu[sic] My Films My Windows Programs, etc.

                                  J Offline
                                  J Offline
                                  James Lonero
                                  wrote on last edited by
                                  #30

                                  Then one second after that would be 240001 or 000001?

                                  G 1 Reply Last reply
                                  0
                                  • J James Lonero

                                    Then one second after that would be 240001 or 000001?

                                    G Offline
                                    G Offline
                                    GenJerDan
                                    wrote on last edited by
                                    #31

                                    000001 But we just started the new logs at 0001Z. That minute inbetween was just ignored. Actually, come to think of it, we never used 2400Z, either. The day ended at 2359Z and the next started at 0001Z. :p

                                    So I rounded up my camel Just to ask him for a smoke He handed me a Lucky, I said "Hey, you missed the joke." My Mu[sic] My Films My Windows Programs, etc.

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

                                      S Offline
                                      S Offline
                                      Steve Burchett
                                      wrote on last edited by
                                      #32

                                      If you are dealing with instantaneity, 12:00:00 and 24:00:00 (or 0:00:00, if you prefer) are neither AM nor PM: the first is Noon and the second is Midnight.

                                      Just think of it as evolution in action.

                                      1 Reply Last reply
                                      0
                                      • L Lilith C

                                        BobJanova wrote:

                                        Anyone spot any more?

                                        No need to set a string to return from the function. A simple return "AM"; or return "PM"; would suffice.

                                        I'm not a programmer but I play one at the office

                                        B Offline
                                        B Offline
                                        BobJanova
                                        wrote on last edited by
                                        #33

                                        That's not really so much a horror as a stylistic choice, though one which I would also change as you have suggested there. Some people say that a single point of return is better because you don't have to look through the whole function to find escape points, and though I disagree with that (for one thing your function should be short enough it isn't a problem) I can see what they're getting at.

                                        L 1 Reply Last reply
                                        0
                                        • B BobJanova

                                          That's not really so much a horror as a stylistic choice, though one which I would also change as you have suggested there. Some people say that a single point of return is better because you don't have to look through the whole function to find escape points, and though I disagree with that (for one thing your function should be short enough it isn't a problem) I can see what they're getting at.

                                          L Offline
                                          L Offline
                                          Lilith C
                                          wrote on last edited by
                                          #34

                                          I disagree with the single point of return as well. To me it requires some degree of convoluting the code just to reach that point. I tried that approach for a while but I found myself having to add code rather than getting straight to the purpose of it. But then I've always tried to avoid having to take those few extra CPU cycles to get from point A to point B if point A++ gets the job done faster.

                                          I'm not a programmer but I play one at the office

                                          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