ics-query 0.1.0a0__py3-none-any.whl → 0.1.dev1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. ics_query/__init__.py +18 -2
  2. ics_query/__main__.py +15 -0
  3. ics_query/_version.py +2 -2
  4. ics_query/cli.py +620 -18
  5. ics_query/parse.py +78 -4
  6. ics_query/query.py +78 -0
  7. ics_query/tests/conftest.py +68 -20
  8. ics_query/tests/runs/all --tz Singapore one-event.ics -.run +9 -0
  9. ics_query/tests/runs/all three-events.ics -.run +33 -0
  10. ics_query/tests/runs/at 2019-03-04 multiple-calendars.ics -.run +20 -0
  11. ics_query/tests/runs/at 2019-03-04 one-event-twice.ics -.run +18 -0
  12. ics_query/tests/runs/at 2019-03-07 multiple-calendars.ics -.run +11 -0
  13. ics_query/tests/runs/at 2024-08-20 Berlin-Los-Angeles.ics -.run +23 -0
  14. ics_query/tests/runs/between 20240823 4d recurring-work-events.ics -.run +24 -0
  15. ics_query/tests/runs/calendars/Berlin-Los-Angeles.ics +381 -0
  16. ics_query/tests/runs/calendars/empty-calendar.ics +7 -0
  17. ics_query/tests/runs/calendars/empty-file.ics +0 -0
  18. ics_query/tests/runs/calendars/multiple-calendars.ics +71 -0
  19. ics_query/tests/runs/calendars/one-event-twice.ics +68 -0
  20. ics_query/tests/runs/calendars/one-event-without-timezone.ics +14 -0
  21. ics_query/tests/runs/calendars/recurring-work-events.ics +223 -0
  22. ics_query/tests/runs/calendars/simple-journal.ics +15 -0
  23. ics_query/tests/runs/calendars/simple-todo.ics +15 -0
  24. ics_query/tests/runs/calendars/three-events.ics +37 -0
  25. ics_query/tests/runs/first -c VJOURNAL -c VEVENT one-event.ics -.run +9 -0
  26. ics_query/tests/runs/first -c VJOURNAL one-event.ics -.run +0 -0
  27. ics_query/tests/runs/first -c VJOURNAL simple-journal.ics -.run +12 -0
  28. ics_query/tests/runs/first -c VTODO -c VJOURNAL simple-todo.ics -.run +10 -0
  29. ics_query/tests/runs/first -c VTODO simple-todo.ics -.run +10 -0
  30. ics_query/tests/runs/first empty-calendar.ics -.run +0 -0
  31. ics_query/tests/runs/first empty-file.ics -.run +0 -0
  32. ics_query/tests/runs/first recurring-work-events.ics -.run +12 -0
  33. ics_query/tests/test_command_line.py +62 -0
  34. ics_query/tests/test_parse_date.py +81 -0
  35. ics_query/tests/test_parse_timedelta.py +40 -0
  36. ics_query/version.py +36 -3
  37. {ics_query-0.1.0a0.dist-info → ics_query-0.1.dev1.dist-info}/METADATA +366 -43
  38. ics_query-0.1.dev1.dist-info/RECORD +44 -0
  39. ics_query-0.1.0a0.dist-info/RECORD +0 -16
  40. {ics_query-0.1.0a0.dist-info → ics_query-0.1.dev1.dist-info}/WHEEL +0 -0
  41. {ics_query-0.1.0a0.dist-info → ics_query-0.1.dev1.dist-info}/entry_points.txt +0 -0
  42. {ics_query-0.1.0a0.dist-info → ics_query-0.1.dev1.dist-info}/licenses/LICENSE +0 -0
ics_query/cli.py CHANGED
@@ -1,3 +1,18 @@
1
+ # ics-query
2
+ # Copyright (C) 2024 Nicco Kunzmann
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <https://www.gnu.org/licenses/>.
1
16
  """The command line interface."""
2
17
 
3
18
  from __future__ import annotations
@@ -6,23 +21,45 @@ import functools
6
21
  import os # noqa: TCH003
7
22
  import sys
8
23
  import typing as t
24
+ import zoneinfo
9
25
 
10
26
  import click
11
- import recurring_ical_events
12
- from icalendar import Calendar
13
- from recurring_ical_events import CalendarQuery
27
+ from icalendar.cal import Calendar, Component
28
+ from tzlocal import get_localzone_name
14
29
 
15
30
  from . import parse
31
+ from .query import Query
32
+ from .version import cli_version
16
33
 
17
34
  if t.TYPE_CHECKING:
18
35
  from io import FileIO
19
36
 
37
+ import recurring_ical_events
20
38
  from icalendar.cal import Component
21
39
 
22
- from .parse import DateArgument
40
+ from .parse import Date
23
41
 
24
42
  print = functools.partial(print, file=sys.stderr) # noqa: A001
25
43
 
44
+ ENV_PREFIX = "ICS_QUERY"
45
+ LICENSE = """
46
+ ics-query
47
+ Copyright (C) 2024 Nicco Kunzmann
48
+
49
+ This program is free software: you can redistribute it and/or modify
50
+ it under the terms of the GNU General Public License as published by
51
+ the Free Software Foundation, either version 3 of the License, or
52
+ (at your option) any later version.
53
+
54
+ This program is distributed in the hope that it will be useful,
55
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
56
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
57
+ GNU General Public License for more details.
58
+
59
+ You should have received a copy of the GNU General Public License
60
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
61
+ """
62
+
26
63
 
27
64
  class ComponentsResult:
28
65
  """Output interface for components."""
@@ -35,6 +72,11 @@ class ComponentsResult:
35
72
  """Return a component."""
36
73
  self._file.write(component.to_ical())
37
74
 
75
+ def add_components(self, components: t.Iterable[Component]):
76
+ """Add all components."""
77
+ for component in components:
78
+ self.add_component(component)
79
+
38
80
 
39
81
  class ComponentsResultArgument(click.File):
40
82
  """Argument for the result."""
@@ -50,6 +92,39 @@ class ComponentsResultArgument(click.File):
50
92
  return ComponentsResult(file)
51
93
 
52
94
 
95
+ class JoinedCalendars:
96
+ def __init__(
97
+ self, calendars: list[Calendar], timezone: str, components: t.Sequence[str]
98
+ ):
99
+ """Join multiple calendars."""
100
+ self.queries = [
101
+ Query(calendar, timezone, components=components) for calendar in calendars
102
+ ]
103
+
104
+ def at(self, dt: tuple[int]) -> t.Generator[Component]:
105
+ """Return the components."""
106
+ for query in self.queries:
107
+ yield from query.at(dt)
108
+
109
+ def first(self) -> t.Generator[Component]:
110
+ """Return the first events of all calendars."""
111
+ for query in self.queries:
112
+ for component in query.all():
113
+ yield component
114
+ break
115
+
116
+ def all(self) -> t.Generator[Component]:
117
+ """Return the first events of all calendars."""
118
+ for query in self.queries:
119
+ yield from query.all()
120
+
121
+ def between(
122
+ self, start: parse.Date, end: parse.DateAndDelta
123
+ ) -> t.Generator[Component]:
124
+ for query in self.queries:
125
+ yield from query.between(start, end)
126
+
127
+
53
128
  class CalendarQueryInputArgument(click.File):
54
129
  """Argument for the result."""
55
130
 
@@ -61,32 +136,559 @@ class CalendarQueryInputArgument(click.File):
61
136
  ) -> recurring_ical_events.CalendarQuery:
62
137
  """Return a CalendarQuery."""
63
138
  file = super().convert(value, param, ctx)
64
- calendar = Calendar.from_ical(file.read())
65
- return recurring_ical_events.of(calendar)
139
+ calendars = Calendar.from_ical(file.read(), multiple=True)
140
+ components = ctx.params.get("component", ("VEVENT", "VTODO", "VJOURNAL"))
141
+ timezone = ctx.params.get("tz", "")
142
+ return JoinedCalendars(calendars, timezone, components)
143
+
144
+
145
+ opt_components = click.option(
146
+ "--component",
147
+ "-c",
148
+ multiple=True,
149
+ envvar=ENV_PREFIX + "_COMPONENT",
150
+ help=(
151
+ "Select the components which can be returned. "
152
+ "By default all supported components can be in the result. "
153
+ "Possible values are: VEVENT, VTODO, VJOURNAL. "
154
+ ),
155
+ )
156
+
157
+ opt_timezone = click.option(
158
+ "--tz",
159
+ envvar=ENV_PREFIX + "_TZ",
160
+ help=("Set the timezone. See also --available-timezones"),
161
+ )
162
+
163
+
164
+ def arg_calendar(func):
165
+ """Decorator for a calendar argument with all used options."""
166
+ arg = click.argument("calendar", type=CalendarQueryInputArgument("rb"))
167
+
168
+ @functools.wraps(func)
169
+ def wrapper(*args, component=(), tz="", **kw): # noqa: ARG001
170
+ """Remove some parameters."""
171
+ return func(*args, **kw)
66
172
 
173
+ return opt_timezone(opt_components(arg(wrapper)))
67
174
 
68
- arg_calendar = click.argument("calendar", type=CalendarQueryInputArgument("rb"))
69
- arg_output = click.argument("output", type=ComponentsResultArgument("wb"))
175
+
176
+ arg_output = click.argument("output", type=ComponentsResultArgument("wb"), default="-")
177
+ # Option with many values and list as result
178
+ # see https://click.palletsprojects.com/en/latest/options/#multiple-options
179
+
180
+
181
+ def opt_available_timezones(*param_decls: str, **kwargs: t.Any) -> t.Callable:
182
+ """List available timezones.
183
+
184
+ This is copied from the --help option.
185
+
186
+ Commonly used timezone names are added first.
187
+ """
188
+
189
+ def callback(ctx: click.Context, param: click.Parameter, value: bool) -> None: # noqa: FBT001, ARG001
190
+ if not value or ctx.resilient_parsing:
191
+ return
192
+
193
+ click.echo("localtime") # special local time handle
194
+ click.echo(get_localzone_name())
195
+ click.echo("UTC")
196
+ all_zones = zoneinfo.available_timezones()
197
+ for zone in sorted(all_zones, key=str.lower):
198
+ click.echo(zone)
199
+ ctx.exit()
200
+
201
+ if not param_decls:
202
+ param_decls = ("--available-timezones",)
203
+
204
+ kwargs.setdefault("is_flag", True)
205
+ kwargs.setdefault("expose_value", False)
206
+ kwargs.setdefault("is_eager", True)
207
+ kwargs.setdefault("help", "List all available timezones and exit.")
208
+ kwargs["callback"] = callback
209
+ return click.option(*param_decls, **kwargs)
210
+
211
+
212
+ def opt_license(*param_decls: str, **kwargs: t.Any) -> t.Callable:
213
+ """List available timezones.
214
+
215
+ This is copied from the --help option.
216
+ """
217
+
218
+ def callback(ctx: click.Context, param: click.Parameter, value: bool) -> None: # noqa: FBT001, ARG001
219
+ if not value or ctx.resilient_parsing:
220
+ return
221
+ click.echo(LICENSE)
222
+ ctx.exit()
223
+
224
+ if not param_decls:
225
+ param_decls = ("--license",)
226
+
227
+ kwargs.setdefault("is_flag", True)
228
+ kwargs.setdefault("expose_value", False)
229
+ kwargs.setdefault("is_eager", True)
230
+ kwargs.setdefault("help", "Show the license and exit.")
231
+ kwargs["callback"] = callback
232
+ return click.option(*param_decls, **kwargs)
70
233
 
71
234
 
72
235
  @click.group()
73
- def main():
74
- """Simple program that greets NAME for a total of COUNT times."""
75
- # sys.stdout = sys.stderr # remove accidential print impact
236
+ @click.version_option(cli_version)
237
+ @opt_available_timezones()
238
+ @opt_license()
239
+ def cli():
240
+ """Find out what happens in ICS calendar files.
241
+
242
+ ics-query can query and filter RFC 5545 compatible .ics files.
243
+ Components are events, journal entries and TODOs.
244
+
245
+ \b
246
+ Common Parameters
247
+ -----------------
248
+
249
+ Common parameters are described below.
250
+
251
+ CALENDAR
252
+
253
+ The CALENDAR is a readable file with one or more ICS calendars in it.
254
+ If CALENDAR is "-", then the standard input is used.
255
+
256
+ OUTPUT
257
+
258
+ This is the OUTPUT file for the result.
259
+ It is usually a path to a file that can be written to.
260
+ If OUTPUT is "-", then the standard output is used.
261
+
262
+ \b
263
+ Calculation
264
+ -----------
265
+
266
+ An event can be very long. If you request smaller time spans or a time as
267
+ exact as a second, the event will still occur within this time span if it
268
+ happens during that time.
269
+
270
+ Generally, an event occurs within a time span if this applies:
271
+
272
+ event.DTSTART <= span.DTEND and span.DTSTART < event.DTEND
273
+
274
+ The START is INCLUSIVE, then END is EXCLUSIVE.
275
+
276
+ \b
277
+ Timezones
278
+ ---------
279
+
280
+ We have several timezones available to choose from.
281
+ While the calendar entries might use their own timezone definitions,
282
+ the timezone parameters of ics-query use the timezone definitions of
283
+ Python's tzdata package.
284
+
285
+ You can list all timezones available with this command:
286
+
287
+ \b
288
+ ics-query --available-timezones
289
+
290
+ By default the local time of the components is assumed.
291
+ In this example, two events happen at 6am, one in Berlin and one in Los Angeles.
292
+ Both are hours apart though.
293
+
294
+ \b
295
+ $ ics-query at 2024-08-20 Berlin-Los-Angeles.ics - | grep -E 'DTSTART|SUMMARY'
296
+ SUMMARY:6:00-7:00 Europe/Berlin 20th August
297
+ DTSTART;TZID=Europe/Berlin:20240820T060000
298
+ SUMMARY:6:00-7:00 Amerika/Los Angeles 20th August
299
+ DTSTART;TZID=America/Los_Angeles:20240820T060000
300
+
301
+ If you however wish to get all events in a certain timezone, use the --tz parameter.
302
+ In this example, the event that happens at the 19th of August at 21:00 in
303
+ Los Angeles is actually happening on the 20th in local Berlin time.
304
+
305
+ \b
306
+ $ ics-query at --tz=Europe/Berlin 2024-08-20 Berlin-Los-Angeles.ics - \\
307
+ | grep -E 'DTSTART|SUMMARY'
308
+ SUMMARY:6:00-7:00 Europe/Berlin 20th August
309
+ DTSTART;TZID=Europe/Berlin:20240820T060000
310
+ SUMMARY:6:00-7:00 Amerika/Los Angeles 20th August
311
+ DTSTART;TZID=Europe/Berlin:20240820T150000
312
+ SUMMARY:21:00-22:00 Amerika/Los Angeles 19th August
313
+ DTSTART;TZID=Europe/Berlin:20240820T060000
314
+
315
+ If you wish to get events in your local time, use --tz localtime.
316
+ If you like UTC, use --tz UTC.
317
+
318
+ You can also set the environment variable ICS_QUERY_TZ to the timezone instead of
319
+ passing --tz.
320
+
321
+ \b
322
+ Components
323
+ ----------
324
+
325
+ We support different types of recurring components: VEVENT, VTODO, VJOURNAL.
326
+ You can specify which can be in the result using the --component parameter.
327
+
328
+ You can also set the environment variable ICS_QUERY_COMPONENT to the timezone
329
+ instead of passing --component.
330
+
331
+ """ # noqa: D301
76
332
 
77
333
 
78
334
  pass_datetime = click.make_pass_decorator(parse.to_time)
79
335
 
80
336
 
81
- @main.command()
337
+ @cli.command()
82
338
  @click.argument("date", type=parse.to_time)
83
339
  @arg_calendar
84
340
  @arg_output
85
- def at(calendar: CalendarQuery, output: ComponentsResult, date: DateArgument):
86
- """Get the components at a certain time."""
87
- for event in calendar.at(date):
88
- print("debug")
89
- output.add_component(event)
341
+ def at(calendar: JoinedCalendars, output: ComponentsResult, date: Date):
342
+ """Print occurrences at a certain date or time.
343
+
344
+ YEAR
345
+
346
+ All occurrences in this year.
347
+
348
+ \b
349
+ Formats:
350
+ \b
351
+ YYYY
352
+ \b
353
+ Examples:
354
+ \b
355
+ ics-query at 2024 # all occurrences in year 2024
356
+ ics-query at `date +%Y` # all occurrences in this year
357
+
358
+ MONTH
359
+
360
+ All occurrences in this month.
361
+
362
+ \b
363
+ Formats:
364
+ \b
365
+ YYYY-MM
366
+ YYYY-M
367
+ YYYYMM
368
+ \b
369
+ Examples:
370
+ \b
371
+ ics-query at 2019-10 # October 2019
372
+ ics-query at 1990-01 # January 1990
373
+ ics-query at 1990-1 # January 1990
374
+ ics-query at 199001 # January 1990
375
+ ics-query at `date +%Y%m` # this month
376
+
377
+ DAY
378
+
379
+ All occurrences in one day.
380
+
381
+ \b
382
+ Formats:
383
+ \b
384
+ YYYY-MM-DD
385
+ YYYY-M-D
386
+ YYYYMMDD
387
+ \b
388
+ Examples:
389
+ \b
390
+ ics-query at 1990-01-01 # 1st January 1990
391
+ ics-query at 1990-1-1 # 1st January 1990
392
+ ics-query at 19900101 # 1st January 1990
393
+ ics-query at `date +%Y%m%d` # today
394
+
395
+ HOUR
396
+
397
+ All occurrences within one hour.
398
+
399
+ \b
400
+ Formats:
401
+ \b
402
+ YYYY-MM-DD HH
403
+ YYYY-MM-DDTHH
404
+ YYYY-M-DTH
405
+ YYYYMMDDTHH
406
+ YYYYMMDDHH
407
+ \b
408
+ Examples:
409
+ \b
410
+ ics-query at 1990-01-01 00 # 1st January 1990, 12am - 1am
411
+ ics-query at 1990-01-01T00 # 1st January 1990, 12am - 1am
412
+ ics-query at 1990-1-1T17 # 1st January 1990, 17:00 - 18:00
413
+ ics-query at 19900101T23 # 1st January 1990, 23:00 - midnight
414
+ ics-query at 1990010123 # 1st January 1990, 23:00 - midnight
415
+ ics-query at `date +%Y%m%d%H` # this hour
416
+
417
+ MINUTE
418
+
419
+ All occurrences within one minute.
420
+
421
+ \b
422
+ Formats:
423
+ \b
424
+ YYYY-MM-DD HH:MM
425
+ YYYY-MM-DDTHH:MM
426
+ YYYY-M-DTH:M
427
+ YYYYMMDDTHHMM
428
+ YYYYMMDDHHMM
429
+ \b
430
+ Examples:
431
+ \b
432
+ ics-query at 1990-01-01 10:10 # 1st January 1990, 10:10am - 10:11am
433
+ ics-query at 1990-01-01T10:10 # 1st January 1990, 10:10am - 10:11am
434
+ ics-query at 1990-1-1T7:2 # 1st January 1990, 07:02 - 07:03
435
+ ics-query at 19900101T2359 # 1st January 1990, 23:59 - midnight
436
+ ics-query at 199001012359 # 1st January 1990, 23:59 - midnight
437
+ ics-query at `date +%Y%m%d%H%M` # this minute
438
+
439
+ SECOND
440
+
441
+ All occurrences at a precise time.
442
+
443
+ \b
444
+ Formats:
445
+ \b
446
+ YYYY-MM-DD HH:MM:SS
447
+ YYYY-MM-DDTHH:MM:SS
448
+ YYYY-M-DTH:M:S
449
+ YYYYMMDDTHHMMSS
450
+ YYYYMMDDHHMMSS
451
+ \b
452
+ Examples:
453
+ \b
454
+ ics-query at 1990-01-01 10:10:00 # 1st January 1990, 10:10am
455
+ ics-query at 1990-01-01T10:10:00 # 1st January 1990, 10:10am
456
+ ics-query at 1990-1-1T7:2:30 # 1st January 1990, 07:02:30
457
+ ics-query at 19901231T235959 # 31st December 1990, 23:59:59
458
+ ics-query at 19900101235959 # 1st January 1990, 23:59:59
459
+ ics-query at `date +%Y%m%d%H%M%S` # now
460
+ """ # noqa: D301
461
+ output.add_components(calendar.at(date))
462
+
463
+
464
+ @cli.command()
465
+ @arg_calendar
466
+ @arg_output
467
+ def first(calendar: JoinedCalendars, output: ComponentsResult):
468
+ """Print only the first occurrence.
469
+
470
+ This prints the first occurrence in each calendar that is given.
471
+
472
+ \b
473
+ This example prints the first event in calendar.ics:
474
+ \b
475
+ ics-query first --component VEVENT calendar.ics -
476
+
477
+ """ # noqa: D301
478
+ output.add_components(calendar.first())
479
+
480
+
481
+ @cli.command()
482
+ @arg_calendar
483
+ @arg_output
484
+ def all(calendar: JoinedCalendars, output: ComponentsResult): # noqa: A001
485
+ """Print all occurrences in a calendar.
486
+
487
+ The result is ordered by the start of the occurrences.
488
+ If you have multiple calendars, the result will contain
489
+ the occurrences of the first calendar before those of the second calendar
490
+ and so on.
491
+
492
+ \b
493
+ This example prints all events in calendar.ics:
494
+ \b
495
+ ics-query all --component VEVENT calendar.ics -
496
+
497
+ Note that calendars can create hundreds of occurrences and especially
498
+ contain endless repetitions. Use this with care as the output is
499
+ potentially enourmous. You can mitigate this by closing the OUTPUT
500
+ when you have enough e.g. with a head command.
501
+ """ # noqa: D301
502
+ output.add_components(calendar.all())
503
+
504
+
505
+ @cli.command()
506
+ @click.argument("start", type=parse.to_time)
507
+ @click.argument("end", type=parse.to_time_and_delta)
508
+ @arg_calendar
509
+ @arg_output
510
+ def between(
511
+ start: parse.Date,
512
+ end: parse.DateAndDelta,
513
+ calendar: JoinedCalendars,
514
+ output: ComponentsResult,
515
+ ):
516
+ """Print occurrences between a START and an END.
517
+
518
+ The start is inclusive, the end is exclusive.
519
+
520
+ This example returns the events within the next week:
521
+
522
+ \b
523
+ ics-query between --component VEVENT `date +%Y%m%d` +7d calendar.ics -
524
+
525
+ This example saves the events from the 1st of May 2024 to the 10th of June in
526
+ events.ics:
527
+
528
+ \b
529
+ ics-query between --component VEVENT 2024-5-1 2024-6-10 calendar.ics events.ics
530
+
531
+ In this example, you can check what is happening on New Years Eve 2025 around
532
+ midnight:
533
+
534
+ \b
535
+ ics-query between 2025-12-31T21:00 +6h calendar.ics events.ics
536
+
537
+ \b
538
+ Absolute Time
539
+ -------------
540
+
541
+ START must be specified as an absolute time.
542
+ END can be absolute or relative to START, see Relative Time below.
543
+
544
+ Each of the formats specify the earliest time e.g. the start of a day.
545
+ Thus, if START == END, there are 0 seconds in between and the result is
546
+ only what happens during that time or starts exactly at that time.
547
+
548
+ YEAR
549
+
550
+ Specifiy the start of the year.
551
+
552
+ \b
553
+ Formats:
554
+ \b
555
+ YYYY
556
+ \b
557
+ Examples:
558
+ \b
559
+ 2024 # start of 2024
560
+ `date +%Y` # this year
561
+
562
+ MONTH
563
+
564
+ The start of the month.
565
+
566
+ \b
567
+ Formats:
568
+ \b
569
+ YYYY-MM
570
+ YYYY-M
571
+ YYYYMM
572
+ \b
573
+ Examples:
574
+ \b
575
+ 2019-10 # October 2019
576
+ 1990-01 # January 1990
577
+ 1990-1 # January 1990
578
+ 199001 # January 1990
579
+ `date +%Y%m` # this month
580
+
581
+ DAY
582
+
583
+ The start of the day
584
+
585
+ \b
586
+ Formats:
587
+ \b
588
+ YYYY-MM-DD
589
+ YYYY-M-D
590
+ YYYYMMDD
591
+ \b
592
+ Examples:
593
+ \b
594
+ 1990-01-01 # 1st January 1990
595
+ 1990-1-1 # 1st January 1990
596
+ 19900101 # 1st January 1990
597
+ `date +%Y%m%d` # today
598
+
599
+ HOUR
600
+
601
+ The start of the hour.
602
+
603
+ \b
604
+ Formats:
605
+ \b
606
+ YYYY-MM-DD HH
607
+ YYYY-MM-DDTHH
608
+ YYYY-M-DTH
609
+ YYYYMMDDTHH
610
+ YYYYMMDDHH
611
+ \b
612
+ Examples:
613
+ \b
614
+ 1990-01-01 01 # 1st January 1990, 1am
615
+ 1990-01-01T01 # 1st January 1990, 1am
616
+ 1990-1-1T17 # 1st January 1990, 17:00
617
+ 19900101T23 # 1st January 1990, 23:00
618
+ 1990010123 # 1st January 1990, 23:00
619
+ `date +%Y%m%d%H` # this hour
620
+
621
+ MINUTE
622
+
623
+ The start of a minute.
624
+
625
+ \b
626
+ Formats:
627
+ \b
628
+ YYYY-MM-DD HH:MM
629
+ YYYY-MM-DDTHH:MM
630
+ YYYY-M-DTH:M
631
+ YYYYMMDDTHHMM
632
+ YYYYMMDDHHMM
633
+ \b
634
+ Examples:
635
+ \b
636
+ 1990-01-01 10:10 # 1st January 1990, 10:10am
637
+ 1990-01-01T10:10 # 1st January 1990, 10:10am
638
+ 1990-1-1T7:2 # 1st January 1990, 07:02
639
+ 19900101T2359 # 1st January 1990, 23:59
640
+ 199001012359 # 1st January 1990, 23:59
641
+ `date +%Y%m%d%H%M` # this minute
642
+
643
+ SECOND
644
+
645
+ A precise time. RFC 5545 calendars are specified to the second.
646
+ This is the most precise format to specify times.
647
+
648
+ \b
649
+ Formats:
650
+ \b
651
+ YYYY-MM-DD HH:MM:SS
652
+ YYYY-MM-DDTHH:MM:SS
653
+ YYYY-M-DTH:M:S
654
+ YYYYMMDDTHHMMSS
655
+ YYYYMMDDHHMMSS
656
+ \b
657
+ Examples:
658
+ \b
659
+ 1990-01-01 10:10:00 # 1st January 1990, 10:10am
660
+ 1990-01-01T10:10:00 # 1st January 1990, 10:10am
661
+ 1990-1-1T7:2:30 # 1st January 1990, 07:02:30
662
+ 19901231T235959 # 31st December 1990, 23:59:59
663
+ 19900101235959 # 1st January 1990, 23:59:59
664
+ `date +%Y%m%d%H%M%S` # now
665
+ \b
666
+ Relative Time
667
+ -------------
668
+
669
+ The END argument can be a time range.
670
+ The + at the beginning is optional but makes for a better reading.
671
+
672
+ \b
673
+ Examples:
674
+ \b
675
+ Add 10 days to START: +10d
676
+ Add 24 hours to START: +1d or +24h
677
+ Add 3 hours to START: +3h
678
+ Add 30 minutes to START: +30m
679
+ Add 1000 seconds to START: +1000s
680
+ \b
681
+ You can also combine the ranges:
682
+ Add 1 day and 12 hours to START: +1d12h
683
+ Add 3 hours and 15 minutes to START: +3h15m
684
+
685
+ """ # noqa: D301
686
+ output.add_components(calendar.between(start, end))
687
+
688
+
689
+ def main():
690
+ """Run the program."""
691
+ cli(auto_envvar_prefix=ENV_PREFIX)
90
692
 
91
693
 
92
- __all__ = ["main"]
694
+ __all__ = ["main", "ENV_PREFIX", "cli"]