You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 1bbeb94
Browse filesBrowse the repository at this point in the historyBrowse files
fix(formula): date-subtraction refusals name the sub-day datetime() form (#33291)
<!-- claude-projects-attribution: {"github_login":"os-elon-musk"} -->
_Requested by **Elon** · [project
thread](https://claude.ai/code/project/chan_01WedDzV26nniwxv7jC88B9D?thread=cmsg_01WedDzV26nniwxv7jC88B9D4Jsmd91BqTVB7dSii9uJMV)_Fixes#32980
Clause-②: no
Metadata-protocol: none
## 维护者速读
- **改了什么**:公式校验对「两个日期/日期时间字段相减」的拒绝提示(`date-text-arithmetic` 及其各
arm、`date-duration-value`),在 `daysBetween` 旁边补上按小时/分钟算跨度的写法:两侧各包一层
`datetime(…)`,再读 Duration 的 `.getMinutes()` / `.getHours()`;公式文档与
formula 技能表格同步一行。
- **为什么改**:「加班小时 = 结束 − 开始」是 HR 应用第一天就要写的公式,原提示只指向按整天计的
`daysBetween`,能用的写法只能去翻 stdlib 源码才找得到。
- **风险与回滚**:只改提示文案,拒绝码与 params 不变,该写法在 main 上本就校验通过、求值正确(新测试实测 98 小时与
3.5 小时);回滚即 revert 本 PR。
- **先看**:`packages/formula/src/validate.ts`(`shift`
常量,两个拒绝共用这一句);`packages/formula/src/validate-date-text-arithmetic.test.ts`(新增的子日跨度用例)。
- **两分钟验证**:`pnpm --filter @objectstack/formula exec vitest run
src/validate-date-text-arithmetic.test.ts`,预期全绿,其中含 `the sub-day form
reads the hours between two date-time fields`。
- **需要你做的**:无。`skills/**` 那一行已按席位指示移到单独的 PR #33294(Refs #32980,等授权审批人),本
PR 不再受管,复审通过后由本区落地。
## What changes
- `packages/formula/src/validate.ts`: the shared `shift` sentence that
both the `date-text-arithmetic` family (bare, `-fail-closed`,
`-fail-open`, `-run-fails`, `-run-may-fail`) and `date-duration-value`
append now adds: "For a span in hours or minutes, wrap each side in
`datetime(…)` and read the Duration: `(datetime(b) -
datetime(a)).getMinutes()` / `.getHours()`." Codes and params are
unchanged. The `date-arithmetic` refusal (a date plus a number) is
untouched: it is not a span.
- `content/docs/data-modeling/formulas.mdx`: the Date subtraction row
names the same form and gives the hours example. The
`skills/objectstack-formula/SKILL.md` row moved to PR #33294 at
`bb078699`, so this PR is no longer governed.
- One `patch` changeset for `@objectstack/formula`.
## Tests
- `validate-date-text-arithmetic.test.ts`: two control rows in the
gate-versus-evaluator table (`double((datetime(record.end_at) -
datetime(record.start_at)).getMinutes()) / 60.0` and `(now() -
datetime(record.start_at)).getHours()`: both validate clean and evaluate
to a value), and one test that the hours form validates `ok` and
evaluates to `98` and `3.5` on two served rows. These pin the card's
premise: the form works at `origin/main` `d4fbb4db`, before and after
this diff, because only wording changed.
- `expression-refusal-codes.test.ts`: the existing exact-message pins
for the seven affected codes take the new sentence. Those pins are the
file's declared control (the message is what API callers, the CLI and
the agent tool read beside the code), so no new message pin was added.
## Acceptance notes
- Ruled out here, per the dispatch: a new stdlib helper such as
`hoursBetween(a, b)`. It would be a new authorable function (a contract
change), so it needs its own ruling; the card's Expected names it as an
alternative only.
- Not changed:
`packages/spec/src/migrations/entries/semantic/18.formula-date-subtraction-refused.ts`.
Its `replacement` is released 18.x text written by hand, not generated
from the `validate.ts` sentence, so changing it would rewrite a
published migration entry; it still prescribes `daysBetween`, which
remains correct for whole days.
- Skills: no `skills/**` change at head `bb078699` (the row measured at
`4350de67`, 493 → 494 lines, ships in PR #33294).
## Verification
Head `4350de67` (the merge of `origin/main` was a no-op: `origin/main`
had not moved from `d4fbb4db`).
<details><summary>formula test + typecheck (under the verify
lock)</summary>
```
pnpm --filter @objectstack/formula test && pnpm --filter @objectstack/formula typecheck
Test Files 67 passed (67)
Tests 1760 passed (1760)
check:test-typecheck: OK
os-verify-lock: VERDICT command-exit 0
```
</details>
<details><summary>Derived gate families (dispatch-gates --commands, 103
families)</summary>
102 of 103 exit 0 locally, each exit code captured before any pipe. Six
first answered exit 3 (prerequisite not met: unbuilt `formula`, `lint`,
`client-react`, `objectql` dist) and were re-run green after a build of
those packages: `check:doc-formula-expressions`,
`check:doc-security-posture`, `check:skill-examples`,
`check:docs-transcript-drift`, `check:dual-build-cjs-loads`,
`check:lean-entry-closure`. `check:skill-docs` exit 0.
NOT MEASURED: `node scripts/check-plugin-teardown-shape.mjs
--self-test`, reason: shallow clone cannot reach its pinned
positive-control commit; CI runs it on a full checkout.
`dispatch-gates --ran`: 103 derived families accounted for.
`check:nul-bytes`: OK.
</details>
`test:repo` was not run locally (the diff does not touch that project);
`Test Core` carries it in CI.
domain:server#5 · os-elon-musk · session_016WV4cw787kMeaX7oyz7DDC
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_016WV4cw787kMeaX7oyz7DDC
<!-- signed: domain:server#5 · os-elon-musk ·
session_016WV4cw787kMeaX7oyz7DDC -->
---------
Co-authored-by: Claude <noreply@anthropic.com>
fix(formula): the date-subtraction refusals name the sub-day form next to `daysBetween`
6
+
7
+
Clause-②: no
8
+
Metadata-protocol: none
9
+
10
+
The `date-text-arithmetic` refusal (and its flow and fail-closed / fail-open arms) and the `date-duration-value` refusal sent an author who wanted an hour span, such as overtime hours from two date-time fields, to `daysBetween(a, b)`, which counts whole days only. Both refusals now add: for a span in hours or minutes, wrap each side in `datetime(…)` and read the Duration, `(datetime(b) - datetime(a)).getMinutes()` / `.getHours()`. That form already validated and evaluated; only the refusal wording changes, and the refusal codes and params are unchanged.
11
+
12
+
FROM `record.end_at - record.start_at` (refused, `date-text-arithmetic`) TO `double((datetime(record.end_at) - datetime(record.start_at)).getMinutes()) / 60.0` for the hours between them.
Copy file name to clipboardExpand all lines: content/docs/data-modeling/formulas.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -244,7 +244,7 @@ come at two severities: **errors** fail the build; **warnings** are advisory
244
244
|**Unknown function** — a misspelled or nonexistent stdlib call. |`isBlnk(record.x)`| error |
245
245
| **Type soundness** — a text or boolean field used with an arithmetic (`+ - * / %`) or ordering (`< > <= >=`) operator against a number faults at runtime unless the text is numeric. In a formula it evaluates to `null`. Where a fault does something else it is an error, worded for what happens: a validation rule, a field `requiredWhen` / `readonlyWhen`, an option `visibleWhen` or a hook `condition` refuses the write; a record-triggered flow's start, edge or `decision` branch condition fails the run (the write that fired it still lands), whether it reads the field bare or as `record.<field>`, and so does a time-relative flow's that sweeps the same object, where no write fires the run and only the run for that row fails; a bare name that a declared flow variable or a `screen` field holds reads that value, so it is not judged as the field, and a bare name after a node that can bind any name (`script`, `connector_action`, `wait`, `subflow`, `map`, a screen with no fields) gets the warning instead, while its `record.<field>` read is still refused; an advisory (`severity: 'warning'` / `'info'`) validation rule is skipped, so it never gives its advisory. Store it as a number field, compare text with text, or convert explicitly (`size(record.name)` for the length; `double(record.name)`, which itself faults on text that is not a number). | `record.title * 2`; `record.name > 5` in a validation rule → `size(record.name) > 5` | warning in a formula or a display predicate, and in a condition of any other flow, where the warning says the run fails if the condition faults (what such a flow binds under the name depends on how it is started); error at the sites named |
246
246
|**Date arithmetic** — a `date` / `datetime` field used with `+` / `-` against a number (a `YYYY-MM-DD` value is a string at runtime, so this always faulted to `null`). Use the date helpers instead. |`record.end_date - record.start_date + 1` → `daysBetween(record.start_date, record.end_date) + 1`; `today() + 30` → `daysFromNow(30)`; `record.date + n` → `addDays(record.date, n)`| error (#3306) |
247
-
|**Date subtraction** — the runtime holds a `date` / `datetime` field as its text (`YYYY-MM-DD`, or an ISO-8601 instant), so subtracting two of them faults and the formula reads `null`; a timestamp minus one computes a duration, which a field reads as `{}`. Use `daysBetween`. A condition may still compare a duration (`today() - record.start_date > duration("72h")`). |`record.end_date - record.start_date` → `daysBetween(record.start_date, record.end_date)`; `today() - record.start_date` → `daysBetween(record.start_date, today())`| error |
247
+
|**Date subtraction** — the runtime holds a `date` / `datetime` field as its text (`YYYY-MM-DD`, or an ISO-8601 instant), so subtracting two of them faults and the formula reads `null`; a timestamp minus one computes a duration, which a field reads as `{}`. Use `daysBetween`; for hours or minutes, wrap each side in `datetime(…)` and read the Duration. A condition may still compare a duration (`today() - record.start_date > duration("72h")`). |`record.end_date - record.start_date` → `daysBetween(record.start_date, record.end_date)`; `today() - record.start_date` → `daysBetween(record.start_date, today())`; `record.end_at - record.start_at` in hours → `double((datetime(record.end_at) - datetime(record.start_at)).getMinutes()) / 60.0`| error |
248
248
249
249
> **Integer literals in arithmetic are fine.**`record.amount / 100`,
250
250
> `record.price * 2`, `record.total - fee` all work — the engine handles mixed
0 commit comments