Menu

time object error or parameter?

Help
Ronny H
2008-10-29
2012-12-14
  • Ronny H

    Ronny H - 2008-10-29

    In the demo project is a time object in the left edge. When the minutes only has one number the browser show this number without the 0. The same is on the date object. Example:

    Date: 1/1/2008
    Time: 9:5

    I want this

    Date: 01/01/2008
    Time: 09:05

    What is the correct setting for this object when i try to show the 0 before the number?

     
    • jef2000

      jef2000 - 2008-11-01

      Hi,

      No easy solution for this yet. Removing 0 with regular expressions is easy, but inserting them is not. Perhaps linknx could always put the zero, so that knxweb can remove it if needed.

      A workaround solution could be to put 4 text controls at the same place:
      Format1=0$3.0$2.$1
      Pattern1=(\d+)-(\d)-(\d)
      Format2=$3.$2.$1
      Pattern2=(\d+)-(\d\d)-(\d\d)
      Format3=$3.0$2.$1
      Pattern3=(\d+)-(\d)-(\d\d)
      Format4=0$3.$2.$1
      Pattern4=(\d+)-(\d\d)-(\d)

      When a pattern doesn't match, nothing is displayed. Since only one of the 4 will match, you'll always get it right.
      The first one will display if day and month have one digit and add the leading 0.
      The second one will display if day and month have two digit.
      The third one will display if only month has one digit and add the leading 0.
      The fourth one will display if only day has one digit and add the leading 0.

      It's not a very nice solution.... , but it works.
      I'll try to find something better for next release.

      Regards,

      Jean-François

       
    • Ronny H

      Ronny H - 2008-11-02

      Hi,

      i take the 4 text controls at the same place, and i try to find another way. Now i fixed my problem with a code change in the linknx project. Then the date and time value will always get a two digit value.

      in the file > src/objectcontroller.cpp <

      #include <iomanip>
      using namespace std;

      and in function > std::string TimeObjectValue::toString() < i replaced the line

      out << hour_m << ":" << min_m << ":" << sec_m;

      with

      out << setfill('0') << setw(2) << hour_m << ":" << setw(2) << min_m << ":" << sec_m;

      and in function > std::string DateObjectValue::toString() < i replaced the line

      out << year_m+1900 << "-" << month_m << "-" << day_m;

      with

      out << year_m+1900 << "-" << setfill('0') << setw(2) << month_m << "-" << setw(2) << day_m;

      save and compile.

      Now the date and time format is exactly the same that i wanted.

       
    • jef2000

      jef2000 - 2008-11-02

      Hi,

      Of course, if you can recompile it yourself, everything is possible. But since I'm used to people asking for binary packages, I always try to find quick solution working with existing binaries ;-)

      I think I'll add your change in the next release. If somebody ir relying on the old format (without the leading zero), I hope he will read this forum and reply. If I don't hear anything, I'll take your change in.

      But this leads to a more general question. Is there a need for more flexibility in the formatting of object values on the XML interface. And if yes, what would be the best solution.

      Regards,

      Jean-François

       
      • Ronny H

        Ronny H - 2008-11-02

        Here a three little examples where i think thats more flexibility is good:

        * Temperature: my analog input unit (ABB AE/S with four PT100 sensors) give me a float value. The knxweb shows this value with no problems. Now i need only one or no number after the decimal places.

        * Lux: a weather station can send very different light intensity values (depending on manufactor), sometimes i need no number after the decimal places.

        * Counter: a electric meter can send 2 numbers after the decimal places. But it looks not good, when the value is only a integer.

        With a extra parameter the values can show every time all numbers. Its not easy to find a simple way. In an other visualization exists a parameter for the number (for and after) the decimal places from the analog value. Can it be possible?

        This post is like a feature request :-)

         
    • jef2000

      jef2000 - 2008-11-02

      Hi,

      The kind of things you describe can already be done with the actual text control.
      You can remove decimal places with:
      Format=$1
      Pattern=(\d+)[.,]?

      Or keep only one decimal place with:
      Format=$1$2
      Pattern=(\d+)([.,]\d)?

      Regards,

      Jean-François

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.