Skip to content

fix(tasks): preserve time component when setting due date with time#837

Open
nuthalapativarun wants to merge 1 commit into
googleworkspace:mainfrom
nuthalapativarun:fix/696-tasks-due-time
Open

fix(tasks): preserve time component when setting due date with time#837
nuthalapativarun wants to merge 1 commit into
googleworkspace:mainfrom
nuthalapativarun:fix/696-tasks-due-time

Conversation

@nuthalapativarun
Copy link
Copy Markdown

Description

When setting a due date that includes a time component via gws tasks, the time was silently dropped — only the date was preserved in the API request.

Identified the root cause in the due-date serialization logic and fixed it to preserve the full RFC 3339 datetime when a time is provided.

This PR adds a tasks helper with a +insert subcommand that includes a --due flag. The key fix is in normalize_due_date():

  • Date-only (YYYY-MM-DD) → normalised to YYYY-MM-DDT00:00:00.000Z
  • Full datetime (2026-06-20T14:00:00Z, 2026-06-20T09:00:00-07:00, etc.) → passed through unchanged, preserving the time component

Also fixes a pre-existing clippy::collapsible_match warning in helpers/script.rs that caused cargo clippy -- -D warnings to fail.

Closes #696

Checklist:

  • My code follows the AGENTS.md guidelines (no generated google-* crates).
  • I have run cargo fmt --all to format the code perfectly.
  • I have run cargo clippy -- -D warnings and resolved all warnings.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have provided a Changeset file (e.g. via pnpx changeset) to document my changes.

Add a `tasks` helper with a `+insert` subcommand that accepts a `--due`
flag. When the user supplies a full RFC 3339 datetime (e.g.
`2026-06-20T14:00:00Z`) the time component is passed through to the
Google Tasks API unchanged. A date-only value (`YYYY-MM-DD`) is
normalised to midnight UTC (`T00:00:00.000Z`).

Also fix a pre-existing collapsible-match clippy warning in script.rs
that caused `cargo clippy -- -D warnings` to fail.

Closes googleworkspace#696
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jun 2, 2026

🦋 Changeset detected

Latest commit: 273be8f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@googleworkspace/cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces functionality to create tasks via the CLI while ensuring that time components in due dates are correctly preserved. By updating the serialization logic, the tool now distinguishes between date-only inputs and full RFC 3339 timestamps, preventing data loss during API requests. Additionally, the PR includes minor cleanup of existing code to satisfy linting requirements.

Highlights

  • Task Creation Support: Added a new +insert subcommand to the tasks helper, allowing users to create tasks with optional due dates and times.
  • Due Date Normalization: Implemented normalize_due_date to preserve full RFC 3339 datetime strings while defaulting date-only inputs to midnight UTC.
  • Code Quality: Resolved a clippy::collapsible_match warning in helpers/script.rs to ensure clean builds.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Generative AI Prohibited Use Policy, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@googleworkspace-bot googleworkspace-bot added the area: core Core CLI parsing, commands, error handling, utilities label Jun 2, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new TasksHelper to support creating tasks with an optional due date/time via the +insert command, while preserving the time component when provided. It also simplifies a match arm in script.rs. The review feedback highlights security concerns regarding terminal escape sequence injection: first, by recommending character validation on the --due datetime string when it contains a 'T' separator, and second, by suggesting the sanitization of the user-supplied --due string using escape_debug() when formatting it into validation error messages.

Comment on lines +183 to +185
if due_str.contains('T') {
return Ok(due_str.to_string());
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

security-high high

When the --due input contains a T separator, it is currently passed through to the API completely unchecked. If the input contains malicious payloads (such as terminal escape sequences or control characters), these could be echoed back by the API in error responses, leading to terminal escape sequence injection.

To prevent this, validate that the datetime string only contains valid RFC 3339 characters (digits, standard separators, and timezone designators) before returning it.

Suggested change
if due_str.contains('T') {
return Ok(due_str.to_string());
}
if due_str.contains('T') {
if !due_str.chars().all(|c| {
c.is_ascii_digit()
|| c == 'T'
|| c == 't'
|| c == 'Z'
|| c == 'z'
|| c == '-'
|| c == ':'
|| c == '.'
|| c == '+'
}) {
return Err(GwsError::Validation(
"Invalid characters in --due datetime value".to_string(),
));
}
return Ok(due_str.to_string());
}

Comment on lines +196 to +199
return Err(GwsError::Validation(format!(
"--due value '{due_str}' is not a valid date (YYYY-MM-DD) or \
datetime (RFC 3339, e.g. 2026-06-20T14:00:00Z)"
)));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

security-high high

To prevent terminal escape sequence injection, sanitize the user-supplied --due string before formatting it into the error message. If the input contains control characters or ANSI escape sequences, printing them directly to the terminal can be hazardous. Using escape_debug() ensures any control characters are safely represented as printable escape sequences.

        return Err(GwsError::Validation(format!(
            "--due value '{}' is not a valid date (YYYY-MM-DD) or \
             datetime (RFC 3339, e.g. 2026-06-20T14:00:00Z)",
            due_str.escape_debug()
        )));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: core Core CLI parsing, commands, error handling, utilities

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug - Tasks - set due time

2 participants