how to get a boolean value with the conditions given here?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • leovach
    New Member
    • Sep 2010
    • 1

    how to get a boolean value with the conditions given here?

    hi dudes...
    i need to finish this sample task asap, could anyone look n respond asap?
    i have this syntax,
    Code:
    public boolean trans_possible(int hours, int minutes)
    {
    ....
    }
    the condition is this trans_possible will return true if the time is with in 4.45pm else it will return false.
    with that the other requirements are,
    it should take both arguments >> hours and minutes.
    hour is in 24 format >> 0 to 23
    minute is in 59 format >> 0 to 59
    with these details, i need the body of the class, i dont need conversion of hour to minutes.

    thanks in advance

    regards,
    leo
    Last edited by Nepomuk; Sep 12 '10, 08:14 AM. Reason: Please use [CODE] tags
  • Oralloy
    Recognized Expert Contributor
    • Jun 2010
    • 988

    #2
    Time can be a bit difficult the first time you need to think about it. Part of the problem is that there are some major time concepts that people try to ignore in software, and then find they can't.

    First off, there's the concept of absolute time. This is a timestamp that represents an instant in time, whenever - be it 2010 BC March 14 at 3:15:26, or whatever.

    Then there's the concept of a time interval. For instance, 1989 represents the entire year 1989 from 00:00:00 on January 01 through 23:59:59.99999 on December 31.

    Which is different from the concept of an absolute time difference, say 17:15:00, which would be seventeen hours, fifteen minutes. Time differences can be positive or negative.

    Then there's the concept of the indeterminate time difference. One month's difference means what? On February first, adding one month should give March first, right? So it's 28 (or 29) days. But on December first, one months difference is 31 days.

    In your context the values you're recieving are exact time differences. Which means that they can be added together in a sensible sort of way.

    Likewise, 4.45pm is also an exact time difference. It's the common form of expressing a time difference relative to the start of a day.

    Exact time differences can be directly compared without having to worry about little things like time period overlap and all that mess.

    But you probably don't care. Just convert the entire input mess to relative hours and test, like follows:
    Code:
    float zeit=hours+(float)minutes/60.0;
    boolean re=(zeit<16.75);
    return re;
    Or, if you prefer, do it in minutes.
    Code:
    int d=minutes+hours*60;
    boolean r=(1005>d);
    return r;
    Sorry for being so short, it's just that I've taken headers into time issues on occasion, and most folks just don't seem to understand the issues and the assumptions that we make when we deal with time in our day-to-day lives.

    Just wait until you have somebody ask for timestamps and then just say "duh?" when you mention the fact that their web site is 24/7 worldwide, so what time zone...Oh yes, and what's this 22:00 business - it's only 3:00pm.

    Comment

    • Oralloy
      Recognized Expert Contributor
      • Jun 2010
      • 988

      #3
      Or you can just compress it all out...
      Code:
      return(1005>minutes+60*hours);
      Code:
      return hours+minutes/60.0<16.75;

      Comment

      Working...