@@ -49,7 +49,7 @@ the 16 degrees-rule and Schedy evaluates rules from top to bottom. From
4949 the value to set. Consequently, you should design your schedules with
5050 the most specific rules at the top and gradually generalize to wider
5151 time frames towards the bottom. Finally, there should be a fallback
52- rule without time constraints at all to ensure you have no time slot
52+ rule without time restrictions at all to ensure you have no time slot
5353 left without a value defined for.
5454
5555The ``name `` parameter we specified here is completely optional and
@@ -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
@@ -83,13 +85,14 @@ Constraints
8385
8486 - v: 15
8587
86- With your knowledge so far, this should be self-explanatory. The only
87- new parameter is ``weekdays ``, which is a so called constraint.
88+ With your knowledge so far, this should be self-explanatory. The only new parameter is
89+ ``weekdays ``, which is a so called constraint.
8890
89- Constraints can be used to limit the starting days on which the rule is
90- considered . There are a number of these constraints, namely:
91+ Constraints can be used to limit the days on which the rule should start to be
92+ active . 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.
@@ -111,11 +114,12 @@ considered. There are a number of these constraints, namely:
111114 provided, the nearest prior valid date (namely 2018-02-28 in this
112115 case) is assumed.
113116
114- All constraints you define need to be fulfilled for the rule to match.
117+ A date needs to fulfill all constraints you defined for a rule to be considered
118+ active at that specific date.
115119
116- The format used to specify values for the first five types of constraints
117- is similar to that of crontab files. We call it range specification,
118- and only integers are supported, no decimal values.
120+ The format used to specify values for the first five types of constraints is similar
121+ to that of crontab files. We call it range specification, and only integers are
122+ supported, no decimal values.
119123
120124* ``x ``: the single number ``x ``
121125* ``x-y `` where ``x < y ``: range of numbers from ``x `` to ``y ``,
@@ -129,15 +133,14 @@ and only integers are supported, no decimal values.
129133* ... and so on
130134* Any spaces are ignored.
131135
132- If an exclamation mark (``! ``) is prepended to the range specification,
133- it's values are inverted. For instance, the constraint ``weekdays:
134- "!4-5,7" `` expands to ``weekdays: 1,2,3,6 `` and ``months: "!3" `` is
135- equivalent to ``months: 1-2,4-12 ``.
136+ If an exclamation mark (``! ``) is prepended to the range specification, its values are
137+ inverted. For instance, the constraint ``weekdays: "!4-5,7" `` expands to ``weekdays:
138+ 1,2,3,6 `` and ``months: "!3" `` is equivalent to ``months: 1-2,4-12 ``.
136139
137140.. note ::
138141
139- The ``! `` sign has a special meaning in YAML, hence inverted
140- specifications have to be enclosed in quotes.
142+ The ``! `` sign has a special meaning in YAML, hence inverted specifications have
143+ to be enclosed in quotes.
141144
142145
143146Rules Spanning Multiple Days
@@ -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