GithubHelp home page GithubHelp logo

Comments (4)

MLopezJ avatar MLopezJ commented on June 26, 2024

How to represent date in Json Schema?

Using the keyword type as string and the format keyword as date-time

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "$id": "https://github.com/NordicSemiconductor/lwm2m-types-js/blob/saga/LwM2MDocument.schema.json",
  "title": "LwM2M JSON Schema",
  "description": "JSON schema for expressing LwM2M resources as JSON",
  "properties": {
    "6": {
      "properties": {
        "5": {
          "type": "string",
          "format": "date-time",
          "title": "Timestamp",
        },
      },
    },
  },
}

More info

What is the expected value according to LwM2M XML definition?

2 examples:

Object 6

<Item ID="5">
  <Name>Timestamp</Name>
  <Operations>R</Operations>
  <MultipleInstances>Single</MultipleInstances>
  <Mandatory>Mandatory</Mandatory>
  <Type>Time</Type>
  <RangeEnumeration></RangeEnumeration>
  <Units></Units>
  <Description><![CDATA[The timestamp of when the location measurement was performed.]]></Description>
</Item>

Object 3303

<Item ID="5518">
  <Name>Timestamp</Name>
  <Operations>R</Operations>
  <MultipleInstances>Single</MultipleInstances>
  <Mandatory>Optional</Mandatory>
  <Type>Time</Type>
  <RangeEnumeration></RangeEnumeration>
  <Units></Units>
  <Description>The timestamp of when the measurement was performed.</Description>
</Item>

What is the LwM2M definition of Time type ?

Unix Time. A signed integer representing the number of seconds since Jan 1st, 1970 in the UTC time zone.

LwM2M documentation pag 96

How does the provided value look like in the shadow?

Object 3303 prop 5518: Temperature

{
  "Timestamp": "2022-10-07T13:33:22Z"
}

Object 6, prop 5: Location

{
  "Timestamp": "1970-01-01T00:00:00Z",
}

Problem

The expected format according to the standard is UNIX TIME but provided value in shadow follows ISO 8601 date-time

from lwm2m-types-js.

MLopezJ avatar MLopezJ commented on June 26, 2024

How to represent UNIX TIME in Json Schema ?

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "$id": "https://github.com/NordicSemiconductor/lwm2m-types-js/blob/saga/LwM2MDocument.schema.json",
  "title": "LwM2M JSON Schema",
  "description": "JSON schema for expressing LwM2M resources as JSON",
  "properties": {
    "6": {
      "properties": {
        "5": {
          "type": "integer",
          "minimum": -864e12,
          "maximum": 864e12,
          "title": "Timestamp",
        },
      },
    },
  },
}

stackoverflow

Because UNIX TIME definition says: it is the number of seconds between a particular date and the Unix Epoch unixtimestamp

Other alternative could be add format keyword as date-time in object definition

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "$id": "https://github.com/NordicSemiconductor/lwm2m-types-js/blob/saga/LwM2MDocument.schema.json",
  "title": "LwM2M JSON Schema",
  "description": "JSON schema for expressing LwM2M resources as JSON",
  "properties": {
    "6": {
      "properties": {
        "5": {
          "type": "integer",
          "minimum": -864e12,
          "maximum": 864e12,
          "title": "Timestamp",
          "format": "date-time",
        },
      },
    },
  },
}

However, this is not a real solution because "format": "date-time" only work on string type and LwM2M described value as integer:

here is described another alternative using ajv, however that does not work neither because the expected value is UNIX TIME format and not ISO 8601 format.

from lwm2m-types-js.

github-actions avatar github-actions commented on June 26, 2024

🎉 This issue has been resolved in version 2.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

from lwm2m-types-js.

coderbyheart avatar coderbyheart commented on June 26, 2024

@MLopezJ

How does the provided value look like in the shadow?

This is not relevant for this project.

from lwm2m-types-js.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.