Issue with Getting Current Date and Time in Shopify Product Discount Function (Rust)

Hi Shopify community,

I’m developing a Shopify app that applies campaign-based tiered pricing discounts to product variants using Shopify Functions. The discounts are time-sensitive, based on start and end dates, and we’re storing the rules in variant metafields.

Setup Details:

  • Metafield Configuration:
    • Namespace: test
    • Key: rules
    • Owner: Variant
    • Type: JSON

The JSON structure for the rules looks like this:

{
  "cn": "Special Offer",  // Display name in cart & checkout (optional)
  "sd": "2025-09-22T10:14:00Z",  // Start date; if not set, default to current date & time
  "ed": "",  // End date (optional)
  "r": [
    {
      "q": "4",  // Quantity threshold
      "t": "p",  // Type: percentage discount
      "v": "20",  // Value: 20%
      "c": "all"  // Customer segment: all
    },
    {
      "q": "8",
      "t": "p",
      "v": "25",
      "c": "vip"
    }
  ]
}

We’re applying these rules across multiple variants but creating only one discountNode for all variant rules to keep things efficient.

The Issue:

The discounts need to be conditional based on the current date and time (e.g., to check if the campaign is active between sd and ed). However, we’re running into a blocker:

  • We can’t retrieve the current time via the Shopify Function’s GraphQL query input.
  • When we try to get the system date and time programmatically in Rust (e.g., using chrono or similar crates), it doesn’t provide the correct/expected date and time—possibly due to the sandboxed environment or timezone issues in Functions.

Our tech stack is Shopify Functions with Rust.

Question:

How can we reliably get the current date and time within a Shopify Discount Function (in Rust) to validate if the campaign is active? Is there a recommended way to access this via the input query, context, or another method? Any workarounds or best practices would be greatly appreciated, as this is critical for our business logic.

Thanks in advance for any insights!

You cannot do this because Shopify functions are designed to be deterministic.