etling Posted September 16, 2014 Share Posted September 16, 2014 I found myself often converting hours & minutes to a decimal format when creating invoices. This workflow simply does that calculation and copies it to the clipboard. Type in the keyword, then hours:minutes to get that amount of time in decimal (rounded to the nearest hundredth). For example, 6 hours and 38 minutes: dtime 6:38 Copies 6.63 to clipboard. http://static.etling.com/assets/decimal_time_workflow.zip Link to comment
vitor Posted September 17, 2014 Share Posted September 17, 2014 There’s no need to .zip the workflow. In fact, it’s a waste, since workflows are already .zip files with a different extension. Link to comment
ixium Posted February 16, 2017 Share Posted February 16, 2017 Is there another copy of this workflow around? I am looking for this specific function and am having no luck Link to comment
dfay Posted February 16, 2017 Share Posted February 16, 2017 (edited) Try this in a Run Script box with language as python and input as {query}. You can pipe it out to a Copy to Clipboard action. i = "{query}".split(":") m=int(i[1])+(int(i[0])*60) print float(m)/60 Edited February 16, 2017 by dfay Link to comment
dfay Posted February 16, 2017 Share Posted February 16, 2017 (edited) Also if you want to go further here is a whole command-line time calculator library I wrote in python some years ago. The code above does the conversion to minutes rather than seconds but it's basically the same as the input_time, to_seconds and base_time functionality below. def to_seconds(i): seconds=int(i[2])+(int(i[1])*60)+(int(i[0]) * 60 * 60) return seconds def from_seconds(raw_seconds): seconds=abs(int(raw_seconds)) minutes=0 hours=0 while seconds > 59: seconds=seconds-60 minutes=minutes+1 while minutes > 59: minutes=minutes-60 hours=hours+1 if raw_seconds<0: hours=hours*-1 return [str(hours), str(minutes), str(seconds)] def input_time(): time = raw_input('enter time in h:m:s format: ') time_list=time.split(":") return time_list def add(base_time): increase=input_time() return(from_seconds(to_seconds(base_time)+to_seconds(increase))) def subtract(base_time): decrease=input_time() return(from_seconds(to_seconds(base_time)-to_seconds(decrease))) def multiply(base_time, multiplier): return(from_seconds(to_seconds(base_time)*multiplier)) def divide(base_time, divisor): return(from_seconds(to_seconds(base_time)/divisor)) def milePaceToKMPace(mile_pace): return(multiply(mile_pace,0.621371)) def kmPacetoMilePace(km_pace): return(multiply(km_pace,1.609343994)) def decimal_equivalent(base_time): return(to_seconds(base_time)/3600.0) def negative(base_time): return(multiply(base_time,-1)) def display_time(i): if len (i[1])==1: i[1]="0"+i[1] if len (i[2])==1: i[2]="0"+i[2] print i[0]+":"+i[1]+":"+i[2] Edited February 16, 2017 by dfay deanishe 1 Link to comment
alwaysaugust Posted April 22, 2017 Share Posted April 22, 2017 On 2/16/2017 at 11:28 AM, dfay said: Try this in a Run Script box with language as python and input as {query}. You can pipe it out to a Copy to Clipboard action. i = "{query}".split(":") m=int(i[1])+(int(i[0])*60) print float(m)/60 I got this to work and thank you so much, I was sad when the file here was a dead link. Can you explain how to make a script that will go the other way? hundereths to hh:m Link to comment
dfay Posted April 22, 2017 Share Posted April 22, 2017 this should work: i = "{query}" t =i.split(".") print t[0]+":"+str(int(t[1])*0.6) Link to comment
alwaysaugust Posted April 22, 2017 Share Posted April 22, 2017 Thank you soooooo much!!!! Link to comment
alwaysaugust Posted May 2, 2017 Share Posted May 2, 2017 (edited) Based on what dfay provided code wise I made this if anyone wants to use or modify it. Minute:Decimal Converter.alfredworkflow It could use some cleaning of the decimal places it outputs, etc but is functional. Edited May 2, 2017 by alwaysaugust link change Link to comment
deanishe Posted May 3, 2017 Share Posted May 3, 2017 FWIW, you should never use : in a filename that's intended for a Mac. The old macOS used : as a path separator, not /, so using a colon in a filename can cause unexpected behaviour. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now