Save me from having to write the most boring, time consuming task since EVER.

145 views
Skip to first unread message

brandall

unread,
May 28, 2011, 6:37:35 PM5/28/11
to Tasker
In short, I need to find out the number of minutes between:

Wed 1st June 2011 13:00

and

5-28-11 23.32 (which is %DATE %TIME).

Using variables sets and splits, I'm pretty sure it's going to be
painfully boring...

Anyone got any bright ideas?

Please save me.

brandall

unread,
May 28, 2011, 7:47:43 PM5/28/11
to Tasker
Since I wrote the above, Google changed their RSS output to:

Wed Jun 1, 2011 13:00

So glad I hadn't already written it!

BossMan

unread,
May 28, 2011, 8:54:02 PM5/28/11
to Tasker
Should be pretty easy to handle e.g. in python, so consider running an
external script.

BR,
A.

secretspy711

unread,
May 29, 2011, 2:00:14 PM5/29/11
to Tasker
I would look into python as well. Some programming languages have a
command to convert a date to a numeric value. Then its just a matter
of subtracting the two and converting back to minutes. You'd want to
do a couple hand-crank calculations to make sure its working
correctly.

brandall

unread,
May 29, 2011, 6:25:56 PM5/29/11
to Tasker
I guess I best add python to my list of things to learn...

It's going to be a long night...

Cheers for the replies.

BossMan

unread,
May 29, 2011, 6:50:25 PM5/29/11
to Tasker
I think it should be even easier in python - you can define custom
formatting for every date variable and simply subtract them. Then,
handle the delta in a way you want (hours, days, etc..).

BR,
A.

brandall

unread,
May 29, 2011, 8:11:16 PM5/29/11
to Tasker
> I think it should be even easier in python - you can define custom
> formatting for every date variable and simply subtract them. Then,
> handle the delta in a way you want (hours, days, etc..).

I only wish I knew what 'delta' meant!?

You almost sound like you're convincing yourself to write this for me
BossMan ;)

The coffee is on and 'python for noobs' in about to query Google...

UncleMike

unread,
May 29, 2011, 11:42:49 PM5/29/11
to tas...@googlegroups.com

I think I've got something here.  It's quite convoluted, and I think an external script would certainly be easier, but I post this to show that (I think) it can be done in Tasker, and to show a way I came up with to pull a value out of a pseudo-array.

# minutes between 5-28-11 23.32 and wed jun 1, 2011 13:00 (%DATE %TIME)
# Assumptions
# Leap year every 4 years (not true, but good until 2100)
# the dates are within one year of each other

# Set %DAY1MIN to the number of minutes that have passed in the current day
%TMP = %TIME

Split %TMP .
%DAY1MIN = %TMP1 * 60 + %TMP2
Join %TMP delete parts
Clear %TMP

# For the current day, set %DAYS2 to the number of days that have passed in the preceding months
# by extracting the number from an array (of sorts), using the current month as an index
# account for leap years, but ignore the 100 year rule
# then calculate the number of full days that have passed this year, convert to minutes
# and add to %DAY1MIN to get the number of minutes that have passed this year

%TMP = %DATE
Split %TMP -
%LEAP1 = %TMP3 / 4
Split %LEAP1 .
%DAYS = x(1)0(1)(2)31(2)(3)59(3)(4)90(4)(5)120(5)(6)151(6)(7)181(7)(8)212(8)(9)243(9)(10)273(10)(11)304(11)(12)334(12)x if %LEAP12 is set
%DAYS = x(1)0(1)(2)31(2)(3)60(3)(4)91(4)(5)121(5)(6)152(6)(7)191(7)(8)213(8)(9)244(9)(10)274(10)(11)305(11)(12)335(12)x if %LEAP12 isn't set
Split %DAYS (%TMP1)
Variable Add %DAY1MIN = (%DAYS2 + %TMP2 - 1) * 1440
Join %TMP delete parts
Clear %TMP
Join %DAYS
Clear %DAYS


# Now let's look at day 2 (format: wed jun 1, 2011 13:00)
# assume date is contained in %CALDATE

Split %CALDATE [space]
Split %CALDATE5 :
%DAY2MIN = %CALDATE51 * 60 + %CALDATE52
Join %CALDATE5 delete parts
Split %CALDATE3 ,
%YEAR = %CALDATE4
%LEAP = %YEAR / 4
Split %LEAP .
%DAYS = xjan0janfeb31febmar59marapr90aprmay120mayjun151junjul181julaug212augsep243sepoct273octnov304novdec334decx if %LEAP2 is set
%DAYS = xjan0janfeb31febmar60marapr91aprmay121mayjun152junjul191julaug213augsep244sepoct274octnov305novdec335decx if %LEAP2 isn't set
Split %DAYS %DATE2
Variable Add %DAY2MIN = (%DAYS2 + %CALDATE31 - 1) * 1440
Join %CALDATE3 delete parts
Join %CALDATE delete parts
Clear %CALDATE
Join %DAYS delete parts
Clear %DAYS
Join %LEAP
Clear %LEAP

%DELTAMIN = %DAY2MIN - %DAY1MIN
If %DELTAMIN < 0
Variable Add %DELTAMIN = 365 * 1440
Variable Add %DELTAMIN = 1440 if %LEAP12 Isn't Set
End if

Join %LEAP1 delete parts
Clear %LEAP1

BossMan

unread,
May 30, 2011, 9:07:37 AM5/30/11
to Tasker
There you go - I was curious enough to spend half an hour and try
writing my first python script to.

This is the output:
python ~/my_script.py "5-28-11 23.32" "Wed Jun 1, 2011 13:00"
Wed Jun 1, 2011 13:00
5-28-11 23.32
Back: 2011-05-28 23:32:00
Then: 2011-06-01 13:00:00
This is number of minutes: 11608

.. and this is the script itself

#### script starts here
import datetime
import time
import sys

print sys.argv[1]
print sys.argv[2]

back = datetime.datetime(*time.strptime(sys.argv[1], "%m-%d-%y %H.%M")
[0:5])
then = datetime.datetime(*time.strptime(sys.argv[2], "%a %b %d, %Y %H:
%M")[0:5])

difference = then - back

minutes = difference.days*3600
tmp_minutes, seconds = divmod(difference.seconds, 60)

print "Back:", back
print "Then:", then

print "This is number of minutes:", minutes+tmp_minutes

#### script ends here

I have not check it on phone as I do not have ASE installed - but I
think it should work as well. Also, might that Pent is changing date/
time format in the next version. If the date format is changed, you
can check this link to update the pattern matching: http://strftime.org/

BR,
A.

brandall

unread,
May 30, 2011, 11:48:19 AM5/30/11
to Tasker
WOW!

Really appreciate this guys, I was hoping someone would take on the
challenge!

I'm viewing this on my phone at the moment, but will check out both
methods properly later.

Thanks again and good to know where two Tasker Master-minds are for
future reference! ;)

Matthieu Berthomé

unread,
May 31, 2011, 10:02:20 AM5/31/11
to tas...@googlegroups.com
Wow, These pseudo-array are really clever !
you should post something in the tasker pro with the general methodology or something, that'd be great !



brandall

unread,
May 31, 2011, 8:37:57 PM5/31/11
to Tasker
@UncleMike - Big thanks again because it really works...

It took me a while as discovered a few issues with it - I'll list them
in case anyone else uses it for something:

1) The month array had to have a capital for it to recognise the split
due to the RSS output it was reading from (you weren't to know this of
course!).
2) Split %DAYS %DATE2 <- that line should have read Split %DAYS
%CALDATE2
3) Tasker couldn't handle the maths in one action - it would throw up
an error of 'massive number' or something like that, so I had to split
apart actions such as 'Variable Add %DAY2MIN = (%DAYS2 + %CALDATE31 -
1) * 1440'

That's was it!

Will make sure I give you a big credit in this post when I load it up!
http://forum.xda-developers.com/showthread.php?t=1093359

@Bossman - I'll try out your script tomorrow!

I can't remember what I did with my life before Tasker...?

UncleMike

unread,
May 31, 2011, 10:20:54 PM5/31/11
to tas...@googlegroups.com

My thought process on this started out of sequence, and midway through I realized that %DATE was an internal variable, and it looks like I forgot to change one occurrence to %CALDATE.  Worse things have happened.

I'm glad it works with little modification - obviously I didn't test it. :)

Pent

unread,
Jun 1, 2011, 5:42:03 AM6/1/11
to Tasker
> I think I've got something here.  

Yes, a touch of lunacy :-)

> It's quite convoluted, and I think an
> external script would certainly be easier, but I post this to show that (I
> think) it can be done in Tasker, and to show a way I came up with to pull a
> value out of a pseudo-array.

Awesome!

I was getting close to putting in some conversion functions (date/time
to seconds etc) but this is much better :-)

Pent

BossMan

unread,
Jun 1, 2011, 6:49:49 AM6/1/11
to tas...@googlegroups.com
@brandall

I checked my script yesterday evening using SL4A and it works, but requires some changes in order to handle parameters sent from Tasker. Additionally, I did not think of a way to return value - currently it is only "toasted" + loaded into notification. Possibly, this could be read from notification or a file using "file changed"/"notificaiton" events.

In order to run script, you should use Misc->Run Script action and put %DATE,%TIME,%GDATE  in the parameters list.

##### script starts
import android
import datetime
import time

droid = android.Android()
tasker_date = droid.getIntent().result[u'extras'][u'%DATE']
droid.makeToast(tasker_date)
tasker_time = droid.getIntent().result[u'extras'][u'%TIME']
droid.makeToast(tasker_time)
google_date = droid.getIntent().result[u'extras'][u'%GDATE']
droid.makeToast(google_date)

tasker_date += " " + tasker_time
droid.makeToast(tasker_date)

back = datetime.datetime(*time.strptime(tasker_date, "%Y-%m-%d %H.%M")[0:5])
then = datetime.datetime(*time.strptime(google_date, "%a %b %d, %Y %H:%M")[0:5])



difference = then - back

minutes, seconds = divmod(difference.seconds, 60)
minutes += difference.days*3600
toast = "Back: " + str(back)
droid.makeToast(toast)
droid.makeToast("Then: " + str(then))

droid.makeToast("This is number of minutes: " + str(minutes))

droid.notify("minutes " + str(minutes), str(minutes))
#### script ends

BR,
A.

brandall

unread,
Jun 1, 2011, 1:53:15 PM6/1/11
to Tasker
@Bossman - brilliant! - thank you very much.

I have no knowledge how to pass the variables and results back and
forth either, but I'm sure Google will be my friend! That's my night
sorted...

@UncleMike "I'm glad it works with little modification - obviously I
didn't test it" <- can't believe you did that from your head... as
soon as I do a variable spit using Tasker I get a headache... Let
alone without...

Another little error - jun152junjul191jul <- It's just not good
enough! ;)
Reply all
Reply to author
Forward
0 new messages