@@ -66,6 +66,8 @@ still can't create different schedules for, for instance, the days of
6666the week. Let's do this next.
6767
6868
69+ .. _schedy/schedules/basics/constraints :
70+
6971Constraints
7072-----------
7173
@@ -89,7 +91,8 @@ new parameter is ``weekdays``, which is a so called constraint.
8991Constraints can be used to limit the starting days on which the rule is
9092considered. There are a number of these constraints, namely:
9193
92- * ``years ``: limit the years (e.g. ``years: 2016-2018 ``
94+ * ``years ``: limit the years (e.g. ``years: 2016-2018 ``); only years from 1970 to
95+ 2099 are supported
9396* ``months ``: limit based on months of the year (e.g.
9497 ``months: 1-3, 10-12 `` for Jan, Feb, Mar, Oct, Nov and Dec)
9598* ``days ``: limit based on days of the month (e.g.
@@ -157,36 +160,56 @@ If you omit the ``start`` parameter, Schedy assumes that you mean midnight
157160a rule that ends the same moment it starts at wouldn't make sense. We
158161expect it to count for the whole day instead.
159162
160- In order to express what we actually want, there's another parameter named
161- ``end_plus_days `` to tell Schedy how many midnights there are between
162- the start and end time. As we didn't specify this parameter explicitly,
163- it's value is determined by Schedy. If the end time of the rule is prior
164- or equal to its start time, ``end_plus_days `` is assumed to be
165- ``1 ``, otherwise ``0 ``.
166-
167- .. note ::
168-
169- The value of ``end_plus_days `` can't be negative, meaning you can't
170- span a rule backwards in time. Only positive integers and ``0 ``
171- are allowed.
163+ In order to express what we actually want, we'd have to set ``end `` to ``"00:00+1d" ``,
164+ which tells Schedy that there is one midnight between the start and end times. For
165+ convenience, Schedy automatically assumes one midnight between start and end when
166+ you don't specify a number of days explicitly and the start time is prior or equal
167+ to the end time, as in our case.
172168
173169.. note ::
174170
175- You don't need to care about setting ``end_plus_days `` yourself,
176- unless one of your rules should span more than 24 hours, requiring
177- ``end_plus_days: 2 `` or greater.
171+ You don't need to care about setting ``+?d `` yourself unless one of your rules
172+ should span more than 24 hours, requiring ``+1d `` or greater.
178173
179174Having written out what Schedy assumes automatically would result in
180175the following rule, which behaves exactly identical to what we begun with.
181176
182177::
183178
184- - { v: 16, start: "0:00", end: "0:00", end_plus_days: 1 }
179+ - { v: 16, start: "0:00", end: "0:00+1d" }
180+
181+ .. note ::
182+
183+ The rule has been rewritten to take just a single line. This is no
184+ special feature of Schedy, it's rather normal YAML. But writing rules
185+ this way is often more readable, especially if you need to create
186+ multiple similar ones which, for instance, only differ in weekdays,
187+ time or value.
188+
189+ Let's get back to :ref: `schedy/schedules/basics/constraints ` briefly. We know that
190+ constraints limit the days on which a rule starts to be active. This explanation is
191+ not correct in all cases, as you'll see now.
192+
193+ There are some days, such as the last day of a month, which can't be expressed
194+ using constraints explicitly. To allow targeting such days anyway, the ``start ``
195+ parameter of a rule accepts a day shifting suffix as well. Your constraints are
196+ checked for some date, but the rule starts being active some days earlier or later,
197+ relative to the matching date.
198+
199+ Even though you can't specify the last day of a month, you can well specify the
200+ 1st. This rule is active on the last day of February from 6.00 pm to 10.00 pm,
201+ no matter if in a leap year or not::
202+
203+ - { v: 22, start: "18:00-1d", end: "22:00", days: 1, months: 3 }
204+
205+ This one even runs until March 1st, 10.00 pm::
206+
207+ - { v: 22, start: "18:00-1d", end: "22:00+1d", days: 1, months: 3 }
185208
186- Note how the rule has been rewritten to take just a single line. This is
187- no special feature of Schedy, it's rather normal YAML. But writing rules
188- this way is often more readable, especially if you need to create multiple
189- similar ones which, for instance, only differ in weekdays, time or value .
209+ As you noted, the day shift of `` start `` can be negative as well, but not that of
210+ `` end ``, meaning your rules can't span backwards in time. This design decision was
211+ made in order to keep rules readable and the evaluation algorithm simple. It neither
212+ has a technical reason nor does it reduce the expressiveness of rules .
190213
191214
192215.. _schedy/schedules/basics/rules-with-sub-schedules :
0 commit comments