Date-Time and Time-Delta are different things!



  • I wrote a routine to retrieve records that occur within a specified timeframe, as follows:

      /**
    * Utility to extract all records from <...> that were created within the
    * specified time interval, inclusive.
    *
    * Usage:
    * long startMS = new GregorianCalendar(yyyy,mm,dd,hh,mm,ss).getTime().getTime();
    * long endMS = new GregorianCalendar(yyyy,mm,dd,hh,mm,ss).getTime().getTime();
    * List<Record> list = myFunc(startMS,endMS);
    *
    * @param startDateTimeInMS long - start of window; absolute time in MS
    * @param endDateTimeInMS long - end of window; absolute time in MS
    * @return List<Record><record> - all records from <...> that fall within
    * the specified timeframe, inclusive
    */
    List<Record> myFunc(long startDateTimeInMS, long endDateTimeInMS) {
    List<Record> matchingRecords = new ArrayList<record><Record>();
    for (Record rec : masterRecordList) {
    long recTime = rec.getTimeMS();
    if (startDateTimeInMS <= recTime && recTime <= endDateTimeInMS) {
    matchingRecords.add(rec);
    }
    }
    return matchingRecords;
    }
    </record></record>

    A coworker who is barely capable of conveying the simplest thought in no less than 50,000 words decided to use my function. After three days of working on it, he comes over to complain that it isn't returning any records.

    Background: this guy works on a feature that takes user input wherein the start of a given range is today minus some interval, and the end is some time in the past (before that).

    He computes the delta, from today, for both values, and passes the two deltas, in ms, to my routine.

    For example:

      long msIn2Years = 730 * 24 * 3600 * 1000;
    long msIn1Month = 30 * 24 * 3600 * 1000;
    List<Record><record> list = myFunc(msIn1Month, msIn2Years);
    </record>

    Naturally, my routine tried to find any records between Feb 1 1970 and Jan 1 1972; this didn't return any of the records from the past 2 years. What he should have done was:

      long startMS = new GregorianCalendar(2010,Calendar.April,20,0,0,0).getTime().getTime();
    long endMS = new GregorianCalendar(2012,Calendar.March,20,23,59,59).getTime().getTime();
    List<Record><record> list = myFunc(startMS,endMS);
    </record>

    Even with a detailed explanation of the startDateTimeInMS and endDateTimeInMS parameters, and sample code in the javadocs, he still managed to get it wrong.

    Sigh.



  • TRWTF is .getTime().getTime() right? Java? Yeah, that's it.  Also, your coworker.



  •  Why don't you just make your function accept a Date or Calendar object for start and end, and use the ms representation internally? Would have made more sense to me (although your documentation is quite clear on what you should use as parameters). Probably would be less confusing for your coworker, even though he's an idiot for not reading the doc



  • @Hantas said:

     Why don't you just make your function accept a Date or Calendar object for start and end, and use the ms representation internally? Would have made more sense to me (although your documentation is quite clear on what you should use as parameters). Probably would be less confusing for your coworker, even though he's an idiot for not reading the doc

    This^^  Your API sucks.  (Although it's well-documented)



  • @Hantas said:

     Why don't you just make your function accept a Date or Calendar object for start and end,
    Actually, that was how I originally wrote it, but this guy specifically requested me to change it to ms because everything he worked with was already in ms, and he didn't want to have to convert back to a date.



  • @snoofle said:

    @Hantas said:

     Why don't you just make your function accept a Date or Calendar object for start and end,
    Actually, that was how I originally wrote it, but this guy specifically requested me to change it to ms because everything he worked with was already in ms, and he didn't want to have to convert back to a date.

    And the same guy is the one who can't work out how to use your code?

    I want a signed copy of your memoirs!



  • @OzPeter said:

    the same guy
    Yes, it's the same guy. He originallyl converted the time deltas to Dates and passed them, but complained because of what he perceived as a useless conversion.

    Personally, I hate making relatively clean interfaces dirty, but arguing with this guy is so painful, and he doesn't stop, no matter how many cues you give him; since he's the only one who'd be using it I just made the change to shut him up.

    Yes, he read the javadocs, but simply couldn't understand the difference between the concepts of time-delta and date-time, and I wasted 45 minutes of my life trying to explain it to him (pictures, timeline; everything short of smacking him in the head) before he finally got it.



  • @snoofle said:

    everything short of smacking him in the head

    Looks like that's TRWTF.



  • @snoofle said:


    long msIn1Month = 30 * 24 * 3600 * 1000;

    I just spotted this. Did he really think that all months contain 30 days?



  • @OzPeter said:

    @snoofle said:

    long msIn1Month = 30 * 24 * 3600 * 1000;
    I just spotted this. Did he really think that all months contain 30 days?
    Normally, you'd be right, but in this particular business feature, they use 30 days as a "standard" month for purposes of a certain calculation.



  • @snoofle said:

    @OzPeter said:
    the same guy
    Yes, it's the same guy. He originallyl converted the time deltas to Dates and passed them, but complained because of what he perceived as a useless conversion.

    Personally, I hate making relatively clean interfaces dirty, but arguing with this guy is so painful, and he doesn't stop, no matter how many cues you give him; since he's the only one who'd be using it I just made the change to shut him up.

    Yes, he read the javadocs, but simply couldn't understand the difference between the concepts of time-delta and date-time, and I wasted 45 minutes of my life trying to explain it to him (pictures, timeline; everything short of smacking him in the head) before he finally got it.

    Seeing as how you were able to explain this concept to him (at great sacrifice to yourself), could you explain this concept to the developers behind Excel?


Log in to reply