Format script damaging string format

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 6 years and 5 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
User avatar
jdainsworth
Posts: 25
Last visit: Thu Dec 14, 2023 9:10 am

Format script damaging string format

Post 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
User avatar
mxtrinidad
Posts: 399
Last visit: Tue May 16, 2023 6:52 am

Re: Format script damaging string format

Post 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'))
User avatar
jdainsworth
Posts: 25
Last visit: Thu Dec 14, 2023 9:10 am

Re: Format script damaging string format

Post by jdainsworth »

Your sample code does not provide the output in ISO 8601 format (YYYY-MM-DDThh:mm:ss[.nnnnnnn][{+|-}hh:mm]).
User avatar
mxtrinidad
Posts: 399
Last visit: Tue May 16, 2023 6:52 am

Re: Format script damaging string format

Post 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.
User avatar
jdainsworth
Posts: 25
Last visit: Thu Dec 14, 2023 9:10 am

Re: Format script damaging string format

Post 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 3204 times
User avatar
mxtrinidad
Posts: 399
Last visit: Tue May 16, 2023 6:52 am

Re: Format script damaging string format

Post 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.
:)
User avatar
mxtrinidad
Posts: 399
Last visit: Tue May 16, 2023 6:52 am

Re: Format script damaging string format

Post 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.
:)
This topic is 6 years and 5 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.