Restlaufzeit Waschmaschine (Zeit addieren?)

Post your questions and help other users.

Moderator: Martin

User avatar
yogi108
Posts: 100
Joined: 09 Nov 2016 08:00
Contact:

Re: Restlaufzeit Waschmaschine (Zeit addieren?)

Post by yogi108 » 18 Oct 2017 15:29

Jennes wrote:Hallo yogi108,
hallo Desmanto,
...

Die globalen Variablen nutze ich nur, um nicht den Überblick zu verlieren und gleichzeitg die resultierenden Werte im Blick zu behalten. Oder sind die nicht-globalen Variablen irgendwo sichtbar??


*Der einzige kosmetische Fehler den ich noch habe, ist, dass die Restlaufzeit in der Statusbar mit h m s und ms angezigt wird. Mir wäre lieber, dass nur auf h und m zu beschränken. Wie mache ich das denn?
Hi,

Die globalen Variablen überdauern auch das Ausschalten des Handys, für das ist es gedacht!
Alle temporären Variablen, Zwischenrechnung etc., kannst Du mit der Debug condition ansehen - einfach an der
Stelle wo Du sehen willst, was gerade da ist, diese debug condition reinhängen.


Die duration zeigt immer die voll verfügbare Zeit an - bei Jahren glaube ich nicht, aber zumindest Tage.
Eine Abhilfe geht als regex, Vorsicht, ich bein kein Profi!
Desmanto?

Code: Select all

differenz=getDurationString(dat2-dat1);
restzeit=replaceAll(differenz,'( [0-9]{0,3}ms)', '');
Das schneidet die Millisekunden raus.

Danach nochmal mit dem restzeit folgendes wegen der Sekunden:

Code: Select all

restzeit=replaceAll(restzeit,'(.*)( [0-9]{0,2}s)', '');

Das wäre nur eine Zeile, wie gesagt ich bin kein Profi, liefert aber zusätzlich "null" für nicht gefundene Werte,
also wenn z.B. keine Sekunden oder Millisekunden in dem String vorkommen:

Code: Select all

restzeit=replaceAll(restzeit,'(.*)( [0-9]{0,2}s [0-9]{0,3}ms)|( [0-9]{0,3}ms)|( [0-9]{0,2}s)', '$1');
Unter https://regexr.com macht er keine Probleme, vielleicht weiß wer einen besseren (einfacheren) Weg.

LG
"You cannot know the meaning of your life until you are connected to the power that created you.”
Shri Mataji Nirmala Devi, founder of Sahaja Yoga

Jennes
Posts: 21
Joined: 19 May 2017 12:22

Re: Restlaufzeit Waschmaschine (Zeit addieren?)

Post by Jennes » 18 Oct 2017 18:24

Supergeil!

:D

sowas bekomme ich echt nicht hin. Für das Arbeiten mit einem Script fehlt mir einfach das Talent - umso mehr herzlichen Dank!

LG

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Restlaufzeit Waschmaschine (Zeit addieren?)

Post by Desmanto » 19 Oct 2017 04:03

I have hard time to understand the flow, since I haven't started studying German. Need google translate a lot. So I will just directly go to the main problem, to show the time only in hours and minutes.

I just know there is function getDurationString(). :D I faced the same problem before, to show my study app time in minutes only (no hour, no second). I use dateformat to parse it properly. So here you can have another 2 ways to solve it.

First you can still use getDurationString(), but before you pass the value to it, divide the value by 60000 and multiply by 60000 again. Why? because division in automagic will always happen in integer, unless we put decimal point (divide by 60000.0 will give 1 decimal point). So divide by 60000 will remove all seconds and miliseconds point. But we need to multiply it back by 60000 to get the original value (after truncated). The formula for the restzeit becomes

Code: Select all

restzeit = getDurationString( (global_WMEnde - triggertime) / 60000 * 60000 );
You can use this method to round any kind of number on certain base point. Example you want to round by 7, you can divide by 7 and multiply by 7.

Second, if you need custom text for hours and minutes, it can't be done using above method. Since it will only shown as "1h 23m". If you need to show as "1 hour 23 minutes", you have to use dateformat. But dateformat will still be affected by your timezone. If you are using UTC+2, all your time shown will be added 2 hours. We need to show it as UTC timezone (UTC+0). You can subtract the time without using getDurationString(). Then show the dateformat.

Code: Select all

restzeit = global_WMEnde - triggertime;
restzeit = "{restzeit,dateformat,timezone,UTC,H 'hours' mm 'minutes'}";
I use 2 lines so easier to understand, but you can combine to single line if you want.

Code: Select all

restzeit = "{global_WMEnde - triggertime,dateformat,timezone,UTC,H 'hours' mm 'minutes'}";
You can customize the 'hours' and 'minutes' to your need. I don't really care for plural s (grammatical mistake), since I don't think it will be a big problem here.

I think maybe Martin should extend the function getDurationString() so it can accept custom dateformat.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

User avatar
yogi108
Posts: 100
Joined: 09 Nov 2016 08:00
Contact:

Re: Restlaufzeit Waschmaschine (Zeit addieren?)

Post by yogi108 » 19 Oct 2017 07:04

@Desmanto

Thanks again for your valuable input. Accordingly to your information I updated the flow and will soon put it online.

regards,
"You cannot know the meaning of your life until you are connected to the power that created you.”
Shri Mataji Nirmala Devi, founder of Sahaja Yoga

Post Reply