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

String is always converted to DateTime under certain conditions #10

Closed
AutoComplete1 opened this issue Jan 12, 2021 · 2 comments
Closed
Labels
bug Something isn't working

Comments

@AutoComplete1
Copy link

AutoComplete1 commented Jan 12, 2021

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
@v2kiran v2kiran added the bug Something isn't working label Jan 13, 2021
@rdbartram
Copy link

rdbartram commented Jan 18, 2021

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)
        }

@v2kiran
Copy link
Owner

v2kiran commented Aug 12, 2021

fixed in v2.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants