Skip to content

Add Duration property to HistoryInfo - #5208

Merged
Ilya (iSazonov) merged 12 commits into
PowerShell:masterfrom
powercode:historyInfo
Aug 28, 2018
Merged

Add Duration property to HistoryInfo#5208
Ilya (iSazonov) merged 12 commits into
PowerShell:masterfrom
powercode:historyInfo

Conversation

@powercode

@powercode Staffan Gustafsson (powercode) commented Oct 24, 2017

Copy link
Copy Markdown
Collaborator

Fixes #4181
Adding a property Duration to HistoryInfo to end the {$_.EndExecutionTime - $_.StartExecutionTime} madness :)


This change is Reviewable

@vors sergei (vors) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sweet! any tests?

@iSazonov Ilya (iSazonov) self-assigned this Oct 25, 2017
@powercode

Copy link
Copy Markdown
Collaborator Author

Not really sure what to test. Testing

public TimeSpan Duration => EndExecutionTime - StartExecutionTime; 

will hardly give a lot.
But maybe a test that the formatting view is in place?

@vors

Copy link
Copy Markdown
Collaborator

Not really sure what to test

GetExecutionTimeString seems like a good candidate for unit tests

@iSazonov

Copy link
Copy Markdown
Collaborator

Staffan Gustafsson (@powercode) Please resolve merge conflicts.

@powercode

Copy link
Copy Markdown
Collaborator Author

sergei (@vors) You were so right. Added tests and fixed bugs

@vors sergei (vors) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks solid, but not a big fan of reflection in the tests. This is very fragile.
I guess it should not be a blocker, but maybe we can just do some unit testing from C#? Don't we have such tests?

@iSazonov Ilya (iSazonov) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leave a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a specific list of types and HistoryInfo isn't in that list

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests are very similar. Please use -TestCases.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point

@powercode Staffan Gustafsson (powercode) changed the title Add ExecutionTime property to HistoryInfo Add Duration property to HistoryInfo Nov 9, 2017

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comment - should we follow ToString() and use ToDurationString() for public?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, or Tostring(string). Thought about that a bit also, but never reach any real conclusion.

@iSazonov Ilya (iSazonov) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leave a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we remove the test?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TimeSeparator can be culture sensitive. Could you please use TimeSpan constructor for duration?

Also in C# $@"{duration:d\.hh\:mm\:ss}"; should we be culture sensitive too?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ilya (@iSazonov) Excellent catch!
I will fix!

@iSazonov Ilya (iSazonov) Jan 25, 2018

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We keep the implementation as it is.
Closed.

@SteveL-MSFT

Copy link
Copy Markdown
Member

We're not holding the RC for this PR, if it makes it in soon, great! If not, it'll catch the next release.

@mi-hol

mi-hol commented Dec 14, 2017

Copy link
Copy Markdown

Steve Lee (@SteveL-MSFT) will it merge this time?

@SteveL-MSFT

Copy link
Copy Markdown
Member

mi-hol if the maintainer Ilya (@iSazonov) believes there has been sufficient review, he can merge this, but we're limiting code changes we're taking for GA to avoid risk of regression. This will show up in 6.1.0 preview release which should happen early next year.

@SteveL-MSFT Steve Lee (SteveL-MSFT) removed this from the 6.0.0-NiceToHave milestone Dec 15, 2017
@iSazonov

Copy link
Copy Markdown
Collaborator

We have only one open comment about TimeSeparator.
I don't see any reason why we won't get it in 6.1.0.

@powercode

Copy link
Copy Markdown
Collaborator Author

I have looked a bit on how PowerShell treats timespans in other cases, and it seems to use the default formatting, which is not culture sensitive.
I think we should stick with consistency here, and keep the implementation as it is.

@iSazonov

Copy link
Copy Markdown
Collaborator

Staffan Gustafsson (@powercode) please resolve conflicts.

@iSazonov

Copy link
Copy Markdown
Collaborator

Steve Lee (@SteveL-MSFT) Dongbo Wang (@daxian-dbw) Have you any thoughts about the PR?

@SteveL-MSFT Steve Lee (SteveL-MSFT) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding GetDurationString() vs ToDurationString(), looking in PS code, it seems Get*String() is used (although internal methods). I'm fine keeping GetDurationString() unless someone can point to some guidance otherwise.

@iSazonov

Ilya (iSazonov) commented Feb 24, 2018

Copy link
Copy Markdown
Collaborator

Travis Plunk (@TravisEz13) Dongbo Wang (@daxian-dbw) Have you any thoughts about GetDurationString() vs ToDurationString()?

@powercode Staffan Gustafsson (powercode) changed the title WIP: Add Duration property to HistoryInfo Add Duration property to HistoryInfo Jun 19, 2018
@powercode

Copy link
Copy Markdown
Collaborator Author

These build errors are not related to my changes.

Can anyone restart the build here?

@iSazonov

Copy link
Copy Markdown
Collaborator

Reopen the PR to restart CIs.

@TravisEz13
Travis Plunk (TravisEz13) dismissed Steve Lee (SteveL-MSFT)’s stale review July 6, 2018 00:41

Changes were recommended after approval

@iSazonov

Copy link
Copy Markdown
Collaborator

Staffan Gustafsson (@powercode) Is the PR ready for review?

@powercode

Copy link
Copy Markdown
Collaborator Author

Yes

@iSazonov

Copy link
Copy Markdown
Collaborator

@TravisEz13 Travis Plunk (TravisEz13) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 1 files at r4, 1 of 2 files at r5.
Reviewable status: :shipit: complete! all files reviewed

}

It "HistoryInfo calculates Duration" {
$ctor = [Microsoft.PowerShell.Commands.HistoryInfo].GetConstructors([Reflection.BindingFlags]::NonPublic -bor [Reflection.BindingFlags]::Instance).Where{$_.GetParameters().Length -eq 5}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this test should just get the first item from item from Get-History and validate that Duration = End - Start?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Steve Lee (@SteveL-MSFT) Am I guaranteed to have something in the history at that moment?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Staffan Gustafsson (@powercode) I think it's ok to use Add-History

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@SteveL-MSFT Steve Lee (SteveL-MSFT) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

}
$history | Add-History
$h = Get-History -count 1
$h.Duration | Should Be $duration

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Staffan Gustafsson (@powercode) Sorry I lost the PR. Please fix Be -> -Be and we ready to merge.

@iSazonov

Copy link
Copy Markdown
Collaborator

Staffan Gustafsson (@powercode) Thank you for the contribution! Sorry for delay.

@TravisEz13 Travis Plunk (TravisEz13) added this to the v6.1.0 milestone Aug 28, 2018
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
* Remove regions in HistoryInfo class
* Auto properties refactoring in HistoryInfo
* Adding Duration property to HistoryInfo
* Rename ExecutionTime => Duration
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Committee-Reviewed PS-Committee has reviewed this and made a decision

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants