Adding minutes to !NOW

Discussions and Tech Support specific to the iMacros Firefox Add-on.
Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information: CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
Post Reply
alex4478
Posts: 22
Joined: Tue Oct 15, 2013 7:56 pm

Adding minutes to !NOW

Post by alex4478 » Mon Sep 15, 2014 7:50 am

Hi,

I'd like to be able to use the !NOW command, but add 20 minutes to the time.

What would be the correct syntax for this?

Thanks for any help.
chivracq
Posts: 9004
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Adding minutes to !NOW

Post by chivracq » Mon Sep 15, 2014 9:35 am

alex4478 wrote:Hi,

I'd like to be able to use the !NOW command, but add 20 minutes to the time.

What would be the correct syntax for this?

Thanks for any help.
CIM...! :mrgreen:

And what have you tried...?

The Wiki has an Example for 'EVAL()' using '!NOW'...
Last edited by chivracq on Mon Sep 15, 2014 10:02 am, edited 1 time in total.
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
alex4478
Posts: 22
Joined: Tue Oct 15, 2013 7:56 pm

Re: Adding minutes to !NOW

Post by alex4478 » Mon Sep 15, 2014 10:01 am

I have looked at that wiki entry. When I see all the symbols and words I get confused, I'm sure when you know what they mean it's just a case of translating the code so it says "get the time and add this value to it, oh and by the way the value is 20 minutes".
alex4478
Posts: 22
Joined: Tue Oct 15, 2013 7:56 pm

Re: Adding minutes to !NOW

Post by alex4478 » Mon Sep 15, 2014 2:17 pm

I've looked again at the above page.

I was thinking to use a prompt to ask for the amount of time to add on.

The prompt works and a variable is set, but still not able to add the variable to the time.

I then thought about subtracting the variable from the time, that didn't work either.
chivracq
Posts: 9004
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Adding minutes to !NOW

Post by chivracq » Mon Sep 15, 2014 2:29 pm

Yep, then post what you've tried, how far you've come with your Script, as I won't be writing your Code from Scratch...

And "CIM" is a Question... :idea: Read my Sig...

And several of your previous Threads were never neatly finished and are waiting for some Follow-up from you or you posting the final Solution... It looks like once you've managed to get your Solution, you don't bother anymore to post it, even though that could help other Users in the future with the same Question/Problem...
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
alex4478
Posts: 22
Joined: Tue Oct 15, 2013 7:56 pm

Re: Adding minutes to !NOW

Post by alex4478 » Mon Sep 15, 2014 2:39 pm

Code: Select all

AG POS=1 TYPE=INPUT:TEXT FORM=ID:eng_stats ATTR=ID:StartTime CONTENT={{!NOW:hh:nn}}
PROMPT "Enter Duration" !VAR1
SET !VAR2 {{!NOW:hh:nn}}
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:eng_stats ATTR=ID:FinishTime CONTENT={{!VAR1+!VAR2}}
I don't have anything positive to say about my behavior, and anything I could say would be misunderstood. You obviously know iMacro very well, so I am clearly at a disadvantage in that you have the answer I need.

I've looked through the old posts and don't believe I can remember if it was solved or not.

I will finish off the thread correctly.
chivracq
Posts: 9004
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Adding minutes to !NOW

Post by chivracq » Mon Sep 15, 2014 3:00 pm

Okay..., but CIM again... (3rd time...)
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
alex4478
Posts: 22
Joined: Tue Oct 15, 2013 7:56 pm

Re: Adding minutes to !NOW

Post by alex4478 » Mon Sep 15, 2014 3:04 pm

(Full) Config Info Missing: iMacros + Browser + OS with all Versions...

iMacros 8.8.2, Firefox 32.0.1, osX 10.7.5
chivracq
Posts: 9004
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Adding minutes to !NOW

Post by chivracq » Mon Sep 15, 2014 9:55 pm

alex4478 wrote:(Full) Config Info Missing: iMacros + Browser + OS with all Versions...

iMacros 8.8.2, Firefox 32.0.1, osX 10.7.5
Well, finally...

So OK, I got your thing to work... It's a bit cumbersome and there might be some better way to implement it if there is a way to make Calculations on Time Objects in JavaScript, but I'm no JavaScript Guru, so I implemented my own...
There are a few Limitations:
- It works for Duration up to 60 min, or up to 120 min minus the Nb of Minutes in '!NOW', otherwise you get some "14:74" funny Time...! (I could add it if you expect Durations to be longer than 60 min, but you mentioned 20 min...)
- I did not handle going over Midnight, tell me if you need it...

Code: Select all

VERSION BUILD=8820413 RECORDER=FX
TAB T=1

TAG POS=1 TYPE=INPUT:TEXT FORM=ID:eng_stats ATTR=ID:StartTime CONTENT={{!NOW:hh:nn}}
PROMPT "Enter Duration" !VAR1

'Use 'EVAL()' to avoid hh and nn to be treated like Strings for [00-09]:
SET !VAR2 EVAL("var x='{{!NOW:hh}}'*1; x;")
SET !VAR3 EVAL("var x='{{!NOW:nn}}'*1; x;")
'PROMPT !VAR2:<SP>{{!VAR2}}<BR>!VAR3:<SP>{{!VAR3}}
ADD !VAR3 {{!VAR1}}

SET nn EVAL("var d='{{!VAR3}}'; var x; if (d>=60) {x=d-60;} else {x=d;}; x;")
SET hh EVAL("var d='{{!VAR3}}'; var x; if (d>=60) {x=1;} else {x=0;}; x;")
ADD hh {{!VAR2}}

'Add an extra Zero for hh=[0-9] and nn=[0-9]:
SET ExtraZeroH EVAL("var d='{{hh}}'; var x; if (d<10) {x=0;} else {x='';}; x;")
SET ExtraZeroM EVAL("var d='{{nn}}'; var x; if (d<10) {x=0;} else {x='';}; x;")
SET FinishTime {{ExtraZeroH}}{{hh}}:{{ExtraZeroM}}{{nn}}

PROMPT !NOW:<SP>{{!NOW:hh:nn}}<BR>!VAR1:<SP>{{!VAR1}}<BR>!VAR2:<SP>{{!VAR2}}<BR>!VAR3:<SP>{{!VAR3}}<BR>hh:<SP>{{hh}}<BR>nn:<SP>{{nn}}<BR>ExtraZeroH:<SP>_{{ExtraZeroH}}_<BR>ExtraZeroM:<SP>_{{ExtraZeroM}}_<BR>=><SP>FinishTime:<SP>{{FinishTime}}

TAG POS=1 TYPE=INPUT:TEXT FORM=ID:eng_stats ATTR=ID:FinishTime CONTENT={{FinishTime}}
Tested on iMacros v8.8.2 for FF, on Pale Moon v24.7.2 (=FF32), WinXP SP3.
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
alex4478
Posts: 22
Joined: Tue Oct 15, 2013 7:56 pm

Re: Adding minutes to !NOW

Post by alex4478 » Tue Sep 16, 2014 8:37 am

That worked just fine. Some durations are over 60 mins, but not very often.

I'd like to say "Thank you".
chivracq
Posts: 9004
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Adding minutes to !NOW

Post by chivracq » Tue Sep 16, 2014 9:22 am

alex4478 wrote:That worked just fine. Some durations are over 60 mins, but not very often.

I'd like to say "Thank you".
OK then, I've extended the Duration till 120 min:

Code: Select all

VERSION BUILD=8820413 RECORDER=FX
TAB T=1

TAG POS=1 TYPE=INPUT:TEXT FORM=ID:eng_stats ATTR=ID:StartTime CONTENT={{!NOW:hh:nn}}
PROMPT "Enter Duration" !VAR1

'Use 'EVAL()' to avoid hh and nn to be treated like Strings for [00-09]:
SET !VAR2 EVAL("var x='{{!NOW:hh}}'*1; x;")
SET !VAR3 EVAL("var x='{{!NOW:nn}}'*1; x;")
'PROMPT !VAR2:<SP>{{!VAR2}}<BR>!VAR3:<SP>{{!VAR3}}
ADD !VAR3 {{!VAR1}}

'Duration up to max 60 min:
'SET nn EVAL("var d='{{!VAR3}}'; var x; if (d>=60) {x=d-60;} else {x=d;}; x;")
'SET hh EVAL("var d='{{!VAR3}}'; var x; if (d>=60) {x=1;} else {x=0;}; x;")
'Duration up to max 120 min:
SET nn EVAL("var d='{{!VAR3}}'; var x; if (d>=120) {x=d-120;} else if (d>=60) {x=d-60;} else {x=d;}; x;")
SET hh EVAL("var d='{{!VAR3}}'; var x; if (d>=120) {x=2;} else if (d>=60) {x=1;} else {x=0;}; x;")
ADD hh {{!VAR2}}
'Rmk: FinishTime going over Midnight not handled...

'Add an extra Zero for hh=[0-9] and nn=[0-9]:
SET ExtraZeroH EVAL("var d='{{hh}}'; var x; if (d<10) {x=0;} else {x='';}; x;")
SET ExtraZeroM EVAL("var d='{{nn}}'; var x; if (d<10) {x=0;} else {x='';}; x;")
SET FinishTime {{ExtraZeroH}}{{hh}}:{{ExtraZeroM}}{{nn}}

PROMPT !NOW:<SP>{{!NOW:hh:nn}}<BR>!VAR1:<SP>{{!VAR1}}<BR>!VAR2:<SP>{{!VAR2}}<BR>!VAR3:<SP>{{!VAR3}}<BR>hh:<SP>{{hh}}<BR>nn:<SP>{{nn}}<BR>ExtraZeroH:<SP>_{{ExtraZeroH}}_<BR>ExtraZeroM:<SP>_{{ExtraZeroM}}_<BR>=><SP>FinishTime:<SP>{{FinishTime}}

TAG POS=1 TYPE=INPUT:TEXT FORM=ID:eng_stats ATTR=ID:FinishTime CONTENT={{FinishTime}}
Tested on iMacros v8.8.2 for FF, on Pale Moon v24.7.2 (=FF32), WinXP SP3.

The PROMPT included is for Debugging obviously, you comment it out to disable it...

And I hope you understand what my Script does and how it works...
Tricky part were the Calculations with Hours and/or Minutes with a Zero as the first Digit because iMacros then treats "05" as a String and not as a Number, which leads to "05+20"=0520 instead of =25...

A good Exercise for you would be to adapt my Script to extend the Duration to 180 min...! :idea:
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
Post Reply