• Manadar (unregistered)
    Jeff replaced all instances of PopulateDates() with the built-in ToShortDateString().

    Don't forget the 2 global variables in PopulateDates. O_o

    A straight up search and replace is going to be a problem. Better to rewrite PopulateDates to use ToShortDateString instead.

  • David Aldridge (unregistered)

    I'm pretty sure that the auto industry has it's own annual calendar, which is what all of the date arithmetic is about.

  • Leo (unregistered)

    The real WTF is VB.

  • Remy Porter (cs) in reply to David Aldridge

    I've worked with custom calendars. Not a one has any insane logic like this.

  • Mike (unregistered) in reply to Leo
    Leo:
    The real WTF is VB.

    The real WTF is VBScript!

    (VB is fine)

  • Remy Porter (cs) in reply to Mike

    VB.Net is fine. VB is... special.

  • MrBester (unregistered) in reply to Manadar
    Manadar:
    Jeff replaced all instances of PopulateDates() with the built-in ToShortDateString().

    Don't forget the 2 global variables in PopulateDates. O_o

    A straight up search and replace is going to be a problem. Better to rewrite PopulateDates to use ToShortDateString instead.

    And don't forget the localisation. This returns US style dates.
  • Chairman_Mau (unregistered)

    What happens to the text boxes that are now not populated because he's replaced the call to the method that would populate them...

  • Karma (unregistered)

    If you're rolling your own date logic, chances are better than 99% you're Doing It Wrong.

    Of course, if the human system for reckoning time is so thoroughly hosed that 99 out of 100 programmers can't implement it, is there any chance some of the blame might lie with the human system for reckoning time?

  • Pip (unregistered) in reply to Karma

    Human are far too lazy to try look up how it works to implement it correctly in the first place.

    Most 'implementations' I've seen are based on bad assumptions and a complete disregard to Timezones,Formats,Cultures, etc...

  • QJo (unregistered) in reply to Karma
    Karma:
    Of course, if the human system for reckoning time is so thoroughly hosed that 99 out of 100 programmers can't implement it, is there any chance some of the blame might lie with the human system for reckoning time?

    Absolutely not. The ability to handle the really-quite-straightforward technique for reckoning time according to the Gregorian calendar is a pons asinorum in the understanding of the universe. And if there are computer programmers who do not have the basic intelligence to be able to understand how a calendar works, they have absolutely no business being in the industry.

    What's the current socio-political position as regards eugenics and euthanasia for the terminally thick?

  • Nagesh (cs)

    Windows system date also cause many issue due to cultural impositions and varied date formats in all parts of universe.

  • pjt33 (cs) in reply to MrBester

    This code would work fine with a lunar calendar.

    MrBester:
    And don't forget the localisation. This returns US style dates.
    Just need to use InvariantCulture. For some reason which I don't understand, that uses US style rather than ISO 8601.
  • fa2k (unregistered)

    There's a couple of bugs in January, but I don't really see the big WTF. Seems like they just need an approximate last week.

  • Joe M (unregistered) in reply to Remy Porter
    Remy Porter:
    I've worked with custom calendars. Not a one has any insane logic like this.

    My employer uses some oddball logic to calculate it's financial calendar. (Though this looks less "insane" and more "incomplete" to me.)

    The complicated logic is why we almost never actually store anything in the financial calendar's format. We just convert it when we need it instead -- usually just for reports.

  • @Deprecated (cs)
    Contracted long ago, the logger had been usable but quirky
    If day > 7 Then beginday = DateTime.Today.Day - 7

    Somebody help me out here... WTF was the programmer doing?

    Here are a selection of dates run through this bizarre algorithm: Good WTF 12/05/1999: 10/25/1999 01/18/2000: 0/11/2000 01/23/2000: 0/16/2000 02/12/2000: 1/5/2000 03/20/2000: 2/13/2000 12/15/2000: 11/8/2000 01/19/2001: 0/12/2001 02/06/2001: 0/26/2000 02/15/2001: 1/8/2001 02/28/2001: 1/21/2001 04/17/2001: 3/10/2001 06/10/2001: 5/3/2001 09/06/2001: 7/26/2001 10/24/2001: 9/17/2001 12/22/2001: 11/15/2001 01/21/2002: 0/14/2002 02/20/2002: 1/13/2002 03/25/2002: 2/18/2002 10/24/2002: 9/17/2002 12/19/2002: 11/12/2002 01/12/2003: 0/5/2003 02/18/2003: 1/11/2003 03/05/2003: 1/25/2003 03/28/2003: 2/21/2003 04/11/2003: 3/4/2003 05/03/2003: 3/23/2003 09/29/2003: 8/22/2003 10/11/2003: 9/4/2003 11/23/2003: 10/16/2003 11/23/2003: 10/16/2003 12/18/2003: 11/11/2003 02/01/2004: 0/21/2003 03/24/2004: 2/17/2004 03/24/2004: 2/17/2004 04/23/2004: 3/16/2004 08/27/2005: 7/20/2005 10/02/2005: 8/22/2005 11/30/2005: 10/23/2005 12/04/2005: 10/24/2005 12/09/2005: 11/2/2005 12/22/2005: 11/15/2005 01/26/2006: 0/19/2006 02/25/2006: 1/18/2006 04/22/2006: 3/15/2006 04/12/2007: 3/5/2007 04/12/2007: 3/5/2007 06/03/2007: 4/23/2007 10/13/2007: 9/6/2007 11/19/2007: 10/12/2007 12/27/2007: 11/20/2007 01/04/2008: -1/24/2008 02/12/2008: 1/5/2008 02/19/2008: 1/12/2008

    My favourite has to be -1/24/2008.

    It is pretty obvious what TRWTF is this time... m/d/y :-p

    Edit: Let me qualify I used Java Calendar to get the year, month, and day of month, which I assumed was the same as VB's, and may be an invalid assumption.

  • QJo (unregistered)

    Of course, the real WTF is that both Jeff and Tabitha are working at 7:15. Which 7:15 it is, they don't say (another failure of the US way; the civilised world uses the 24-hour clock). Either this is 7:15 pm, which means that they're both staying late, or they start really early in the morning.

  • georgir (cs)

    Aside from the already mentioned 'month 0' WTF and the obvious but strangely not explicitely commented yet 'treat all months as 28 days' lunar calendar approach WTF, there are WTFs in the article conclusion as well. Someone already mentioned 'replaced a sub with a function', but why that function was about date formatting and not date arithmetics (i.e. DateAdd) is a bigger WTF.

    The real WTF of course are the parents that could not spell Tabitha properly. (edit: oh wait, it is spelled correctly in the first instance in the article, but not in the rest... so whose WTF is it really, the article author, or the poor girl's parents?)

  • Tuka (unregistered) in reply to QJo
    QJo:
    Either this is 7:15 pm, which means that they're both staying late, or they start *really early* in the morning.

    "pm" is a redundant information.

    No real programer starts before 9:00 am. And start means here "first coffee". So 7:15am is something which will never happen. The 'pm' can be dropped.

  • RonBeck62 (cs)

    I'm with Tabitha. The code is bug-free. It fills in two text boxes on the form with today for the end date, and something over a week ago for the begin date. By doing a global substitution instead of simplifying the routine, Jeff broke the build. And, he should have been looking for the problem in the logging section, not creating new ones in the reporting section.

      Sub PopulateDates()
        txtBeginDate.Text = Now.AddDays(-7).ToShortDateString
        txtEndDate.Text = Now.ToShortDateString
      End Sub
    
  • georgir (cs) in reply to @Deprecated
    @Deprecated:
    Edit: Let me qualify I used Java Calendar to get the year, month, and day of month, which I assumed was the same as VB's, and may be an invalid assumption.
    Of course it is an invalid assumption. Not even array indices start at zero in VB by default, why would you expect month indices to do that. Whoever decided to do it that way in Java was actually suffering some serious brain disease, and I feel pity about them almost as much as about those that have to program with the result.

    Edit: and aside from the month parts, it seems to me you have messed up the resulting day parts for inputs in the first seven days of a month.

  • Joe M (unregistered) in reply to georgir
    georgir:
    the obvious but strangely not explicitely commented yet 'treat all months as 28 days' lunar calendar approach WTF

    While I agree that it probably constitutes a WTF, some financial calendars consist of 13 28-day "periods" in a year. Except for every 5-7 years there is a period that is 5 weeks instead of four. It was more common in the 50's and prior than it is now (according to my parents anyway... I wouldn't know).

  • Joe M (unregistered) in reply to Joe M
    Joe M:
    georgir:
    the obvious but strangely not explicitely commented yet 'treat all months as 28 days' lunar calendar approach WTF

    While I agree that it probably constitutes a WTF, some financial calendars consist of 13 28-day "periods" in a year. Except for every 5-7 years there is a period that is 5 weeks instead of four. It was more common in the 50's and prior than it is now (according to my parents anyway... I wouldn't know).

    I can add that I unfortunately work for a company who still uses this format.

  • Dom (unregistered) in reply to Karma
    Karma:
    Of course, if the human system for reckoning time is so thoroughly hosed that 99 out of 100 programmers can't implement it, is there any chance some of the blame might lie with the human system for reckoning time?

    Surely the "human system for reckoning time" is based on the Earth's rotation and its orbit around the Sun. Maybe the blame lies with God.

  • Don'tneedastinkingname (unregistered)
    And if there are computer programmers who do not have the basic intelligence to be able to understand how a calendar works, they have absolutely no business being in the industry.

    And yet... There they are.

    The real wtf is the arse backwards American date format. Amirite?

  • BobB (cs)

    Jeff was lucky. Humor in our offices is only allowed from 4:50pm to 5:00pm. Any sooner than that and you risk being written up for being disruptive and 'not a team player'. Attempts at making humor must be announced via the holding of an orange neon card as the humor is being made. Failure to use the orange neon card will also result in a write up. Attempts at making an 'off color humor' will not be tolerated, but some of us hear stories about how upper management is allowed to do so, and that it requires a UV reactive black card. We're debating going in and acquiring one of these cards as apparently a coworker has an awesome joke about a duck, a midget, a dragon, a radish and the CEO. I look forward to to the day we can acquire one of those black cards.

  • I forget (unregistered)

    AM/PM forever, you foreign third-world heretics!

    One day you will learn to do things the same as the great US of A!

  • QJo (unregistered) in reply to georgir
    georgir:
    The real WTF of course are the parents that could not spell Tabitha properly. (edit: oh wait, it is spelled correctly in the first instance in the article, but not in the rest... so whose WTF is it really, the article author, or the poor girl's parents?)

    I wonder if Jeff gets ta-bath-a with her?

  • Pock Suppet (unregistered) in reply to Don'tneedastinkingname
    Don'tneedastinkingname:
    And if there are computer programmers who do not have the basic intelligence to be able to understand how a calendar works, they have absolutely no business being in the industry.

    And yet... There they are.

    The real wtf is the arse backwards American date format. Amirite?

    Urong. The only format any programmer should ever use is yyyy-mm-dd. Period.

  • Staz (unregistered)

    I'm guessing that Jeff isn't the hero of this story, he's the butt of the joke, yes?

    a) he doesn't seem to fix the original problem b) he messes with code he doesn't seem to understand, despite his supervisor saying it isn't required c) he introduces a new bug with his global search/replace d) he does all this because he doesn't like the way date to string conversions have been done

  • Vroooom (unregistered)

    Can we maybe keep the "quirky" characters and clumsy storytelling out of CodeSOD?

  • JC (unregistered)

    Amazing things about this story:

    1. Managing to run VB.NET inside a vbs file (vbs did not have DateTime - thats a .NET object)

    2. Managing to update a textbox from a vbs file

    Author/Editor: If you're going to anonymize, at least get a clue!

  • Coyne (cs)

    Should have named it "MangleDates()"...

  • Twins (unregistered)

    So he works with two ladies with similar sounding names who are both his boss and both use understated and sarcastic humor? I'm confused.

    (Tabitha or Tabatha?)

    nimis: He sailed on the U.S.S. Nimis.

  • ObiWayneKenobi (cs)

    I call BS. What version of VBS lets you A) Specify types (Everything is/was a Variant), and B) Has a ToShortDateString() method?

    This is VB.NET code. If you're going to anonymize, then stay consistent. If the sales logger is VBS, then it wouldn't have VB.NET code, unless I missed something.

    Also, the supervisor's nonchalant response indicates that she probably wrote it.

  • Frank (unregistered) in reply to Pock Suppet
    Pock Suppet:
    The only format any programmer should ever use is yyyy-mm-dd. Period.
    QFT. If you disagree, you are Wrong. Very Wrong. Sorely Wrong. Perhaps Incurably Wrong. Reboot your brain and read again: The only format any programmer should ever use is yyyy-mm-dd. Period.
  • operagost (cs) in reply to QJo
    QJo:
    Of course, the *real* WTF is that both Jeff and Tabitha are working at 7:15. Which 7:15 it is, they don't say (another failure of the US way; the civilised world uses the 24-hour clock). Either this is 7:15 pm, which means that they're both staying late, or they start *really early* in the morning.
    The story says that Jeff was resigned to working after 5 PM, so clearly the most likely answer is 7:15 PM.

    By the way, we're "civilized."

  • Rob (unregistered)

    The code has two problems.

    1. it does not set beginmonth correctly when today is jan-1 to jan-7.
    2. it sets beginday to be 21 days after the current day when the day today's day is 1 to 7 (sets it from the 22nd to the 28th).

    The first is definitely a problem as the resulting date is invalid.

    The second could be a problem, this result would not appear to be intentional. (my guess is that this has been noticed by the car salespeople for years as it amounts to double counting sales made between the 28th and 31st of the month).

    The developer has a different issue, he expects his boss to instantly see the problem in the code, and points out that he is not sure if she does. He should be telling his boss I found these two problems, and I am going to make the code behave like this. Only the first problem was reported, not the second.

  • Valued Service (unregistered) in reply to Dom
    Dom:
    Surely the "human system for reckoning time" is based on the Earth's rotation and its orbit around the Sun. Maybe the blame lies with God.

    The problem is that the rotation around the sun doesn't occur at an exact number of earth's rotations. Which means that every year occurs within 365.xx days. That little xx is what causes our years to have extra days in them.

    We try to fit in those extra days by blowing up that fraction until we have how many days per set of years. But the fraction is so precise that we can't use filler days with any degree of sanity. Plus, we don't have a precise calculation for that fraction, so we find out every now and then we're off by an hour or so.

    Because we like base 10 so much, instead of adding days per x years. We add 1 day per 4 years except every 100 years except every 1000 years. So 1700, 1800, 1900 not a leap year, but 2000 is.

    This is all because we prefer our years to land on solar dates.

    We could of course switch back to a lunar calendar.

  • RFoxmich (unregistered) in reply to Manadar
    Manadar:
    Jeff replaced all instances of PopulateDates() with the built-in ToShortDateString().

    Don't forget the 2 global variables in PopulateDates. O_o

    A straight up search and replace is going to be a problem. Better to rewrite PopulateDates to use ToShortDateString instead.

    Aw man I was going to call that TRWTF. Captch nulla; you getta nulla youa throwa ana exception.

  • RFoxmich (unregistered)

    What about cases where we use the Mayan Calendar -oh wait it's too late for that.

  • RandomGuy (unregistered) in reply to Twins
    Twins:
    So he works with two ladies with similar sounding names who are both his boss and both use understated and sarcastic humor? I'm confused.
    I guess only Tabitha is his supervisor and Tabatha is simply another colleague whom he asked for the second opinion.
  • Steve The Cynic (cs) in reply to Valued Service
    Valued Service:
    Dom:
    Surely the "human system for reckoning time" is based on the Earth's rotation and its orbit around the Sun. Maybe the blame lies with God.

    The problem is that the rotation around the sun doesn't occur at an exact number of earth's rotations. Which means that every year occurs within 365.xx days. That little xx is what causes our years to have extra days in them.

    We try to fit in those extra days by blowing up that fraction until we have how many days per set of years. But the fraction is so precise that we can't use filler days with any degree of sanity. Plus, we don't have a precise calculation for that fraction, so we find out every now and then we're off by an hour or so.

    Because we like base 10 so much, instead of adding days per x years. We add 1 day per 4 years except every 100 years except every 1000 years. So 1700, 1800, 1900 not a leap year, but 2000 is.

    This is all because we prefer our years to land on solar dates.

    We could of course switch back to a lunar calendar.

    (hat type="pendant" position="on head") The Earth revolves around the Sun, and rotates on its axis, so it is "revolutions" and "rotations".

    And it is one leap year per four years, except every hundred years, except every 400 years. (Technically, every century year before 1600 was a leap year because the Gregorian calendar that introduced the except-100-exceptsquared-400 rule wasn't invented until after 1500.) (/hat)

  • Ivan Godard (unregistered)

    The reason 13x28 day months are used in accounting (not just finance) is to make year-to-year results comparable. Without months being even modulo weeks there would be some years with a few percent more business days in them than others, leading to random variations in year-to-year (and month to month) results, which noise would swamp the signal of how the business is doing. It's GAAP. Before laughing at a non-techy, learn a bit about why it's done that way, and then see if you can figure out a better way. Harvard Business School would love to hear from you.

  • Quango (cs) in reply to Remy Porter
    Remy Porter:
    VB.Net is fine. VB is... special.
    VBscript is.. special needs
  • chubertdev (cs)
    Manadar:
    Jeff replaced all instances of PopulateDates() with the built-in ToShortDateString().

    Don't forget the 2 global variables in PopulateDates. O_o

    A straight up search and replace is going to be a problem. Better to rewrite PopulateDates to use ToShortDateString instead.

    "Find All References"

    Remy Porter:
    VB.Net is fine. VB is... special.

    VB .NET has many WTFs. See: IIF

    QJo:
    Of course, the *real* WTF is that both Jeff and Tabitha are working at 7:15. Which 7:15 it is, they don't say (another failure of the US way; the civilised world uses the 24-hour clock). Either this is 7:15 pm, which means that they're both staying late, or they start *really early* in the morning.

    Us Americans are smart enough to read the "resigned to working after 5 PM" part.

    georgir:
    @Deprecated:
    Edit: Let me qualify I used Java Calendar to get the year, month, and day of month, which I assumed was the same as VB's, and may be an invalid assumption.
    Of course it is an invalid assumption. Not even array indices start at zero in VB by default, why would you expect month indices to do that. Whoever decided to do it that way in Java was actually suffering some serious brain disease, and I feel pity about them almost as much as about those that have to program with the result.

    Edit: and aside from the month parts, it seems to me you have messed up the resulting day parts for inputs in the first seven days of a month.

    Array indices start at zero in VB .NET

    Pock Suppet:
    Urong. The only format any programmer should ever use is yyyy-mm-dd. Period.

    Wrong, date formatting is for the UX guys. :)

  • Bob (unregistered) in reply to Pock Suppet

    You mean yyyymmdd. The hyphens are redundant.

    As are the periods. /joke

  • emaNrouY-Here (unregistered)

    Why I spent so much time on this, I'll never know.

    Anyway, here are the results run through VBA Excel:

    Month	Day	Year	Begin Date	End Date
    12	5	1999	11-26-1999	12-5-1999
    1	18	2000	1-23-2000	1-18-2000
    1	23	2000	1-23-2000	1-23-2000
    2	12	2000	2-23-2000	2-12-2000
    3	20	2000	3-23-2000	3-20-2000
    12	15	2000	12-23-2000	12-15-2000
    1	19	2001	1-23-2001	1-19-2001
    2	6	2001	1-27-2001	2-6-2001
    2	15	2001	2-23-2001	2-15-2001
    2	28	2001	2-23-2001	2-28-2001
    4	17	2001	4-23-2001	4-17-2001
    6	10	2001	6-23-2001	6-10-2001
    9	6	2001	8-27-2001	9-6-2001
    10	24	2001	10-23-2001	10-24-2001
    12	22	2001	12-23-2001	12-22-2001
    1	21	2002	1-23-2002	1-21-2002
    2	20	2002	2-23-2002	2-20-2002
    3	25	2002	3-23-2002	3-25-2002
    10	24	2002	10-23-2002	10-24-2002
    12	19	2002	12-23-2002	12-19-2002
    1	12	2003	1-23-2003	1-12-2003
    2	18	2003	2-23-2003	2-18-2003
    3	5	2003	2-26-2003	3-5-2003
    3	28	2003	3-23-2003	3-28-2003
    4	11	2003	4-23-2003	4-11-2003
    5	3	2003	4-24-2003	5-3-2003
    9	29	2003	9-23-2003	9-29-2003
    10	11	2003	10-23-2003	10-11-2003
    11	23	2003	11-23-2003	11-23-2003
    11	23	2003	11-23-2003	11-23-2003
    12	18	2003	12-23-2003	12-18-2003
    2	1	2004	1-22-2004	2-1-2004
    3	24	2004	3-23-2004	3-24-2004
    3	24	2004	3-23-2004	3-24-2004
    4	23	2004	4-23-2004	4-23-2004
    8	27	2005	8-23-2005	8-27-2005
    10	2	2005	9-23-2005	10-2-2005
    11	30	2005	11-23-2005	11-30-2005
    12	4	2005	11-25-2005	12-4-2005
    12	9	2005	12-23-2005	12-9-2005
    12	22	2005	12-23-2005	12-22-2005
    1	26	2006	1-23-2006	1-26-2006
    2	25	2006	2-23-2006	2-25-2006
    4	22	2006	4-23-2006	4-22-2006
    4	12	2007	4-23-2007	4-12-2007
    4	12	2007	4-23-2007	4-12-2007
    6	3	2007	5-24-2007	6-3-2007
    10	13	2007	10-23-2007	10-13-2007
    11	19	2007	11-23-2007	11-19-2007
    12	27	2007	12-23-2007	12-27-2007
    1	4	2008	0/25/2007	1-4-2008
    2	12	2008	2-23-2008	2-12-2008
    2	19	2008	2-23-2008	2-19-2008
    

    And here's the modified for VBA code for your review

    Sub PopulateDates()
    
        Dim curYear As Integer
        Dim curMonth As Integer
        Dim curDay As Integer
        Dim beginday As Integer
        Dim beginmonth As Integer
        Dim beginyear As Integer
    
        For iRow = 2 To ActiveSheet.UsedRange.Rows.Count
    
            curYear = Cells(iRow, "C")
            curMonth = Cells(iRow, "A")
            curDay = Cells(iRow, "B")
    
            If curDay > 7 Then
                beginday = day(curDate) - 7
                beginmonth = curMonth
            Else
                beginday = 21 + curDay
                beginmonth = curMonth - 1
            End If
    
            If curMonth = 1 And curDay < 7 Then
                beginyear = curYear - 1
            Else
                beginyear = curYear
            End If
    
            Dim testbeginday As String
            testbeginday = beginmonth & "/" & beginday & "/" & beginyear
            Dim begindate As String
            begindate = beginmonth & "/" & beginday & "/" & beginyear
        
            Cells(iRow, "D").Value = begindate
            Cells(iRow, "E").Value = curMonth & "/" & curDay & "/" & curYear
            
        Next iRow
    
    End Sub
    
  • emaNrouY-Here (unregistered) in reply to emaNrouY-Here

    Note that only 1/4/2008 gave any problems

  • cellocgw (cs) in reply to Pock Suppet
    Pock Suppet:
    The only format any programmer should ever use is yyyy-mm-dd. Period.

    WTF? Why does a date format have to end with a period?

    Signed, Mr. You_Should_Have_Used_Quotation_Marks .

Leave a comment on “De-Populate Dates”

Log In or post as a guest

Replying to comment #:

« Return to Article