docs: explain date math when used with filters
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
kolaente 2024-10-30 14:28:31 +01:00
parent 8c138595a2
commit 2b00f7454b
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
3 changed files with 126 additions and 9 deletions

View File

@ -23,6 +23,9 @@ export default defineMarkdocConfig({
type: {type: String},
},
},
dateMathExamples: {
render: component('./src/components/partials/DateMathExamples.astro'),
},
configOptions: {
render: component('./src/components/partials/ConfigOptions.astro'),
}

View File

@ -0,0 +1,83 @@
<table>
<tbody>
<tr>
<td><code>now</code></td>
<td>Right now (<span id="now">Oct 30, 2024, 14:26:12</span>)</td>
</tr>
<tr>
<td><code>now+24h</code></td>
<td>In 24h (<span id="now24h">Oct 31, 2024, 14:26:12</span>)</td>
</tr>
<tr>
<td><code>now/d</code></td>
<td>Today at 00:00 (<span id="nowD">Oct 30, 2024, 00:00:00</span>)</td>
</tr>
<tr>
<td><code>now/w</code></td>
<td>The beginning of this week at 00:00 (<span id="nowW">Oct 27, 2024, 00:00:00</span>)</td>
</tr>
<tr>
<td><code>now/w+1w</code></td>
<td>The end of this week (<span id="nowW1w">Nov 3, 2024, 00:00:00</span>)</td>
</tr>
<tr>
<td><code>now+30d</code></td>
<td>In 30 days (<span id="now30d">Nov 29, 2024, 00:00:00</span>)</td>
</tr>
<tr>
<td><code><span id="date-math-today">Oct 30, 2024, 14:26:12</span>||+1M/d</code></td>
<td>
<span id="date-math-today">Oct 30, 2024, 14:26:12</span> plus one month at 00:00 of that day (<span id="nowPlusMonth">Nov 30, 2024, 00:00:00</span>)
</td>
</tr>
</tbody>
</table>
<script>
function formatDate(date) {
return date.toLocaleString('en-US', {
year: 'numeric',
month: 'short',
day: 'numeric',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
hour12: false,
})
}
function updateDates() {
const now = new Date()
document.getElementById('now').textContent = formatDate(now)
const now24h = new Date(now.getTime() + 24 * 60 * 60 * 1000)
document.getElementById('now24h').textContent = formatDate(now24h)
const nowD = new Date(now.setHours(0, 0, 0, 0))
document.getElementById('nowD').textContent = formatDate(nowD)
const nowW = new Date(now)
nowW.setDate(now.getDate() - now.getDay())
nowW.setHours(0, 0, 0, 0)
document.getElementById('nowW').textContent = formatDate(nowW)
const nowW1w = new Date(nowW)
nowW1w.setDate(nowW.getDate() + 7)
document.getElementById('nowW1w').textContent = formatDate(nowW1w)
const now30d = new Date(now.getTime() + 30 * 24 * 60 * 60 * 1000)
document.getElementById('now30d').textContent = formatDate(now30d)
const dateMathToday = new Date()
document.getElementById('date-math-today').textContent = formatDate(dateMathToday)
const nowPlusMonth = new Date(dateMathToday)
nowPlusMonth.setMonth(nowPlusMonth.getMonth() + 1)
nowPlusMonth.setHours(0, 0, 0, 0)
document.getElementById('nowPlusMonth').textContent = formatDate(nowPlusMonth)
}
setInterval(updateDates, 1000)
updateDates()
</script>

View File

@ -31,7 +31,7 @@ The available fields for filtering include:
| `created` | The time and date when the task was created. |
| `updated` | The time and date when the task was updated. |
You can date math to set relative dates. Click on the date value in a query to find out more.
You can use date math to set relative dates with any date field. [See below](#date-math) for an explanation.
All strings must be either single-word or enclosed in `"` or `'`. This extends to date values like `2024-03-11`.
@ -59,14 +59,45 @@ To combine multiple conditions, you can use the following logical operators:
| `\|\|` | OR operator | matches if any of the conditions are true |
| `(` and `)` | Parentheses | for grouping conditions |
## Examples
## Date Math
Date Math allows you to specify relative dates which are resolved on the fly by Vikunja when applying the filter.
Each Date Math expression starts with an anchor date, which can either be `now`, or a date string ending with `||`.
This anchor date can optionally be followed by one or more maths expressions, for example:
* `+1d`: Add one day
* `-1d`: Subtract one day
* `/d`: Round down to the nearest day
These expressions are similar to the ones provided by [Grafana](https://grafana.com/docs/grafana/latest/dashboards/time-range-controls/) and [Elasticsearch](https://www.elastic.co/guide/en/elasticsearch/reference/7.3/common-options.html#date-math).
### Supported time units
| | |
|-----|---------|
| `s` | Seconds |
| `m` | Minutes |
| `h` | Hours |
| `d` | Days |
| `w` | Weeks |
| `M` | Months |
| `y` | Years |
### Example date math expressions
{% dateMathExamples %}
{% /dateMathExamples %}
## Filter Examples
Here are some examples of filter queries:
| | |
|--------------------------------------------------------------|-------------------------------------------------------------|
| `priority = 4` | tasks with priority level 4 |
| `dueDate < now` | tasks with a due date in the past |
| `done = false && priority >= 3` | undone tasks with priority level 3 or higher |
| `assignees in user1, user2` | tasks assigned to either user1 or user2 |
| `(priority = 1 \|\| priority = 2) &&` <br > `dueDate <= now` | tasks with priority level 1 or 2 and a due date in the past |
| | |
|------------------------------------------------------|-------------------------------------------------------------|
| `priority = 4` | tasks with priority level 4 |
| `dueDate < now` | tasks with a due date in the past |
| `done = false && priority >= 3` | undone tasks with priority level 3 or higher |
| `assignees in user1, user2` | tasks assigned to either user1 or user2 |
| `(priority = 1 \|\| priority = 2) && dueDate <= now` | tasks with priority level 1 or 2 and a due date in the past |