|
| 1 | +# Examples |
| 2 | + |
| 3 | +`ics-query` takes a command, a time argument, one or more calendar files, and an output. |
| 4 | +Pass `-` as the calendar to read from stdin. Pass `-` as the output to write to stdout. |
| 5 | + |
| 6 | +```shell |
| 7 | +ics-query at 2019-03-04 calendar.ics - |
| 8 | +``` |
| 9 | + |
| 10 | +## Events at a specific time |
| 11 | + |
| 12 | +Use `at` to get all occurrences at a date, month, year, or precise time. |
| 13 | + |
| 14 | +Get everything happening on a specific day: |
| 15 | + |
| 16 | +```shell |
| 17 | +ics-query at 2019-03-04 calendar.ics - |
| 18 | +``` |
| 19 | + |
| 20 | +Get everything happening this month: |
| 21 | + |
| 22 | +```shell |
| 23 | +ics-query at `date +%Y-%m` calendar.ics - |
| 24 | +``` |
| 25 | + |
| 26 | +Get everything happening right now (to the second): |
| 27 | + |
| 28 | +```shell |
| 29 | +ics-query at `date +%Y%m%d%H%M%S` calendar.ics - |
| 30 | +``` |
| 31 | + |
| 32 | +Accepted time formats for `at` and for the `START` argument of `between`: |
| 33 | + |
| 34 | +| Format | Description | |
| 35 | +| ------ | ----------- | |
| 36 | +| `2019` | all of 2019 | |
| 37 | +| `2019-08` | August 2019 | |
| 38 | +| `2019-08-12` | 12 August 2019 | |
| 39 | +| `2019-08-12T17` | 17:00 to 18:00 on 12 August 2019 | |
| 40 | +| `2019-08-12T17:20` | 17:20 to 17:21 on 12 August 2019 | |
| 41 | +| `2019-08-12T17:20:00` | exactly 17:20:00 on 12 August 2019 | |
| 42 | + |
| 43 | +Compact formats without separators are also accepted: `20190812`, `20190812T1720`, `201908121720`. |
| 44 | + |
| 45 | +## Events within a time span |
| 46 | + |
| 47 | +Use `between` to get occurrences between a start and an end. |
| 48 | +Start is inclusive, end is exclusive. |
| 49 | + |
| 50 | +Get events in the next 7 days: |
| 51 | + |
| 52 | +```shell |
| 53 | +ics-query between `date +%Y%m%d` +7d calendar.ics - |
| 54 | +``` |
| 55 | + |
| 56 | +Get events between two specific dates: |
| 57 | + |
| 58 | +```shell |
| 59 | +ics-query between 2024-05-01 2024-06-10 calendar.ics events.ics |
| 60 | +``` |
| 61 | + |
| 62 | +Get events around New Year's Eve midnight: |
| 63 | + |
| 64 | +```shell |
| 65 | +ics-query between 2025-12-31T21:00 +6h calendar.ics - |
| 66 | +``` |
| 67 | + |
| 68 | +The `END` argument can be a relative duration after `START`: |
| 69 | + |
| 70 | +| Duration | Description | |
| 71 | +| -------- | ----------- | |
| 72 | +| `+1d` | one day | |
| 73 | +| `+1h` | one hour | |
| 74 | +| `+1m` | one minute | |
| 75 | +| `+1s` | one second | |
| 76 | +| `+3600s` | one hour as seconds | |
| 77 | +| `+5d10h` | five days and 10 hours | |
| 78 | + |
| 79 | +The `+` prefix is optional. |
| 80 | + |
| 81 | +## First occurrence |
| 82 | + |
| 83 | +Use `first` to get only the first occurrence in each calendar file. |
| 84 | + |
| 85 | +```shell |
| 86 | +ics-query first calendar.ics - |
| 87 | +``` |
| 88 | + |
| 89 | +## All occurrences |
| 90 | + |
| 91 | +Use `all` to get every occurrence in a calendar. |
| 92 | + |
| 93 | +```shell |
| 94 | +ics-query all calendar.ics - |
| 95 | +``` |
| 96 | + |
| 97 | +Calendars with recurring events can produce a very large number of occurrences. |
| 98 | +Use `head` to limit the output: |
| 99 | + |
| 100 | +```shell |
| 101 | +ics-query all calendar.ics - | head -100 |
| 102 | +``` |
| 103 | + |
| 104 | +## Filtering by component type |
| 105 | + |
| 106 | +By default, `ics-query` returns `VEVENT`, `VTODO`, and `VJOURNAL` components. |
| 107 | +Use `-c` or `--component` to filter. |
| 108 | + |
| 109 | +Only events: |
| 110 | + |
| 111 | +```shell |
| 112 | +ics-query at 2024-08 -c VEVENT calendar.ics - |
| 113 | +``` |
| 114 | + |
| 115 | +Only to-dos: |
| 116 | + |
| 117 | +```shell |
| 118 | +ics-query at 2024-08 -c VTODO calendar.ics - |
| 119 | +``` |
| 120 | + |
| 121 | +Only journal entries: |
| 122 | + |
| 123 | +```shell |
| 124 | +ics-query at 2024-08 -c VJOURNAL calendar.ics - |
| 125 | +``` |
| 126 | + |
| 127 | +Pass `-c` multiple times to include more than one type: |
| 128 | + |
| 129 | +```shell |
| 130 | +ics-query at 2024-08 -c VEVENT -c VTODO calendar.ics - |
| 131 | +``` |
| 132 | + |
| 133 | +You can also set the component via environment variable: |
| 134 | + |
| 135 | +```shell |
| 136 | +export ICS_QUERY_COMPONENT=VEVENT |
| 137 | +ics-query at 2024-08 calendar.ics - |
| 138 | +``` |
| 139 | + |
| 140 | +## Querying alarms |
| 141 | + |
| 142 | +Use `-c VALARM` to query components by their alarm times. |
| 143 | +`VALARM` is not included in the default output. |
| 144 | + |
| 145 | +Alarms behave differently from other components: |
| 146 | + |
| 147 | +- The parent component (`VEVENT`, `VTODO`) may fall outside the queried time span |
| 148 | + while the alarm falls within it, and it will still be included. |
| 149 | +- Absolute alarms may appear only once, not for every recurrence. |
| 150 | +- Each result contains only one alarm. |
| 151 | +- Do not mix `-c VALARM` with other types. You will not be able to tell whether |
| 152 | + the alarm or the parent component matched the time span. |
| 153 | + |
| 154 | +Get all alarms and show their trigger time and event summary: |
| 155 | + |
| 156 | +```shell |
| 157 | +ics-query all -c VALARM calendar.ics - | grep -E 'TRIGGER|SUMMARY' |
| 158 | +``` |
| 159 | + |
| 160 | +## Timezones |
| 161 | + |
| 162 | +By default, `ics-query` uses each component's own timezone. |
| 163 | +Two events at 6am in different timezones both appear when you query by date, |
| 164 | +even though they are hours apart in absolute time. |
| 165 | + |
| 166 | +Use `--tz` to query in a specific timezone: |
| 167 | + |
| 168 | +```shell |
| 169 | +ics-query at --tz=Europe/Berlin 2024-08-20 calendar.ics - |
| 170 | +``` |
| 171 | + |
| 172 | +Use `--tz=localtime` to query in your local system timezone: |
| 173 | + |
| 174 | +```shell |
| 175 | +ics-query at --tz=localtime 2024-08-20 calendar.ics - |
| 176 | +``` |
| 177 | + |
| 178 | +Use `--tz=UTC` for UTC: |
| 179 | + |
| 180 | +```shell |
| 181 | +ics-query at --tz=UTC 2024-08-20 calendar.ics - |
| 182 | +``` |
| 183 | + |
| 184 | +Set the timezone via environment variable: |
| 185 | + |
| 186 | +```shell |
| 187 | +export ICS_QUERY_TZ=Europe/Berlin |
| 188 | +ics-query at 2024-08-20 calendar.ics - |
| 189 | +``` |
| 190 | + |
| 191 | +List all available timezone names: |
| 192 | + |
| 193 | +```shell |
| 194 | +ics-query --available-timezones |
| 195 | +``` |
| 196 | + |
| 197 | +## Valid ICS output |
| 198 | + |
| 199 | +By default, the output contains only the matched components with no `VCALENDAR` wrapper |
| 200 | +and no `VTIMEZONE`. This is intentional for piping into other tools. |
| 201 | + |
| 202 | +To produce a valid `.ics` file that calendar applications can open, use `--as-calendar`: |
| 203 | + |
| 204 | +```shell |
| 205 | +ics-query at --as-calendar 2014-05-03 calendar.ics output.ics |
| 206 | +``` |
| 207 | + |
| 208 | +The output is wrapped in a `VCALENDAR` block and includes any `VTIMEZONE` components |
| 209 | +from the source calendar. |
| 210 | + |
| 211 | +You can also set this via environment variable: |
| 212 | + |
| 213 | +```shell |
| 214 | +export ICS_QUERY_AS_CALENDAR=1 |
| 215 | +ics-query at 2014-05-03 calendar.ics output.ics |
| 216 | +``` |
| 217 | + |
| 218 | +## Multiple calendars |
| 219 | + |
| 220 | +Pass multiple files directly: |
| 221 | + |
| 222 | +```shell |
| 223 | +ics-query at 2024-08 calendar1.ics calendar2.ics - |
| 224 | +``` |
| 225 | + |
| 226 | +Or concatenate them through stdin: |
| 227 | + |
| 228 | +```shell |
| 229 | +cat calendar1.ics calendar2.ics | ics-query at 2024-08 - - |
| 230 | +``` |
| 231 | + |
| 232 | +## Fetching a calendar from the web |
| 233 | + |
| 234 | +```shell |
| 235 | +wget -qO- 'https://example.com/calendar.ics' | ics-query at 2024-08 - - |
| 236 | +``` |
0 commit comments