Stopping timer via API adds 2 extra hours to the timer. Why?

Hello!

How to reproduce the problem that I have:

  1. use Clockify via a browser to run a timer.
  2. use this powershell code to stop that timer:
$apiKey = your_api_key
$workspaceId = your_workspace_id
$userId = your_user_id

$timeEntryUrl = "https://api.clockify.me/api/v1/workspaces/$workspaceId/user/$userId/time-entries"


$headers = @{
    'X-Api-Key' = $apiKey
    'Content-Type' = 'application/json'
}

$endTime = Get-Date -Format "yyyy-MM-ddTHH:mm:ssZ"

write-host("endTime", $endTime)

$timeEntryData = @{
    "end" = $endTime
}

$timeEntryDataJson = $timeEntryData | ConvertTo-Json

$response = Invoke-RestMethod -Uri $timeEntryUrl -Method Patch -Headers $headers -Body $timeEntryDataJson

Every time when I stop the timer using the code above Clockify adds 2h to the duration of the time entry. So, if I run a timer, wait 10 sec and then use the code above the Clockify will create a time entry with a duration of 02:00:10.

This started happening today. There was no such a problem last week.

My Windows OS Time Zone is +2h.
When I set the Time Zone of my Clockify accountt to +0h the same is happening - Clockify adds 2h to the duration of the time entry.
If I set the TimeZone of my Windows OS to +3h, the Clockify adds 3h to the duration of the time entry, no matter what is the Time Zone of my Clockify account.

Hello there,

It would seem like

$endTime = Get-Date -Format "yyyy-MM-ddTHH:mm:ssZ"

Converts the local time and simply adds a Z to the end, which may not accurately represent the UTC time.

To accurately provide the UTC time, please replace

$endTime = Get-Date -Format "yyyy-MM-ddTHH:mm:ssZ"

With

$endTime = [DateTime]::UtcNow | get-date -Format "yyyy-MM-ddTHH:mm:ssZ"

Credit to user8691702 from this thread

If you are still experiencing issues, please contact support@clockify.me

All the best

2 Likes

Thank you.
Now the problem is solved.