Commit ef560a3
authored
feat(typeEvaluator): add support for number + datetime operation (#317)
### TL;DR
Adds support for commutative addition between numbers and datetime values.
https://linear.app/sanity/issue/CLDX-4468/add-support-for-number-datetime-in-groq-js
### What changed?
`number + datetime` is now supported in addition to `datetime + number`
### How to test?
Run the new test case that verifies a datetime can be added to a number:
```typescript
t.test('number + dateTime', (t) => {
const query = `(60 + global::dateTime("2025-03-01T00:00:00Z")) > global::dateTime("2024-03-01T00:00:00Z")`
const ast = parse(query)
const res = typeEvaluate(ast, schemas)
t.same(res, {
type: 'union',
of: [{type: 'boolean', value: undefined}, {type: 'null'}],
})
t.end()
})
```
### Why make this change?
Gradient supports these operations (even though they're not defined in the spec). We should update the spec too, but this change at least gets `groq-js` in line with the actual query engine behaviour, which is what users expect.1 parent 93e4335 commit ef560a3
2 files changed
+16
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
38 | 37 | | |
39 | 38 | | |
40 | 39 | | |
| |||
44 | 43 | | |
45 | 44 | | |
46 | 45 | | |
| 46 | + | |
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| |||
621 | 621 | | |
622 | 622 | | |
623 | 623 | | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
624 | 628 | | |
625 | 629 | | |
626 | 630 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3746 | 3746 | | |
3747 | 3747 | | |
3748 | 3748 | | |
| 3749 | + | |
| 3750 | + | |
| 3751 | + | |
| 3752 | + | |
| 3753 | + | |
| 3754 | + | |
| 3755 | + | |
| 3756 | + | |
| 3757 | + | |
| 3758 | + | |
| 3759 | + | |
3749 | 3760 | | |
3750 | 3761 | | |
3751 | 3762 | | |
| |||
0 commit comments