Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jul 3, 2025

Problem

The --after flag was missing strftime format parsing support that already existed in the --before flag. When users set a custom time format using --time-style with +FORMAT (like date(1)), the --before flag could parse dates in that format, but --after could not, leading to inconsistent behavior.

Solution

Added the missing strftime parsing logic to the --after flag by mirroring the existing implementation from the --before flag. Both flags now consistently support:

  • Standard time formats: MM-dd, MM-dd HH:mm, HH:mm, YYYY-MM-dd, YYYY-MM-dd HH:mm
  • Custom strftime formats when --time-style is set with +FORMAT

Example Usage

# Both flags now work consistently with strftime formats
g --time-style="+%Y-%m-%d" --after="2025-07-03" .
g --time-style="+%m/%d/%Y" --before="07/03/2025" .
g --time-style="+%Y-%m-%d %H:%M" --after="2025-07-03 14:30" .

# US date format
g --time-style="+%m/%d/%Y" --after="07/03/2025" .

# ISO format with time
g --time-style="+%Y-%m-%d %H:%M:%S" --before="2025-07-03 14:30:00" .

Changes Made

  • Added strftime parsing block to --after flag in internal/cli/filtering.go
  • The implementation checks if the format starts with + and uses strftime.Parse() accordingly
  • Maintains backward compatibility with existing time format parsing
  • Error handling works correctly for invalid date formats

Testing

  • Verified both flags work with various strftime formats (%Y-%m-%d, %m/%d/%Y, %Y-%m-%d %H:%M)
  • Confirmed error handling for invalid dates
  • Ensured fallback to standard time parsing still works
  • All existing tests continue to pass

Fixes #245.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

@pull-request-size pull-request-size bot added size/S and removed size/XS labels Jul 3, 2025
Copilot AI changed the title [WIP] [FEAT] Support Parsing strftime format time in before/after flag feat: Add strftime format support to --after flag for consistent time parsing Jul 3, 2025
Copilot AI requested a review from equationzhao July 3, 2025 11:30
if strings.HasPrefix(f, "+") {
t, err := strftime.Parse(s, strings.TrimPrefix(f, "+"))
if err != nil {
fmt.Println(err)
Copy link
Owner

Choose a reason for hiding this comment

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

remove fmt.Println err in both before and after flag action

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 debug fmt.Println(err) statements from both the before and after flag actions. Also cleaned up the unused fmt import. (b1a3434)

Copilot AI requested a review from equationzhao July 3, 2025 11:48
@equationzhao equationzhao marked this pull request as ready for review July 3, 2025 11:50
@equationzhao equationzhao merged commit af1dab8 into master Jul 3, 2025
11 checks passed
@equationzhao equationzhao deleted the copilot/fix-245 branch July 3, 2025 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEAT] Support Parsing strftime format time in before/after flag

2 participants