String is always converted to DateTime under certain conditions
AutoComplete1 opened this issue · comments
Hi,
I have a problem with the latest version of PSLiteDB. When I want to convert a PSCustomObject to a LiteDBBson Object, I always get the following error:
"Clould not convert string to DateTime: Datenschutz"
As I already found out, the problem is the string itself. As soon as the string contains the word DATE, it is recognized as a date. In German data protection means DATEnschutz and after here Date is in the word, it tries to convert the string to a date.
small example code:
Import-Module PSLiteDB
$dbPath = "C:\tmp\test1.db"
New-LiteDBDatabase -Path $dbPath -Verbose
Open-LiteDBConnection -Database $dbPath
New-LiteDBCollection -Collection Event
[String]$mystring = 'Datenschutz'
$myOBJ = [PSCustomObject]@{
MyString = $mystring
}
$myBSON = $myOBJ | ConvertTo-LiteDbBson
I had this issue too.
line 85 in psm1...
# Convert JSON datetime string value to bson datetime values
$bsonobj.GetEnumerator() |
Where-Object {
$_.value.value -match "date|(\d{4})-(\d{2})-(\d{2})T(\d{2})\:(\d{2})\:(\d{2})"
} |
ForEach-Object {
$kvp = $_
$hash[$kvp.key] = [MSJsonDateConverter]::Convert($kvp)
}
fixed in v2.2