javascriptbixby

how to receive JSON time in Bixby concept


I am receiving JSON that includes a time pair in the format:

"_changed": "2020-01-26T00:32:16.282Z"

How do I create a corresponding structure property that parses this into something I can display nicely in a view? Right now I simply have:

  property (_changed){
    type (core.Text)...

But this string is unwieldy and not suitable for display to users. I tried time.DateTimeExpression but that seems to be NL-oriented. How do I manipulate this into something I can display to users in a result view?


Solution

  • The easiest (and possible only) way is to do it in Java Script. There is not any NL training in viv.time can handle that.

    Bixby has JS library that could parse this format, just do the following. Read more about dates library here

    var dates = require('dates')
    var console = require('console')
    module.exports.function = function getToday () {
      var res = dates.ZonedDateTime.parseDateTime("2020-01-26T00:32:16.282Z")
      console.log('res', res)
      return 'works!'
    }
    

    And check the debugger would see the result.

    enter image description here

    The following may not be the best Javascript code, but would get the job done for some non-supported format.

      var str = "2020-01-26T00:32:16.282Z";
      var res = str.split("T")[0].split("-");
      var year = parseInt(res[0]);
      var month = parseInt(res[1]);
      var date = parseInt(res[2]);
    

    You can do the same with hour/minute/second then create and return viv.time object in JS.