• Post Reply Bookmark Topic Watch Topic
  • New Topic

Changing Hour to Min  RSS feed

 
Michele Smith
Ranch Hand
Posts: 421
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a servlet with a method:

/**

* @return <code>double</code> Hours
*/
public double getDriveHours() {
return getAsDouble("DriveTime", 0.0D);
}


I would like to change the time to minutes. I will create a new entry in the db for the minutes, but wondered if the time minutes is also double.

Thanks,
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37507
552
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would expect hour and minutes to have the same type. You can either have fractional hours/minutes in your system or you can't.

As far as converting from hours to minutes, that is easy. What formula could you use?
 
Rico Felix
Ranch Hand
Posts: 411
5
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Time representation is broken into modular parts each represented by an integer hours:minutes:seconds (basic representation)... we know that there are 60 minutes in an hour so to convert hours to minutes we multiply hours * 60 which should give an integer... For time representation I would suggest that you use integer variables for each part.

Example:





From this example you can probably get an idea of a design that suites your application...
 
Janeice DelVecchio
Bartender
Posts: 1812
12
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would expect hour and minutes to have the same type. You can either have fractional hours/minutes in your system or you can't.


It might make sense to have fractional hours, but not fractional minutes. It's different to want to know that something took 1.5 hours / 90 minutes, than it is to want to know that it took 90.2 minutes.
It depends on what level of precision you need to do the job... if you don't care about seconds, you don't care and that's ok.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37507
552
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Janeice DelVecchio wrote:It might make sense to have fractional hours, but not fractional minutes. It's different to want to know that something took 1.5 hours / 90 minutes, than it is to want to know that it took 90.2 minutes.

What's wrong with something taking 2.5 minutes?
 
Janeice DelVecchio
Bartender
Posts: 1812
12
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's exactly nothing wrong with it, but you might not need that level of precision.

If everything "used" to be reported in hours, minutes might be precise enough. Saying that because fractions of hours were possible means fractions of minutes should be possible is not necessarily a logical assumption.

Maybe somewhere in the app, someone was taking the fraction of the hour and rounding it to the closest minute. Who knows?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!