Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. Blockly
    5. "Zeitdifferenz formatieren" liefert "falsches" Format

    NEWS

    • Neuer Blog: Fotos und Eindrücke aus Solingen

    • ioBroker@Smart Living Forum Solingen, 14.06. - Agenda added

    • ioBroker goes Matter ... Matter Adapter in Stable

    "Zeitdifferenz formatieren" liefert "falsches" Format

    This topic has been deleted. Only users with topic management privileges can see it.
    • P
      Paddex last edited by

      Hallo an alle,

      ich habe letzte Woche den (für mich) neuen Block "Zeitdifferenz formatieren" entdeckt, musste aber feststellen, dass das Format nicht richtig angezeigt wird.

      06:09 -> 6 Minuten 9 Sekunden wird mit falsch angezeit:
      44aa1776-ebcf-499f-a9bf-cbeacbdb3215-Screenshot Blockly Fehler Zeit berechnen.png

      Formatierung ist:
      Screenshot Blockly Fehler Formatierung.png

      Er entfernt die Nullen! Was bei der Minute noch ok wäre, ist aber bei den Sekunden absolut falsch.

      Leider ist ein umformatieren mit bem Konvertierungsblock Datum/Zeit auch nicht möglich.
      Screenshot 2024-05-10 155905.png
      Wenn die Zeitdifferenz negativ wird, dann wir z.B. 0-1:55 angezeigt. Dann ist eine Auswertung ob negativ nicht mehr möglich.

      Schreibe hier, weil ich nicht genau weiß, wo der Bug zu melden ist. Hinweise nehme ich gerne.

      Danke an die Programmieren, ioBroker ist echt super. Danke für eure Arbeit.

      Gruß

      Maik

      paul53 3 Replies Last reply Reply Quote 0
      • paul53
        paul53 @Paddex last edited by paul53

        @paddex sagte: wo der Bug zu melden ist.

        Als Issue auf Github.

        Ich konnte es nachvollziehen (Version 8.3.0).

        Blockly_temp.JPG

        Negative Werte werden offenbar auch falsch berechnet.

        1 Reply Last reply Reply Quote 1
        • paul53
          paul53 @Paddex last edited by paul53

          @paddex
          Ich habe die Funktion aus dem Javascript-Adapter mal nachvollzogen: Es werden führende Nullen erzeugt. Lediglich die Berechnung von negativen Differenzen ist falsch.

                 function formatDiffTime(diff, format) {
                     if (!format) {
                         format = 'hh:mm:ss';
                     }
          
                     let text = format;
          
                     log(`formatTimeDiff(format=${format}, diff=${diff})`);
          
                     const second = 1000;
                     const minute = 60 * second;
                     const hour = 60 * minute;
                     const day = 24 * hour;
          
                     if (/DD|TT|ДД|D|T|Д/.test(text)) {
                         const days = Math.floor(diff / day);
          
                         text = text.replace(/DD|TT|ДД/, days < 10 ? `0${days}` : days);
                         text = text.replace(/D|T|Д/, days);
          
                         log(`formatTimeDiff(format=${format}, text=${text}, days=${days})`);
          
                         diff -= days * day;
                     }
          
                     if (/hh|SS|чч|h|S|ч/.test(text)) {
                         const hours = Math.floor(diff / hour);
          
                         text = text.replace(/hh|SS|чч/, hours < 10 ? `0${hours}` : hours);
                         text = text.replace(/h|S|ч/, hours);
          
                         log(`formatTimeDiff(format=${format}, text=${text}, hours=${hours})`);
          
                         diff -= hours * hour;
                     }
          
                     if (/mm|мм|m|м/.test(text)) {
                         const minutes = Math.floor(diff / minute);
          
                         text = text.replace(/mm|мм/, minutes < 10 ? `0${minutes}` : minutes);
                         text = text.replace(/m|м/, minutes);
          
                         log(`formatTimeDiff(format=${format}, text=${text}, minutes=${minutes})`);
          
                         diff -= minutes * minute;
                     }
          
                     if (/ss|сс|мм|s|с/.test(text)) {
                         const seconds = Math.floor(diff / second);
          
                         text = text.replace(/ss|сс/, seconds < 10 ? `0${seconds}` : seconds);
                         text = text.replace(/s|с/, seconds);
          
                         log(`formatTimeDiff(format=${format}, text=${text}, seconds=${seconds})`);
          
                         diff -= seconds * second;
                     }
          
                     log(`formatTimeDiff(format=${format}, text=${text})`);
          
                     return text;
                 }
          
          log(formatDiffTime(369000, 'mm:ss'));
          


          Blockly übergibt das falsche Format an Javascript:

          console.info(formatTimeDiff(diff, 'm:s'));
          console.info(formatTimeDiff((0 - diff), 'm:s'));
          

          EDIT: PR für Korrektur bei negativen Werten ist erstellt.

          haus-automatisierung 1 Reply Last reply Reply Quote 0
          • paul53
            paul53 @Paddex last edited by paul53

            @paddex sagte: Formatierung ist:

            Das wird von Blockly falsch übergeben, aber anwenderformatiert funktioniert es mit positiven Differenzen:

            Blockly_temp.JPG

            EDIT: Neue Erkenntnis: "mm:ss" und "m:s" sind vertauscht:

            Blockly_temp.JPG

            P 1 Reply Last reply Reply Quote 0
            • haus-automatisierung
              haus-automatisierung Developer Most Active @paul53 last edited by

              @paul53 sagte in "Zeitdifferenz formatieren" liefert "falsches" Format:

              Blockly übergibt das falsche Format an Javascript:

              Oh man wie blöde, war alles richtig, nur die Übersetzungen waren vertauscht. Danke!

              1 Reply Last reply Reply Quote 0
              • P
                Paddex @paul53 last edited by Paddex

                @paul53 said in "Zeitdifferenz formatieren" liefert "falsches" Format:

                anwenderformatiert funktionier

                Hallo,

                "anwenderformatiert" war leider auch nicht die Lösung wegen der negativ Darstellung.

                Was mir gerade aufgefallen ist:
                fe9d95b3-8298-40d2-8546-a4eb957a2b55-grafik.png

                positiv 6 min 9 sek -> negativ 7 min 51 sek ??
                Wo ist mein Denkfehler?

                Ansonsten ist der Block richtig gut und spart das selber zusammstellen der Zeit.

                Gruß Maik

                paul53 2 Replies Last reply Reply Quote 0
                • paul53
                  paul53 @Paddex last edited by

                  @paddex sagte: nicht die Lösung wegen der negativ Darstellung.

                  Das ist in der nächsten Version korrigiert.

                  haus-automatisierung 1 Reply Last reply Reply Quote 1
                  • haus-automatisierung
                    haus-automatisierung Developer Most Active @paul53 last edited by

                    @paul53 sagte in "Zeitdifferenz formatieren" liefert "falsches" Format:

                    Das ist in der nächsten Version korrigiert.

                    Genau, ich hab noch 1-2 Bugfixes heute Abend und dann gebe ich die nächste Version frei.

                    paul53 1 Reply Last reply Reply Quote 0
                    • paul53
                      paul53 @haus-automatisierung last edited by paul53

                      @haus-automatisierung
                      Anmerkung: formatDate() kann auch Zeitdifferenzen formatieren (Werte < 1.1.2000), liefert aber bei negativen Werten auch ein falsches Ergebnis: -369000 --> "53:51".

                      1 Reply Last reply Reply Quote 0
                      • paul53
                        paul53 @Paddex last edited by

                        @paddex sagte: negativ 7 min 51 sek ??

                        JS 8.3.1:

                        Blockly_temp.JPG

                        1 Reply Last reply Reply Quote 1
                        • First post
                          Last post

                        Support us

                        ioBroker
                        Community Adapters
                        Donate

                        571
                        Online

                        31.7k
                        Users

                        79.9k
                        Topics

                        1.3m
                        Posts

                        3
                        10
                        427
                        Loading More Posts
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes
                        Reply
                        • Reply as topic
                        Log in to reply
                        Community
                        Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
                        The ioBroker Community 2014-2023
                        logo