Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix RangeError: Invalid time value #364

Merged
merged 8 commits into from
Oct 16, 2024
Merged

Fix RangeError: Invalid time value #364

merged 8 commits into from
Oct 16, 2024

Conversation

palagdan
Copy link
Collaborator

@palagdan palagdan commented Oct 8, 2024

Fix #363

Copy link

netlify bot commented Oct 8, 2024

Deploy Preview for s-forms-kbss ready!

Name Link
🔨 Latest commit 835620a
🔍 Latest deploy log https://app.netlify.com/sites/s-forms-kbss/deploys/67100dc3e2df5f00083e253c
😎 Deploy Preview https://deploy-preview-364--s-forms-kbss.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@palagdan palagdan requested a review from blcham October 8, 2024 13:02
@palagdan
Copy link
Collaborator Author

palagdan commented Oct 8, 2024

@blcham

I also found an error when I clicked on some of the select inputs (not all).

select-error-length-1
select-error-length

@blcham
Copy link
Collaborator

blcham commented Oct 8, 2024

@palagdan thanks, i created #365

@blcham
Copy link
Collaborator

blcham commented Oct 8, 2024

Regarding timestamp:
image

See also how it used to work:
#366

@blcham
Copy link
Collaborator

blcham commented Oct 8, 2024

Regarding timestamp, i can think of two variants:

A)

{
      "label": "Timestamp in db",
      "@id": "http://vfn.cz/ontologies/fss-form/timestamp-in-db-q",
      "has-layout-class": ["timestamp"],
      "has_answer": "http://onto.fel.cvut.cz/ontologies/custom/model/instance#instance123456-a",
      "@type": "doc:question"
    },

or

B)

{
  "label": "Timestamp in db",
  "@id": "http://vfn.cz/ontologies/fss-form/timestamp-in-db-q",
  "has-layout-class": ["datetime"],
  "has_answer": "http://onto.fel.cvut.cz/ontologies/custom/model/instance#instance123456-a",
  "@type": "doc:question",
  "timestamp-format": "epoch-milliseconds", // or "epoch-seconds"
  "form:has-datatype": {
    "@id": "xsd:integer"
  }
}

@blcham
Copy link
Collaborator

blcham commented Oct 8, 2024

@palagdan unless you have better idea I would go with variant B). It seems to me nice solution as "datetime" is rather indicating frontend properties of the component (= layout-class) not how it is stored in RDF .

There are two fundamental properties:

"has-layout-class": ["datetime"],
"timestamp-format": "epoch-milliseconds", // or "epoch-seconds"

Optional property is (it is default and it should work without it):

  "form:has-datatype": {
    "@id": "xsd:integer"
  }

You can see my whole reasoning about it in chatGPT -- https://chatgpt.com/share/67054eed-155c-8006-9c22-ea64d61cde40

@palagdan
Copy link
Collaborator Author

@blcham
Could you please check the implementation? The empty answer appears the same because the timestamp uses a datetime layout, but it stores the value in epoch milliseconds.

@palagdan
Copy link
Collaborator Author

palagdan commented Oct 14, 2024

@blcham
datetime_bug

I investigated and found out the the problem is with jsonld-utils library that returns incorrect responses in hasValue function. That is why date and time has layout date, time and datetime because hasValue returns true.

here:

function hasValue(object, property, value) {
  return object[property] !== undefined && object[property] !== null && (object[property] === value || object[property]['@id'] === value || object[property].indexOf && object[property].indexOf(value) !== -1);
}

When object[property] is "datetime" and value is "date", the expression object[property].indexOf(value) returns 0 because the substring "date" starts at index 0 of the string "datetime". When value is time, indexOf(value) returns 4.
The function should call indexOf only on arrays, not strings.

I suggest refactoring out this library in other places as well, as it may introduce bugs elsewhere.

@palagdan palagdan requested a review from blcham October 14, 2024 15:37
@blcham
Copy link
Collaborator

blcham commented Oct 16, 2024

@palagdan thanks for finding the issue, @ledsoft fixed it in new version -- 0.1.3.

@palagdan
Copy link
Collaborator Author

palagdan commented Oct 16, 2024

@blcham

I removed DATETIME_NUMBER_FORMAT because it was a poor workaround for the numerical representation of the date. The resolveDateTimeFormat function should not need to handle this, as it deals with layouts, not the internal representation of the date. Now it works as expected:

  • If the layout has a timestamp format, it will save the date in milliseconds, allowing for the combination of the layout and this format.
  • I fixed the number conversion to the date in the last commit, making it possible to retrieve the date from the number.
  • I saved the error state so we can discuss how to display it, or if we should display it at all.
  • If there is no value, an error is not thrown, and the input shows the date template instead.

You can have a look at it after merging this: #371

@blcham blcham force-pushed the 363-invalid-time-value branch from 542f288 to 835620a Compare October 16, 2024 19:02
@blcham
Copy link
Collaborator

blcham commented Oct 16, 2024

Good job!

@blcham blcham merged commit cbbae1f into master Oct 16, 2024
7 checks passed
@blcham blcham deleted the 363-invalid-time-value branch October 16, 2024 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RangeError: Invalid time value
2 participants