jdhitsolutions / PSWorkItem

A PowerShell 7 module for managing work and personal tasks or to-do items. This module uses a SQLite database to store task and category information. The module is not a full-featured project management solution, but should be fine for personal needs. The module requires a 64-bit Windows or Linux platform.
MIT License
36 stars 5 forks source link

[Bug]: Issue when getting PSWorkItems (Probably due to French date time format) #2

Closed Tuttu closed 2 years ago

Tuttu commented 2 years ago

Describe the problem

I'm running a Windows 10 in French so the date time format is also in French. After adding a PSWorkItem, it is sometimes impossible to retreive it and the following error is displayed instead.

❯ $ New-PSWorkItem -Name 'Remove McAffee and Sophos AV' -Category Application -DaysDue 30
❯ $ Get-PSWorkItem
InvalidArgument: C:\Users\MichaëlDeBona\Documents\PowerShell\Modules\PSWorkItem\0.6.0\functions\public\Get-PSWorkItem.ps1:94
Line |
  94 |              $tasks = ($tasks).Where({[datetime]$_.duedate -le $d})
     |                                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Cannot convert value "16/10/2022 10:07:04" to type "System.DateTime". Error: "String '16/10/2022
     | 10:07:04' was not recognized as a valid DateTime."

WARNING: Failed to find any matching tasks

Howerver, this does work sometimes. Example with this item. The date format is the same but the item is returned correctly.

ID Name                                              Description DueDate             Category Pct
-- ----                                              ----------- -------             -------- ---
 5 Plan meeting to show DaaS to team                             03/08/2022 14:52:52 Intune     0

Whether the due date is in the past or the future does not seem to matter as work items that are set both in the past or in the future either fails to be fetched or are displayed correctly.

For the record, the items have been imported from your MyTask module using the following command: Get-Mytask | % { New-PSWorkItem -Name $_.Name -Category $_.Category -DueDate (Get-Date $_.Duedate) }

Expectation

Whatever the due date set on a PSWorkItem, it should be returned correctly independently to the date time format.

Additional Information

As stated in the title and above, I'm on a French computer. The date format is the following:

❯ $ Get-Date
vendredi 16 septembre 2022 10:19:28

If needed, I can send you a copy of the database file.

PowerShell version

7.2

Platform

Windows 10 Pro or Enterprise

Additional Checks

jdhitsolutions commented 2 years ago

International date handing is always tricky. Let me see what I can do.

Tuttu commented 2 years ago

For some reason, it is working correctly with the MyTask module. Are you handling dates differently? If needed, I can switch to ISO date format (yyyy-MM-dd). Would that help?

jdhitsolutions commented 2 years ago

It could be related to the sqlite database. The datetime is stored as a string. When the psworkitem is created the string is treated as a [datetime] object. I may have to adjust how the string is parsed.

Tuttu commented 2 years ago

Got it. If needed, I'm available for testing if you don't want to bother with using a French (Or any other language) computer. :)

jdhitsolutions commented 2 years ago

I think I have this figured out. I keep forgetting that PowerShell doesn't respect culture when using expansion.

image

I was using Get-Date subexpressions in the SQL query which resulted in a culture mismatch.

Tuttu commented 2 years ago

Awesome! Good to read. :)

jdhitsolutions commented 2 years ago

Cleaning up some other bugs I came across as well.

jdhitsolutions commented 2 years ago

Update the module to v0.7.0 and try again. You might need to run Set-PSWorkItem on tasks to properly update the database. Worse case, remove the tasks with "bad" dates and re-enter them.

jdhitsolutions commented 2 years ago

Or, use the SQLite command to export the database to a json file.

Export-MySQLiteDB -path $PSWorkItemPath -destination dbexport.json

Edit the dates in the JSON file. Then recreate the database.

import-mySQLiteDB -Path .\dbexport.json -Destination $PSWorkItemPathgwio
Tuttu commented 2 years ago

Hello @jdhitsolutions,

Sorry for the late reply. I updated the module to version 0.7 and it fixed the problem without even needing to import the work items again. It looks like they are now working like a charm. 🙂