Skip to content

Fix date format for serviceBusQueue trigger metadata to ensure ISO8601 compliance #354

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: v4.x
Choose a base branch
from

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Jun 25, 2025

This PR fixes an issue where enqueuedTimeUtc and expiresAtUtc fields in serviceBusQueue trigger metadata were missing timezone information, causing timezone-dependent behavior when parsing dates.

Problem

When using Azure Functions with serviceBusQueue triggers, the context.triggerMetadata contained date fields formatted without timezone information:

// Problematic format (missing 'Z' suffix)
context.triggerMetadata.enqueuedTimeUtc = "2025-06-07T14:46:55.145"
context.triggerMetadata.expiresAtUtc = "2025-06-07T14:46:55.145"

// This caused timezone-dependent parsing
new Date("2025-06-07T14:46:55.145") // Uses system timezone - problematic!

Solution

Added automatic timezone correction for serviceBusQueue triggers to ensure ISO8601 compliance:

// Fixed format (with 'Z' suffix indicating UTC)
context.triggerMetadata.enqueuedTimeUtc = "2025-06-07T14:46:55.145Z"
context.triggerMetadata.expiresAtUtc = "2025-06-07T14:46:55.145Z"

// Now parsing is timezone-independent
new Date("2025-06-07T14:46:55.145Z") // Always UTC - correct!

Implementation Details

  • Added fixDateFormatForServiceBus() function in fromRpcTriggerMetadata.ts
  • Only applies to serviceBus triggers and specific date fields (enqueuedTimeUtc, expiresAtUtc)
  • Uses regex pattern to identify dates missing timezone information
  • Appends 'Z' suffix for UTC timezone compliance
  • Preserves existing behavior for properly formatted dates and other trigger types

Testing

Added comprehensive test cases covering:

  • ✅ Dates missing timezone information are fixed
  • ✅ Dates with existing timezone information remain unchanged
  • ✅ Non-serviceBus triggers are unaffected
  • ✅ All existing tests continue to pass (127/127)

This is a minimal, surgical fix that ensures consistent date parsing behavior regardless of the Azure Functions host's timezone settings.

Fixes #351.


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

@Copilot Copilot AI changed the title [WIP] Improve date format for dates in triggerMetadata for servicebusQueue trigger. Fix date format for serviceBusQueue trigger metadata to ensure ISO8601 compliance Jun 25, 2025
@Copilot Copilot AI requested a review from swapnil-nagar June 25, 2025 03:31
Copilot finished work on behalf of swapnil-nagar June 25, 2025 03:31
@timtucker-dte
Copy link

Doing transformations on the RPC metadata after it comes in seems more like a workaround than a fix -- is this a problem that needs to be fixed upstream?

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.

Improve date format for dates in triggerMetadata for servicebusQueue trigger.
3 participants