473,416 Members | 1,584 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

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,
Expand|Select|Wrap|Line Numbers
  1. public boolean trans_possible(int hours, int minutes)
  2. {
  3. ....
  4. }
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
Sep 9 '10 #1
2 1973
Oralloy
988 Expert 512MB
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:
Expand|Select|Wrap|Line Numbers
  1. float zeit=hours+(float)minutes/60.0;
  2. boolean re=(zeit<16.75);
  3. return re;
Or, if you prefer, do it in minutes.
Expand|Select|Wrap|Line Numbers
  1. int d=minutes+hours*60;
  2. boolean r=(1005>d);
  3. 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.
Sep 10 '10 #2
Oralloy
988 Expert 512MB
Or you can just compress it all out...
Expand|Select|Wrap|Line Numbers
  1. return(1005>minutes+60*hours);
Expand|Select|Wrap|Line Numbers
  1. return hours+minutes/60.0<16.75;
Sep 10 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: WindAndWaves | last post by:
Hi Gurus What is the best way to store a boolean value in a MySql table (e.g. true or false) AND ( ;-) am I asking this in the right newsgroup (I could not find one for MySQL) Thank you -...
4
by: Grzegorz Dostatni | last post by:
Good morning. I've got a Tkinter problem: File "/usr/lib/python2.3/lib-tk/Tkinter.py", line 2310, in selection_present return self.tk.getboolean( TclError: expected boolean value but got "" ...
4
by: Simon Jefferies | last post by:
Hello, I've created an XSD file with the following in it: <xs:attribute name="Enabled" form="unqualified" type="xs:boolean" /> I am trying to set the XML to match this format, but how/what...
2
by: Douglas Buchanan | last post by:
This is a mystery! Why does the boolean value of a record change without my input. What follows describes the situation and the behavior. Table1: Field1: Text Field2: Yes/No Form1 has two...
3
by: Daves | last post by:
trying to get a boolean value from DataReader (that is, result from a SQL query); boolean MyBool = MyDataReader.GetBoolean(3); well it works using that number 3 but of course I would like to...
4
by: Patrick.O.Ige | last post by:
I'm DataBinding a CheckBoxList and i want to get the checkboxes selected when the page is loaded depending on a Boolean value from the Database.. chkDebtor.DataSource = objDR...
2
by: Brian Henry | last post by:
say i have a dataset called dv and i have a boolean value i want to filter by "b_DoesWork" while the column name in the data view that i want to filter on is called "Works" how would i filter...
1
by: STAGED | last post by:
The script: proc bugsy { } { global helmet pack forget .widget1 if { $helmet(key1) } { pack .widget2 -anchor nw -side top -expand 0 } else { show_new_widget }
4
by: moondaddy | last post by:
I'm new to c# and want to know the preferred way to reverse a Boolean value. for example: in vb I can do this: dim flag as Boolean
5
by: shana07 | last post by:
Good day all! I have one more question and needed some inputs from you guys. This is regarding condition value (T/F). My program (Driver) prints out condition values in reversed way - which...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.