Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Measure-Object should support TimeSpan #10712

Copy link
Copy link
@felixfbecker

Description

@felixfbecker
Issue body actions

Summary of the new feature/enhancement

TimeSpans have all arithmetic operators defined on them (addition, subtraction, division, multiplication, equality, greater/less than). However, Measure-Object only works on numbers. If you pipe a TimeSpan to it, it will error with

measure-object : Input object "00:00:00" is not numeric.

It would be very useful if Measure-Object could work on TimeSpan objects too.
Example use case: Measure the time spent in meetings today and their average duration:

Get-GSCalendarEvent -TimeMin (Get-Date).Date -TimeMax (Get-Date).Date.AddDays(1) -SingleEvents |
  ForEach-Object { $_.End.DateTime - $_.Start.DateTime } |
  Measure-Object -AllStats

Count             : 3
Average           : 1:00:00
Sum               : 3:00:00
Maximum           : 2:00:00
Minimum           : 0:30:00
StandardDeviation : 0:30:00
Property          :

Currently, this is more cumbersome:

Get-GSCalendarEvent -TimeMin (Get-Date).Date -TimeMax (Get-Date).Date.AddDays(1) -SingleEvents |
  ForEach-Object { $_.End.DateTime - $_.Start.DateTime } |
  ForEach-Object { $s = New-TimeSpan } { $s += $_ } { $s }

And this only gets you the sum. All the other stats require way more code.

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    HacktoberfestPotential candidate to participate in HacktoberfestPotential candidate to participate in HacktoberfestIssue-Enhancementthe issue is more of a feature request than a bugthe issue is more of a feature request than a bugResolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or moreUp-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility modulecmdlets in the Microsoft.PowerShell.Utility module

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.