Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 19, 2025

This PR adds support for delta time syntax (-1d, -1w, -1mo) to the --start-date and --end-date flags in the gh aw logs command, making it much easier to filter workflow runs using relative dates. Additionally, it improves precision across the entire time delta system by always using precise date calculations.

New Delta Time Syntax

Users can now specify relative dates using intuitive syntax:

# Get runs from the last week
gh aw logs --start-date -1w

# Get runs up to yesterday  
gh aw logs --end-date -1d

# Get runs from the last month
gh aw logs --start-date -1mo

# Complex combinations work too
gh aw logs --start-date -2w3d --end-date -1d

Supported Time Units

  • Days: -1d, -7d
  • Weeks: -1w, -4w
  • Months: -1mo, -6mo
  • Hours/Minutes: -12h, -30m (for sub-day precision)
  • Combinations: -1mo2w3d, -2w5d12h

Always-Precise Date Calculations

Improved precision across the entire time delta system by eliminating conditional calculation logic:

  • Before: Used AddDate() only when months/weeks were present, fell back to simple duration arithmetic otherwise
  • After: Always uses AddDate() for months, weeks, and days for maximum precision in all scenarios
  • Benefits: Proper handling of varying month lengths, leap years, and daylight saving time transitions for all time calculations
  • Applies to: Both the new gh aw logs command and existing workflow stop-time field functionality

For example, adding 1 day on a daylight saving boundary:

  • Old method: Simple 24-hour duration (could be off during DST transitions)
  • New method: Uses AddDate() which properly handles calendar day boundaries

Implementation Details

The implementation extends the existing time delta parsing infrastructure from the compiler's stop-time field functionality:

  1. Extended TimeDelta struct to support weeks and months
  2. Added new parsing functions for negative deltas (going backwards in time)
  3. Created ResolveRelativeDate function that resolves relative dates to absolute YYYY-MM-DD format for GitHub CLI
  4. Updated logs command to parse and resolve delta dates before passing to GitHub CLI
  5. Enhanced help text with examples of the new syntax
  6. Always use precise calculations in both ResolveRelativeDate and resolveStopTime functions by eliminating conditional logic
  7. Updated documentation in instructions.md to document the new logs command functionality

Backward Compatibility

All existing functionality remains unchanged:

  • Absolute dates like 2024-01-01 continue to work exactly as before
  • All existing CLI flags and behavior preserved
  • The change is purely additive

Example Usage

# Traditional absolute dates (still work)
gh aw logs --start-date 2024-01-01 --end-date 2024-01-31

# New relative dates  
gh aw logs --start-date -1w          # Last week's runs
gh aw logs --end-date -1d            # Up to yesterday
gh aw logs --start-date -1mo         # Last month's runs
gh aw logs --start-date -2w3d        # 2 weeks 3 days ago

# Works for workflow stop-time too (now with always-precise calculation)
stop-time: +1mo  # Exactly one month from compilation

The command automatically resolves these relative dates to absolute dates before calling the GitHub CLI, ensuring full compatibility with GitHub's API.

Testing

Added comprehensive test coverage with 95+ new test cases covering:

  • All supported time units (days, weeks, months, hours, minutes)
  • Negative and positive deltas
  • Complex combinations
  • Edge cases and error handling
  • Date resolution accuracy
  • Always-precise calculations in both ResolveRelativeDate and resolveStopTime

Fixes #111.


💡 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.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] [copilot] Add delta time syntax to gh aw logs Add delta time syntax support to gh aw logs command Aug 19, 2025
@Copilot Copilot AI requested a review from pelikhan August 19, 2025 12:03
Copilot finished work on behalf of pelikhan August 19, 2025 12:03
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Aug 19, 2025

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • api.contoso.com
    • Triggering command: /tmp/go-build98263371/b278/cli.test -test.testlogfile=/tmp/go-build98263371/b278/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true (dns block)
    • Triggering command: /tmp/go-build3835627175/b278/cli.test -test.testlogfile=/tmp/go-build3835627175/b278/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@Copilot Copilot AI changed the title Add delta time syntax support to gh aw logs command Add delta time syntax support to gh aw logs command with precise month/week calculations Aug 19, 2025
@Copilot Copilot AI requested a review from pelikhan August 19, 2025 12:28
Copilot finished work on behalf of pelikhan August 19, 2025 12:28
Copy link
Contributor

@pelikhan pelikhan left a comment

Choose a reason for hiding this comment

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

@copilot update instructions.md file

// Calculate absolute time in UTC using precise calculation
var absoluteTime time.Time
if delta.Months > 0 || delta.Weeks > 0 {
// Use AddDate for months and weeks for more accurate calculation
Copy link
Contributor

Choose a reason for hiding this comment

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

@copilot always use precise computation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated both resolveStopTime and ResolveRelativeDate functions to always use precise calculation with AddDate() for months, weeks, and days instead of conditional logic that falls back to simple duration arithmetic. Fixed in commit b2c860f.

…ns.md

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Aug 19, 2025

@copilot update instructions.md file

Updated instructions.md file to document the new delta time syntax support for the gh aw logs command. Added comprehensive examples of relative date filtering with --start-date and --end-date flags, documented all supported time units, and noted that precise calculations are used. Updated in commit b2c860f.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • api.contoso.com
    • Triggering command: /tmp/go-build945599785/b278/cli.test -test.testlogfile=/tmp/go-build945599785/b278/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@Copilot Copilot AI changed the title Add delta time syntax support to gh aw logs command with precise month/week calculations Add delta time syntax support to gh aw logs command with always-precise calculations Aug 19, 2025
@Copilot Copilot AI requested a review from pelikhan August 19, 2025 12:41
Copilot finished work on behalf of pelikhan August 19, 2025 12:41
@@ -114,12 +129,22 @@ func (td *TimeDelta) toDuration() time.Duration {
duration := time.Duration(td.Days) * 24 * time.Hour
duration += time.Duration(td.Hours) * time.Hour
duration += time.Duration(td.Minutes) * time.Minute
duration += time.Duration(td.Weeks) * 7 * 24 * time.Hour
Copy link
Contributor

Choose a reason for hiding this comment

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

is this function still needed? @copilot remove if dead code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed the toDuration function as it was dead code. The function was only used in tests and the application now exclusively uses precise calculations with AddDate() instead of approximate duration arithmetic. Also removed the associated test TestTimeDeltaToDuration. Fixed in commit fc7d906.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Aug 19, 2025

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • api.contoso.com
    • Triggering command: /tmp/go-build536842731/b278/cli.test -test.testlogfile=/tmp/go-build536842731/b278/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true (dns block)
    • Triggering command: /tmp/go-build4281489744/b278/cli.test -test.testlogfile=/tmp/go-build4281489744/b278/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@Copilot Copilot AI requested a review from pelikhan August 19, 2025 12:57
Copilot finished work on behalf of pelikhan August 19, 2025 12:57
@pelikhan pelikhan marked this pull request as ready for review August 19, 2025 13:00
@pelikhan pelikhan merged commit bc985c3 into main Aug 19, 2025
6 checks passed
@pelikhan pelikhan deleted the copilot/fix-111 branch August 19, 2025 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[copilot] Add delta time syntax to gh aw logs
2 participants