Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 07-19-2017, 03:02 PM   #1
Senior Member
Registered: May 2007
Posts: 1,129

Rep: Reputation: 42
Question Do you know a command or shell script to sum hours:minutes:seconds?

I have a scientific calculator that has a [NICE] button which deals with time. "Time", for it, is a unlimited number of hours (or degrees, if you prefer), number of minutes and number of seconds. It works like this:

We type number of hours (not limited to 24 or 360). Nothing new here.

After that, we may type "[NICE], number of minutes, [NICE]". This will make the number of hours (a real) be increased with the right fractional part. For example:

"8 [NICE] 30 [NICE]" gives the result 8.5, which means 8 and half hours. Good?

After that, we may follow with "number of seconds, [NICE]", which will work similarly to what was done for the minutes we typed. For example:

"8 [NICE] 30 [NICE] 900 [NICE]" gives the result of 8.75. Observe that 900 seconds is 0.25 hours, which was added to our previous result.

For any real number, we may check what it represents in [HOURS/DEGREES]:MINUTES:SECONDS. For example:

Make 8.75 be the current number, in any way. Then we type "[shift] [NICE]" to get "8 o 45 o 0". My "o" here is the closest I could type to what my calc shows, which is an "o" at half line height. But you got it:

8 degrees 45' 0"

So, do you know a script or something ready to use that works in a shell? Something like this would happen in a terminal:

$ time 8 45 00   # separators maybe ":" too
$ time 8 30 0 + 0 15 0  # "1" for min. or sec. mean "01", *not* "10"
$ time -r 8.75   # "-r" or "--reverse" means... do the reverse! haha
I found this, but it is not really what I wanted.

So, do you have something to make that?
Old 07-19-2017, 03:20 PM   #2
Registered: Jan 2017
Location: Manhattan, NYC NY
Distribution: Mac OS X, iOS, Solaris
Posts: 508

Rep: Reputation: 143Reputation: 143
I'm sure complex programs like Mathematica do that, but I haven't run across something free that just does that (not to say such thing doesn't exist), but it should be quite easy to program in C or something if you are so inclined.

Last edited by Laserbeak; 07-19-2017 at 03:22 PM.
Old 07-19-2017, 03:24 PM   #3
Registered: Jan 2017
Location: Manhattan, NYC NY
Distribution: Mac OS X, iOS, Solaris
Posts: 508

Rep: Reputation: 143Reputation: 143
This would be actually a cool iPhone program to write... hmmm
Old 07-19-2017, 03:55 PM   #4
Senior Member
Registered: May 2007
Posts: 1,129

Original Poster
Rep: Reputation: 42
I agree with you, Laserbeak. It is actually not that hard to make, so I imagined that it would exist. Quite useful! I do not know how to use everything my sci calc has, but what I called the "[NICE]" button has been useful several times! (:

I will suggest it to gcalctool, which does not have it - seems - among all its tastes: basic, advanced, financial, scientific and programmable.

If I make the script, or if needing a help with some details, I post here.
Old 07-19-2017, 06:26 PM   #5
LQ Newbie
Registered: Jan 2017
Posts: 3

Rep: Reputation: Disabled
Try something like this:

## script name: hours
## Expresses hours in decimal based on input of hours, minutes, seconds
## minutes input can exceed 1 hour, ie, m>60 is ok
## seconds input can exceed 1 minute or 1 hour, ie, s>60 is ok, as is s>3600
h=$1 ## hours
m=$2 ## minutes
s=$3 ## seconds
## set hours, minutes, and second to 0 if variables are unset
echo ${h:-0} hours ${m:-0} minutes ${s:-0} seconds
bc <<< "scale=4;(${h:-0}*60^2 + ${m:-0}*60 + ${s:-0})/60^2"
Here are examples:

$ hours 1
1 hours 0 minutes 0 seconds

$ hours 1 45
1 hours 45 minutes 0 seconds

$ hours 1 45 1800
1 hours 45 minutes 1800 seconds
1 members found this post helpful.



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How to display number of hours, minutes into seconds meditate1926 Programming 3 05-12-2014 09:32 AM
[SOLVED] BASH HowTo: exit script cleanly after x number of seconds(minutes,hours,days,etc) Andy Alt Programming 4 02-27-2014 02:56 PM
LXer: Run a command every 5 minutes, hours, days ... LXer Syndicated Linux News 0 04-08-2012 08:50 PM
convert total no of seconds in the format hour minutes and seconds suchi_s Programming 15 03-15-2011 11:34 AM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:34 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration