Page 1 of 1

Format script damaging string format

Posted: Tue Oct 03, 2017 6:33 pm
by jdainsworth
To help you better we need some information from you.

*** Please fill in the fields below. If you leave fields empty or specify 'latest' rather than the actual version your answer will be delayed as we will be forced to ask you for this information. ***

Product, version and build: PowerShell Studio 2017, 5.4.144
32 or 64 bit version of product: 64-bit
Operating system:
32 or 64 bit OS: 64-bit

*** Please add details and screenshots as needed below. ***

I have a line of code that the 'Format Script' breaks the formatting of a string. The following code will demonstrate the :
$TempDate = (New-Object System.DateTimeOffset((get-date)))
("$($TempDate.LocalDateTime.ToString('yyyy-MM-dd HH:mm:ss.fffffff')) $($TempDate.OffSet.Hours):$({00} -f $TempDate.OffSet.Minutes)" -replace " 0:00$", " -0:00")

Get's reformatted to:

$TempDate = (New-Object System.DateTimeOffset((get-date)))
("$($TempDate.LocalDateTime.ToString('yyyy-MM-dd HH:mm:ss.fffffff')) $($TempDate.OffSet.Hours):$({
00
} -f $TempDate.OffSet.Minutes)" -replace " 0:00$", " -0:00")

which breaks the return value.

DO NOT POST SUBSCRIPTIONS, KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM

Re: Format script damaging string format

Posted: Tue Oct 03, 2017 8:02 pm
by mxtrinidad
I wasn't able to replicate the issue in PS version 144. I copy/paste the code then reformat the script and didn't break code at the brackets {}. Although the code provided has some errors.

Seems the one-liner don't need to use the replace and the results could be simpler.
Try the following to see if agree with it. Here are some variations:
$($TempDate.LocalDateTime.ToString('yyyy-MM-dd HH:mm:ss.00'))
$($TempDate.LocalDateTime.ToString('yyyy-MM-dd HH:mm'))
$($TempDate.LocalDateTime.ToString('yyyy-MM-dd HH:00'))

Re: Format script damaging string format

Posted: Wed Oct 04, 2017 8:01 am
by jdainsworth
Your sample code does not provide the output in ISO 8601 format (YYYY-MM-DDThh:mm:ss[.nnnnnnn][{+|-}hh:mm]).

Re: Format script damaging string format

Posted: Wed Oct 04, 2017 8:54 am
by mxtrinidad
Ah! Understood.

Sometime ago, I work in a Biztalk project were the XML needed to provide an ISO 8601 date format but coming from a SQL table date field.

Maybe the following line might be (sort of) starting point then break it in pieces:

$((Get-Date).ToString('yyyy-MM-dd HH:mm:ss.fffffffzzz'))

Still I wasn't able to replicate the issue you were experience. I remember seem it in older version of PowerShell Studio but not on the current one.

Re: Format script damaging string format

Posted: Wed Oct 04, 2017 8:59 am
by jdainsworth
It would be nice to address the formatting issue, because it does seem to be an interpreter issue. Below are my formatting options.
Capture.PNG
Capture.PNG (24.36 KiB) Viewed 3206 times

Re: Format script damaging string format

Posted: Wed Oct 04, 2017 9:07 am
by mxtrinidad
Thanks for providing the screen image. Of course, I got different setting:
if ($value)
{
Out-Default 'True'
}
else
{
Out-Default 'False'
}

Let me change it and get back to you.
:)

Re: Format script damaging string format

Posted: Wed Oct 04, 2017 9:26 am
by mxtrinidad
Ok! I was able to replicate the issue.

Please try the following settings "Checked" on:
x Place open brace on new line
x Place statement keyword on a new line
x Insert new line after Parameter attribute
x Align hashtable equal signs
x Leave block on the same line (I'm sure is is the one)
x convert curly quotes to straight quotes

Let me know if it work this time.
:)