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

fixDatetimeNanos() doesn't manage date time without nano precision #94

Closed
fredmef opened this issue Sep 27, 2021 · 0 comments · Fixed by #96
Closed

fixDatetimeNanos() doesn't manage date time without nano precision #94

fredmef opened this issue Sep 27, 2021 · 0 comments · Fixed by #96
Milestone

Comments

@fredmef
Copy link

fredmef commented Sep 27, 2021

Steps to reproduce:
List the minimal actions needed to reproduce the behavior.

  1. Create a task using postTasks() through TasksService
  2. The date time returned by postTasksWithHttpInfo() is in second precision

Expected behavior:
Describe what you expected to happen.

When the date time returned by postTasksWithHttpInfo() is in second, fixDatetimeNanos() doesn't crash.

fixDatetimeNanos() shall check the size returned by explode() before accessing the array elements.

static function fixDatetimeNanos(string $date) : string {
    $dateParts = explode(".", $date);
    $nanosZ = $dateParts[1];
    $posZ = strpos($nanosZ, 'Z');
    if (strlen($nanosZ) > 9) {
        $converted = $dateParts[0] . "." . substr($nanosZ, 0, 8);
        if ($posZ > 0) {
            $converted .= "Z";
        }
        return $converted;
    } else {
        return $date;
    }
}

Actual behavior:
Describe What actually happened.

Here is the PHP log for postTasks():

Notice: Undefined offset: 1 in InfluxDB2\ObjectSerializer::fixDatetimeNanos() (line 340 of /var/www/html/vendor/influxdata/influxdb-client-php/src/InfluxDB2/ObjectSerializer.php).
InfluxDB2\ObjectSerializer::fixDatetimeNanos('2021-09-27T07:31:07Z') (Line: 272)
InfluxDB2\ObjectSerializer::deserialize('2021-09-27T07:31:07Z', '\DateTime', NULL) (Line: 323)
InfluxDB2\ObjectSerializer::deserialize(Object, '\InfluxDB2\Model\Task', Array) (Line: 4607)
InfluxDB2\Service\TasksService->postTasksWithHttpInfo(Object, NULL) (Line: 4549)
InfluxDB2\Service\TasksService->postTasks(Object) (Line: 99)

Specifications:

  • Client Version: 2.2.0
  • InfluxDB Version: 2.0.8
  • Platform: Docker (Drupal 9)
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 a pull request may close this issue.

2 participants