+
Skip to content

Tags: PSModule/TimeSpan

Tags

v3.0.1

Toggle v3.0.1's commit message

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
🪲[Fix]: Format-TimeSpan handling of zero values in the middle of time…

… spans (#12)

The `Format-TimeSpan` function was incorrectly truncating output when
zero values appeared between non-zero time units. Consider:

```powershell
# This should show "2h 10s" but only showed "2h"
New-TimeSpan -Hours 2 -Minutes 0 -Seconds 10 | Format-TimeSpan

# Other examples that were broken:
New-TimeSpan -Hours 1 -Milliseconds 500 | Format-TimeSpan  # Should show "1h 500ms"
New-TimeSpan -Days 2 -Minutes 30 | Format-TimeSpan         # Should show "2d 30m"
```

## Root Cause

The issue was in the auto-precision calculation logic. When precision
wasn't explicitly specified, the function would:

1. Count the number of non-zero units (correctly identifying 2 units:
hours and seconds)
2. Process only a fixed range based on that count (`startingIndex +
precision - 1`)
3. Skip zero values during processing, but the limited range prevented
reaching subsequent non-zero units

## Solution

Modified the auto-precision logic to process all time units when
precision is not explicitly specified, allowing the existing filtering
logic to correctly include only non-zero values regardless of gaps.

## Key Changes

- Updated auto-precision calculation in `Format-TimeSpan.ps1` to use
maximum range when `IncludeZeroValues` is false
- Added comprehensive test cases covering various zero-gap scenarios
- Preserved all existing functionality including explicit precision
behavior

## Testing

- ✅ Fixed original issue: `New-TimeSpan -Hours 2 -Minutes 0 -Seconds 10
| Format-TimeSpan` → "2h 10s"
- ✅ All existing regression tests pass (8/8)
- ✅ Added 3 new test cases for zero-gap scenarios
- ✅ Verified explicit precision, different formats, and negative values
still work correctly

Fixes #11.

<!-- START COPILOT CODING AGENT TIPS -->
---

💬 Share your feedback on Copilot coding agent for the chance to win a
$200 gift card! Click
[here](https://survey.alchemer.com/s3/8343779/Copilot-Coding-agent) to
start the survey.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: MariusStorhaug <17722253+MariusStorhaug@users.noreply.github.com>

v3.0.0

Toggle v3.0.0's commit message

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
🌟 [Major]: Change default format precision to be all units that have …

…values (#10)

This pull request introduces significant updates to the `TimeSpan`
PowerShell module, focusing on improving functionality, usability, and
documentation. Key changes include enhancements to the `Format-TimeSpan`
function, updates to the README for better clarity, and expanded test
coverage to ensure backward compatibility and validate new features.

- Fixes #9

### Enhancements to `Format-TimeSpan` functionality

* 🌟 Default behavior now shows all non-zero time units unless explicitly
overridden by the `Precision` parameter. Added a new `IncludeZeroValues`
parameter to include zero-value units in the output.
* 🌟 Precision handling updated to dynamically calculate based on
non-zero units when not explicitly specified, ensuring intuitive
defaults.
* Added examples showing multiple formatting styles (`Symbol`,
`Abbreviation`, `FullName`) and clarified their behavior.

### Documentation improvements

* Updated `README.md` to reflect the new default behavior, provide
detailed usage examples, and explain supported parameters and time
units.
* Enhanced inline comments in `Format-TimeSpan.ps1` to clarify parameter
behavior and default settings.

### Expanded test coverage:
* Added tests for new functionality, including `IncludeZeroValues` and
backward compatibility for explicit precision settings.
* Updated existing tests to align with the new default behavior of
`Format-TimeSpan`.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: MariusStorhaug <17722253+MariusStorhaug@users.noreply.github.com>
Co-authored-by: Marius Storhaug <marstor@hotmail.com>

v2.0.0

Toggle v2.0.0's commit message

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
🌟[Major]: Replace `FullNames` with a dynamic `Format` parameter with …

…3 alternatives (#8)

This pull request introduces enhancements to the formatting
functionality for units and time spans in the PowerShell module. Key
changes include adding a new `Format` parameter to specify unit display
styles (Symbol, Abbreviation, or FullName), updating the `UnitMap` to
include symbols, and refactoring associated tests to reflect these
changes.

- Fixes #7

### Enhancements to TimeSpan Formatting:

* 🌟 **`Format-TimeSpan`:** Replaced the `FullNames` switch with the
`Format` parameter, allowing users to specify the desired unit display
style. Updated logic to use the `Format-UnitValue` function with the new
`Format` parameter.

### Enhancements to Unit Formatting:

* **`Format-UnitValue`:** Added a `Format` parameter with options for
Symbol, Abbreviation, and FullName, replacing the previous `FullNames`
switch. Refactored logic to handle unit formatting based on the selected
format.

* **`src/variables/private/UnitMap.ps1`:** Updated the `UnitMap` to
include a new `Symbol` field for each unit, alongside existing Singular,
Plural, and Abbreviation fields.

### Test Updates:

* **`tests/PSModuleTest.Tests.ps1`:** Refactored tests to validate the
new `Format` parameter functionality, including scenarios for symbols,
abbreviations, and full names. Added new test cases for various formats
and edge cases like negative values and smallest units.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: MariusStorhaug <17722253+MariusStorhaug@users.noreply.github.com>
Co-authored-by: Marius Storhaug <marstor@hotmail.com>

v1.0.1

Toggle v1.0.1's commit message

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Bump PSModule/Process-PSModule from 3 to 4 (#4)

- Moved `mkdocs.yml` file to `.github`.
- Bumps
[PSModule/Process-PSModule](https://github.com/psmodule/process-psmodule)
from 3 to 4.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/psmodule/process-psmodule/releases">PSModule/Process-PSModule's
releases</a>.</em></p>
<blockquote>
<h2>v3.2.17</h2>
<!-- raw HTML omitted -->
<h2>What's Changed</h2>
<h3>Other Changes</h3>
<ul>
<li>🪲 [Fix]: Fix placement of docs after copy by <a
href="https://github.com/MariusStorhaug"><code>@​MariusStorhaug</code></a>
in <a
href="https://redirect.github.com/PSModule/Process-PSModule/pull/138">PSModule/Process-PSModule#138</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a
href="https://github.com/PSModule/Process-PSModule/compare/v3...v3.2.17">https://github.com/PSModule/Process-PSModule/compare/v3...v3.2.17</a></p>
<h2>v3.2.16</h2>
<!-- raw HTML omitted -->
<h2>What's Changed</h2>
<h3>Other Changes</h3>
<ul>
<li>🪲 [Fix]: Fix an issue that break the workflow when there is nothing
to commit in <code>BuildDocs</code> by <a
href="https://github.com/MariusStorhaug"><code>@​MariusStorhaug</code></a>
in <a
href="https://redirect.github.com/PSModule/Process-PSModule/pull/137">PSModule/Process-PSModule#137</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a
href="https://github.com/PSModule/Process-PSModule/compare/v3...v3.2.16">https://github.com/PSModule/Process-PSModule/compare/v3...v3.2.16</a></p>
<h2>v3.2.15</h2>
<!-- raw HTML omitted -->
<h2>What's Changed</h2>
<h3>Other Changes</h3>
<ul>
<li>🩹 [Patch]: Merge <code>Docs</code> jobs into one by <a
href="https://github.com/MariusStorhaug"><code>@​MariusStorhaug</code></a>
in <a
href="https://redirect.github.com/PSModule/Process-PSModule/pull/136">PSModule/Process-PSModule#136</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a
href="https://github.com/PSModule/Process-PSModule/compare/v3...v3.2.15">https://github.com/PSModule/Process-PSModule/compare/v3...v3.2.15</a></p>
<h2>v3.2.14</h2>
<!-- raw HTML omitted -->
<h2>What's Changed</h2>
<h3>Other Changes</h3>
<ul>
<li>🩹 [Patch]: Separate Docs from Build by <a
href="https://github.com/MariusStorhaug"><code>@​MariusStorhaug</code></a>
in <a
href="https://redirect.github.com/PSModule/Process-PSModule/pull/135">PSModule/Process-PSModule#135</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a
href="https://github.com/PSModule/Process-PSModule/compare/v3...v3.2.14">https://github.com/PSModule/Process-PSModule/compare/v3...v3.2.14</a></p>
<h2>v3.2.13</h2>
<!-- raw HTML omitted -->
<h2>What's Changed</h2>
<h3>Other Changes</h3>
<ul>
<li>🩹 [Patch]: Reverting Co-location by <a
href="https://github.com/MariusStorhaug"><code>@​MariusStorhaug</code></a>
in <a
href="https://redirect.github.com/PSModule/Process-PSModule/pull/134">PSModule/Process-PSModule#134</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a
href="https://github.com/PSModule/Process-PSModule/compare/v3...v3.2.13">https://github.com/PSModule/Process-PSModule/compare/v3...v3.2.13</a></p>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/PSModule/Process-PSModule/commit/78a1ce8511fa85425fb029398e9a7acc51232df7"><code>78a1ce8</code></a>
🩹 [Refactor]: Enhance XML report output formatting in workflow script
for imp...</li>
<li><a
href="https://github.com/PSModule/Process-PSModule/commit/d276cf4bb89b09bb2b4e4ee04cb43ee07ed9ff59"><code>d276cf4</code></a>
🩹 [Refactor]: Output merged report as string in workflow script for
improved ...</li>
<li><a
href="https://github.com/PSModule/Process-PSModule/commit/d197e574720ada9fedf16d6b38c22e94dcae8059"><code>d197e57</code></a>
🩹 [Refactor]: Implement XML report merging in workflow script to
consolidate ...</li>
<li><a
href="https://github.com/PSModule/Process-PSModule/commit/40d1337b85bffbece64f53a3c56784841ae58908"><code>40d1337</code></a>
🩹 [Refactor]: Replace Show-FileContent with Get-Content for improved
file con...</li>
<li><a
href="https://github.com/PSModule/Process-PSModule/commit/cba299082a18e431b11fee82329cd595b25fc3eb"><code>cba2990</code></a>
🩹 [Refactor]: Improve file listing and logging in workflow script for
better ...</li>
<li><a
href="https://github.com/PSModule/Process-PSModule/commit/2508f849b0351842b1278926adf95dd05bca28de"><code>2508f84</code></a>
🩹 [Refactor]: Update workflow script to set output rendering and
retrieve rep...</li>
<li><a
href="https://github.com/PSModule/Process-PSModule/commit/963de209b488f8b55741acd8aba54d11d86466f7"><code>963de20</code></a>
🩹 [Refactor]: Simplify artifact download command in workflow script to
direct...</li>
<li><a
href="https://github.com/PSModule/Process-PSModule/commit/c93d57a373be121cee01c406706f6ff62ebd4a92"><code>c93d57a</code></a>
🩹 [Refactor]: Enhance artifact download command in workflow script to
use pat...</li>
<li><a
href="https://github.com/PSModule/Process-PSModule/commit/670b57c03364a7175246878896f86a871eae5980"><code>670b57c</code></a>
🩹 [Refactor]: Update artifact retrieval in workflow script to use
repository ...</li>
<li><a
href="https://github.com/PSModule/Process-PSModule/commit/3cc46e1dc263dbb2090e76872d10d4a1e5ab775c"><code>3cc46e1</code></a>
🩹 [Refactor]: Update artifact filtering in workflow script to improve
code co...</li>
<li>Additional commits viewable in <a
href="https://github.com/psmodule/process-psmodule/compare/v3...v4">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=PSModule/Process-PSModule&package-manager=github_actions&previous-version=3&new-version=4)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Marius Storhaug <marstor@hotmail.com>

v1.0.0

Toggle v1.0.0's commit message

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
🌟 [Major]: Introducing the `TimeSpan` module (#3)

## Description

This pull request introduces the `TimeSpan` PowerShell module, focusing
on formatting numerical values and time spans.

- Fixes #2 

New function:

*
[`src/functions/private/Format-UnitValue.ps1`](diffhunk://#diff-b5be05918c9bdd69f29b7ccf5dd1d94ed3f4c262039a61a0cdaf4efa26f2165bR1-R70):
Added a new function `Format-UnitValue` to format numerical values with
their corresponding units, supporting both abbreviations and full names.
*
[`src/functions/public/Format-TimeSpan.ps1`](diffhunk://#diff-c083b791c0fc9d31b5a09f3192324400a88968ce49165b92316b2204fabdc880R1-R132):
Added a new function `Format-TimeSpan` to format `TimeSpan` objects into
human-readable strings, supporting precision levels and full unit names.

Enhancements to unit handling:

*
[`src/variables/private/UnitMap.ps1`](diffhunk://#diff-2a1908f14064df8453dc87e1f041a5e287ad5d93d18622f8dfdb0c3bc2b93455R1-R79):
Introduced a unit map (`$script:UnitMap`) to provide consistent handling
of various time units, including their singular, plural forms,
abbreviations, and tick values.

Testing improvements:

*
[`tests/PSModuleTest.Tests.ps1`](diffhunk://#diff-854f5db3c1afae9419d6a22487e65e9e83942e00d1f21a85d4c23424dd2f47cdL1-R46):
Added new tests for the `Format-TimeSpan` function to cover various
scenarios, including basic usage, precision handling, smallest unit
handling, negative time spans, and base unit formatting.

## Type of change

<!-- Use the check-boxes [x] on the options that are relevant. -->

- [ ] 📖 [Docs]
- [ ] 🪲 [Fix]
- [ ] 🩹 [Patch]
- [ ] ⚠️ [Security fix]
- [ ] 🚀 [Feature]
- [x] 🌟 [Breaking change]

## Checklist

<!-- Use the check-boxes [x] on the options that are relevant. -->

- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas

v0.0.1

Toggle v0.0.1's commit message

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Init (#1)

## Description

Init

## Type of change

<!-- Use the check-boxes [x] on the options that are relevant. -->

- [ ] 📖 [Docs]
- [ ] 🪲 [Fix]
- [ ] 🩹 [Patch]
- [ ] ⚠️ [Security fix]
- [ ] 🚀 [Feature]
- [ ] 🌟 [Breaking change]

## Checklist

<!-- Use the check-boxes [x] on the options that are relevant. -->

- [ ] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载