Uploaded image for project: 'Qbs ("Cubes")'
  1. Qbs ("Cubes")
  2. QBS-1768

Date() in the JavaScriptCommand not working properly

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Not Evaluated
    • 2.2.1
    • 2.1.2
    • API: JavaScript
    • None
    • Windows
    • 68eceb304 (2.2)

    Description

      Cannot get current time, if Date() object created without any argument.

      Code below working fine in Qbs 1.23, but in the latest version it becomes a time machine:

      timestamp.h generated by Qbs 2.1.2:

      #pragma once
      // timestamp: Sun Nov 15 2392
      #define TIMESTAMP 13344641115
      

      Test project:

      import qbs.TextFile
      
      CppApplication {
          name: "TestApp"
          files: "main.cpp"
      
          cpp.includePaths: [
              product.destinationDirectory,   // for timestamp
          ]
      
          // generate timestamp header
          Rule {
              alwaysRun: true
              multiplex: true
              Artifact {
                  filePath: "timestamp.h"
                  fileTags: "hpp"
              }
              prepare: {
                  var cmd = new JavaScriptCommand();
                  cmd.description = "generating " + output.fileName;
                  cmd.sourceCode = function() {
                      var f = new TextFile(output.filePath, TextFile.WriteOnly);
                      const d = new Date();
                      const utc = Math.floor(d.getTime() / 1000);  // in seconds
                      try {
                          f.writeLine("#pragma once");
                          f.writeLine("// timestamp: " + d.toDateString())
                          f.writeLine("#define TIMESTAMP " + utc)
                      } finally {
                          f.close();
                      }
                  };
                  return [cmd];
              }
          }
      }
      

      Attachments

        For Gerrit Dashboard: QBS-1768
        # Subject Branch Project Status CR V

        Activity

          People

            kandeler Christian Kandeler
            esaulenka Alexey
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes