• (cs) in reply to chubertdev
    chubertdev:
    Oddly enough, this is a case where the Select statement in VB .NET excels.
            Public Shared Function GetDayOrdinal(ByVal intDayOfMonth As Integer) As String
                Select Case intDayOfMonth
                    Case 1, 21, 31
                        Return String.Format("{0}st", intDayOfMonth)
                    Case 2, 22, 32 'asteroid knocked the Earth off a bit
                        Return String.Format("{0}nd", intDayOfMonth)
                    Case 3, 23
                        Return String.Format("{0}rd", intDayOfMonth)
                    Case 4 To 20, 24 To 30
                        Return String.Format("{0}th", intDayOfMonth)
                    Case Else
                        Throw New ArgumentException(String.Format("Invalid day of month: {0}", intDayOfMonth))
                End Select
            End Function
    

    is it too soon to claim Muphry's Law?

    hehe

  • Mario (unregistered)

    Working with day%10 would have been easier.

  • Better late than never (unregistered)

    Found this in the javascript supplied by www.azcentral.com today:

    var d = new Date(); var month = d.getMonth(); var day = d.getDate(); var year = d.getFullYear();

    if(day == 1) { var date_suffix = 'st '; } else if (day == 2) { var date_suffix = 'nd '; } else if (day == 3) { var date_suffix = 'rd '; } else { var date_suffix = 'th '; }

    switch(month) { case 0: month = 'Jan '; break; case 1: month = 'Feb '; break; case 2: month = 'Mar '; break; case 3: month = 'Apr '; break; case 4: month = 'May '; break; case 5: month = 'Jun '; break; case 6: month = 'Jul '; break; case 7: month = 'Aug '; break; case 8: month = 'Sep '; break; case 9: month = 'Oct '; break; case 10: month = 'Nov '; break; case 11: month = 'Dec '; break; }

  • Iggy Drougge (unregistered)

    TRWTF is failing to call OS library functions, unless this code was written in 1987.

  • Peter Wolff (unregistered) in reply to bkDJ
    bkDJ:
    You can force a case fallthrough with a goto in C#...
    case 1:
      do(blah);
      goto 11;
    case 11:
      dont(blah);
    
    A bonus WTF is that Microsoft officially recommends the use of goto in ths case (no pun intended) - see last code sample on that page

Leave a comment on “Remember, Remember the Thirty-Third of November”

Log In or post as a guest

Replying to comment #420947:

« Return to Article