mtboren / NewHtmlReport

PowerShell module to easily create functional, somewhat styled HTML reports from data, providing additional functionality to what the base ConvertTo-Html cmdlet provides. Examples at
https://mtboren.github.io/NewHtmlReport/
7 stars 1 forks source link

Issue while trying to sort french formatted dates #2

Open ethermcman opened 6 years ago

ethermcman commented 6 years ago

Hi, I'm starting to use your PoSh module but when I format dates like 'dd/MM/yyyy HH:mm:ss', the jquery tablesorter doesn't correctly sort dates. Is there a way to modify or configure this behaviour in your code? Regards.

mtboren commented 6 years ago

Greetings, @ethermcman -

Mhmm. I'll have a look. With TableSorter, we can definitely define custom code that separates the "sort value" from the "display value". Will post back here with any update.

Cheers,

Matt

ethermcman commented 6 years ago

Hello, Thanks if you can find anything. Cheers.

mtboren commented 6 years ago

Greets, @ethermcman-

So far what I have found: There are some options to consider for meeting your need:

The first two options involve varying levels of further development. Until such development happens, though, how about if we try the third option?

By using a a slightly different and non-ambiguous date format like 'dd MMM yyyy HH:mm:ss' (similar to your original date format, but with MMM for the month, and no slashes), the existing jQuery and Tablesorter code already properly sort the date column. Example:

Get-ChildItem c:\temp\ | Select-Object Mode, `
    @{n="LastWriteTime"; e={$_.LastWriteTime.ToString('dd MMM yyyy HH:mm:ss')}}, Length, Name | `
    New-HtmlReport | Out-File C:\temp\testReport_withNonAmbiguousFrDate.htm

Give that a shot, and see if the results could meet your needs for the current term, until such a time that NewHtmlReport is expanded to include globalization support, won't you? I'll watch for your feedback.

ethermcman commented 6 years ago

Sorry for being late on your update... I've tried to follow your proposal but it did not work. My very actual code:

Import-Module ActiveDirectory
Import-Module NewHtmlReport
$date = ((get-date).AddYears(-1)).ToString('dd MMM yyyy HH:mm:ss')
New-HtmlReport -Title "Utilisateurs AD" `
    -PreContent "<H3>Utilisateurs AD<H3>" `
    -PostContent "<SPAN CLASS='footerInfo'>Généré le $(Get-Date -Format 'dd MMM yyyy HH:mm:ss')</SPAN>" `
    -InputObject (get-aduser -filter * -Properties * `
    | Select @{n="Prénom";e={$_.GivenName}},
    @{n="Nom";e={$_.SurName}},
    Mail,
    @{n="Titre";e={$_.Title}},
    @{n="Login AD";e={$_.SamAccountName}},
    @{n="Dernière connexion";e={$_.LastLogonDate}},
    @{n="bDoRowHighlight";e={$_.LastLogonDate.ToString('dd MMM yyyy HH:mm:ss') -lt $date}},
    @{n="Créé le";e={$_.Created.ToString('dd MMM yyyy HH:mm:ss')}},
    @{n="UO";e={($_.DistinguishedName -split ",",2)[1]}}|Sort Nom)`
    |Out-File C:\temp\test.html

Thanks for any help.