1 ---
2 sidebar_label: "no-new-date-in-workflow"
3 ---
4
5 export const metadata = {
6 title: `no-new-date-in-workflow - ESLint plugin rules`,
7 }
8
9 # {metadata.title}
10
11 This rule disallows `new Date(...)` and any `Date.*(...)` static-method call directly inside a `createWorkflow` constructor or a `when().then()` callback.
12
13 ## Severity
14
15 `error`. This rule is enabled in the [recommended](../../page.mdx#recommended) preset.
16
17 ## What it Targets
18
19 This rule targets files in your project's `src/workflows` directory. It reports `new Date(...)` and `Date.*(...)` calls placed directly in a workflow's constructor or in a `when().then()` callback.
20
21 The following code is reported by the rule:
22
23 ```ts title="src/workflows/example.ts"
24 import {
25 createWorkflow,
26 WorkflowResponse,
27 } from "@medusajs/framework/workflows-sdk"
28
29 createWorkflow("my-workflow", (input) => {
30 const now = new Date()
31 return new WorkflowResponse(input)
32 })
33 ```
34
35 Instead, wrap the date in `transform` or compute it inside a step:
36
37 ```ts title="src/workflows/example.ts"
38 import {
39 createWorkflow,
40 transform,
41 WorkflowResponse,
42 } from "@medusajs/framework/workflows-sdk"
43
44 createWorkflow("my-workflow", (input) => {
45 const now = transform({}, () => new Date())
46
47 return new WorkflowResponse(now)
48 })
49 ```
50
51 ## Why it's Important
52
53 A workflow's constructor and `when().then()` callbacks run at definition time, not execution time. So, a date created there is fixed when the workflow is registered, not when it runs. Wrap it in `transform` or a `createStep` callback so it evaluates at execution time.
54
55 Learn more in the [Data Manipulation in Workflows documentation](!docs!/learn/fundamentals/workflows/variable-manipulation).
56
57 ## Fixable
58
59 This rule isn't auto-fixable.