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

Certain strings incorrectly identified as dates #202

Closed
markspolakovs opened this issue Nov 5, 2021 · 2 comments
Closed

Certain strings incorrectly identified as dates #202

markspolakovs opened this issue Nov 5, 2021 · 2 comments
Labels
type/bug Unexpected behavior or a feature is broken

Comments

@markspolakovs
Copy link

It looks like the type auto-detection can incorrectly detect certain strings as dates. For example, "foo bar 1.1" is identified as 2001-01-01 - any string in the format aaa aa x.x where a is a letter and x is a number will be identified as 2001-x-x.

Here's the panel JSON:

    {
      "datasource": "JSON API",
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "custom": {
            "align": "auto",
            "displayMode": "auto"
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          }
        },
        "overrides": []
      },
      "gridPos": {
        "h": 9,
        "w": 12,
        "x": 0,
        "y": 0
      },
      "id": 2,
      "options": {
        "showHeader": true
      },
      "pluginVersion": "8.2.3",
      "targets": [
        {
          "cacheDurationSeconds": 300,
          "fields": [
            {
              "jsonPath": "[\"aaa aa 1.1\"]",
              "language": "jsonata"
            }
          ],
          "method": "GET",
          "queryParams": "",
          "refId": "A",
          "urlPath": "/"
        }
      ],
      "title": "Panel Title",
      "type": "table"
    }
@marcusolsson
Copy link
Contributor

Thanks for reporting this! I'm indeed able to reproduce this. It seem that dayjs recognizes the string as a valid date object:

https://github.com/marcusolsson/grafana-json-datasource/blob/779ba3d3bedb160efd0cb15c1bc346d78af58864/src/detectFieldType.ts#L14-L16

After some digging, isValid() apparently doesn't return whether the date is valid, but whether it was parsed correctly.

Think we should instead parse the date as ISO8601. If you have a different time format, then you can always set the type explicitly.

@marcusolsson marcusolsson added type/bug Unexpected behavior or a feature is broken priority/critical-urgent labels Nov 8, 2021
@marcusolsson marcusolsson moved this to In Progress in Grafana plugins Dec 17, 2021
Repository owner moved this from In Progress to Done in Grafana plugins Dec 17, 2021
@marcusolsson
Copy link
Contributor

Fix available in 1.3.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Unexpected behavior or a feature is broken
Projects
None yet
Development

No branches or pull requests

2 participants