Add Get-TimeSpan function for calculating time differences from target DateTime#6
Closed
Marius Storhaug (MariusStorhaug) with Copilot wants to merge 3 commits into
Closed
Add Get-TimeSpan function for calculating time differences from target DateTime#6Marius Storhaug (MariusStorhaug) with Copilot wants to merge 3 commits into
Marius Storhaug (MariusStorhaug) with Copilot wants to merge 3 commits into
Conversation
Co-authored-by: MariusStorhaug <17722253+MariusStorhaug@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] 🩹 [Patch]: Add a function for getting a timespan from a timedate (time - now)
Add Get-TimeSpan function for calculating time differences from target DateTime
Jul 11, 2025
Member
|
Lets change this abit. I want it to:
|
…ve handling Co-authored-by: MariusStorhaug <17722253+MariusStorhaug@users.noreply.github.com>
Contributor
Author
I've refactored the Get-TimeSpan function according to your feedback:
The function now supports flexible usage patterns:
All tests updated and passing. Commit: 55f7dfc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR implements a new
Get-TimeSpanfunction that calculates the time difference between a target DateTime and the current time, addressing the need for countdown timers and age calculations.Features
The function provides a clean interface for time difference calculations:
Implementation Details
Target - Nowfor countdown,Now - Targetfor age[TimeSpan]::Zeroby default for past dates, matching the pattern described in the issueParameters
Target [DateTime]- The target datetime to calculate difference from (required)AllowNegative [switch]- Returns actual negative TimeSpan instead of Zero for past datesAsAge [switch]- Calculates elapsed time (Now - Target) instead of remaining timeIntegration
Works seamlessly with existing module functions:
Testing
Added comprehensive test coverage with 7 test cases covering:
All new tests pass, confirming the implementation works correctly for all specified requirements.
Fixes #5.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.