dateblock 2.0.0__tar.gz → 2.2.0__tar.gz

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.
@@ -0,0 +1,130 @@
1
+ # Change Log
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ ## [2.2.0] - 2026-11-10
5
+ ### Added
6
+ - A drift can be negative, moving each matched time back that many
7
+ seconds, ie: `dateblock -c '0 0 9 1 * * -259200'` is a reminder at 9:00
8
+ three days before each 1st of the month.
9
+
10
+ ## [2.1.0] - 2026-10-31
11
+ ### Added
12
+ - PHP bindings (PHP 8.0 and newer): `dateblock('0 0 9', ref: $tokyo)`
13
+ returns a `DateTimeImmutable`, reading the cron in the timezone of `$ref`.
14
+ Install with `pie install caronc/dateblock` or the `php-dateblock`
15
+ package.
16
+ - Node.js bindings (Node.js 20 and newer): `await dateblock('0 0 9',
17
+ { timeZone: 'Asia/Tokyo' })` waits without blocking, and `next()` only
18
+ works the time out. Install with `npm install @caronc/dateblock`.
19
+ - Python: `await dateblock.wait('0 0 9')` waits with asyncio, without
20
+ blocking other tasks; it takes the same `cron`, `ref` and `isc` as
21
+ `dateblock()`.
22
+ - Month and weekday names, as crontab allows: `0 0 9 * * Mon-Fri`,
23
+ `-m Jan,Jul`. A backwards range of names (`Sat-Sun`) is refused, since
24
+ it would mean every day.
25
+ - A day of the week of 7 means Sunday, as in crontab (`Fri-7`).
26
+ - crontab's shortcuts: `@hourly`, `@daily` (`@midnight`), `@weekly`,
27
+ `@monthly` and `@yearly` (`@annually`), optionally followed by a drift
28
+ (`@daily +30`).
29
+ - List the next few times without waiting, to check a schedule:
30
+ `dateblock -C 5 -i -c '0 9 * * Mon-Fri'`, and in the bindings
31
+ `dateblock.upcoming()` (Python), `dateblock_upcoming()` (PHP) and
32
+ `upcoming()` (Node.js). Up to 1000; just the next one unless told
33
+ otherwise.
34
+
35
+ ### Changed
36
+ - Node.js: the add-on now comes ready built for Linux (x64 and arm64, glibc
37
+ and musl/Alpine), macOS (Intel and Apple silicon) and Windows (x64 and
38
+ arm64), so `npm install @caronc/dateblock` compiles nothing and has no
39
+ install step to approve on npm 12. On any other computer, build it once
40
+ with `npm explore @caronc/dateblock -- npm run build`.
41
+ - macOS and Windows wait with the system's own timer, set to the exact
42
+ moment, instead of waking every second: it still fires on time if the
43
+ computer sleeps or the clock is changed. As a safety net the clock is
44
+ also checked once an hour, a minute before the moment, and every second
45
+ over the final minute. Linux is unchanged (it already slept until the
46
+ exact time).
47
+
48
+ ### Fixed
49
+ - Node.js on Windows: a syntax error's message could come out garbled (or
50
+ empty), since the add-on read it after it had been freed.
51
+ - Error messages write every byte of the input that isn't plain printable
52
+ text as `\xNN` (not just control characters), so nothing in a bad cron
53
+ can upset a terminal or a log.
54
+ - The Python, PHP and Node.js bindings only copy the start of a huge cron
55
+ string before refusing it, instead of all of it.
56
+ - Python: when the clocks go back and a time happens twice, the second one
57
+ comes back with `fold=1`, so its `timestamp()` is right.
58
+ - Node.js: a wait that spans the computer sleeping (or the clock being
59
+ changed) now ends within a minute of the right moment, instead of late
60
+ by however long the computer slept.
61
+
62
+ ## [2.0.0] - 2026-10-26
63
+ The project is now called **dateblock** (it used to be datetools).
64
+
65
+ ### Added
66
+ - Read a schedule in another timezone: `--timezone` (`-z`) on the command
67
+ line, or a timezone-aware `datetime` in Python.
68
+ - Run a command once the time is reached, ie:
69
+ `dateblock -n /15 -- ./backup.sh`; dateblock exits with the command's
70
+ own exit code.
71
+ - Range steps such as `1-10/3` (1, 4, 7 and 10).
72
+ - Error messages that say what is wrong, ie: `minute '99': 99 is outside of
73
+ 0-59`.
74
+ - The `libdateblock` shared library, with headers and a pkg-config file.
75
+ - Packages for Fedora, RHEL 9 and 10, Debian 13, Arch Linux and Homebrew,
76
+ and Python wheels for Linux, macOS and Windows (Python 3.9 to 3.14).
77
+ - A complete man page.
78
+
79
+ ### Changed
80
+ - `--isc` reads an entry exactly as crontab(5) does: the day of the month
81
+ OR the day of the week may match, and `*/5` days are the 1st, 6th, 11th...
82
+ - Fields left out only reset to their lowest value when they are smaller
83
+ than the smallest field given: `/5 * 3,4` is every 5th second during
84
+ hours 3 and 4.
85
+ - Unclear entries such as `5-`, `5,,6` and `*,5` are now errors instead of
86
+ quietly matching something else.
87
+ - Much faster: long lists such as `0-59 0-59 0-23` cost the same as single
88
+ values.
89
+ - Blocking wakes up exactly on the second, and Ctrl-C interrupts it.
90
+ - Boost is no longer needed.
91
+ - Python: Python 3 only (`from dateblock import dateblock` still works).
92
+ A bad schedule raises `SyntaxError`, one that never happens raises
93
+ `ValueError`, and an unsupported `ref` raises `TypeError`.
94
+
95
+ ### Removed
96
+ - The datemath tool; `date -d` (ie: `date -d '+3 days -2 hours'`) does the
97
+ same job.
98
+
99
+ ### Fixed
100
+ - A schedule that never happens (ie: February 31st) is reported as an
101
+ error, while lists that only partly exist (ie: the 30th and 31st of
102
+ February and March) find the dates that do.
103
+ - Rare dates such as February 29th on a given weekday are found.
104
+ - Times around daylight saving changes and month ends are correct (ie: the
105
+ 31st no longer rolls into the next month).
106
+ - A month-only schedule (ie: `-m 3`) starts on the 1st.
107
+ - Date formats such as %I, %j, %P, %U, %x, %X and %h print correctly.
108
+ - Very large drift values no longer loop forever.
109
+ - Python: errors no longer end the Python interpreter.
110
+
111
+ ## [1.0.3] - 2018-05-31
112
+ ### Changed
113
+ - Fixed the padding of dates (padding with a zero).
114
+ - PyPI support.
115
+
116
+ ## [1.0.0] - 2017-04-21
117
+ ### Added
118
+ - The drift can be given inline in the cron with a plus (+): `0 /5 +4` is
119
+ the same as `0 /5 * * * * 4` (every 5 minutes, plus 4 seconds), and
120
+ several drifts work too (`0 /5 +15,45`).
121
+ - Regular crontab entries (Internet Systems Consortium format) with
122
+ `--isc`.
123
+
124
+ ## [0.8.1] - 2015-08-17
125
+ ### Changed
126
+ - Fixed the month missing from the printed time.
127
+
128
+ ## [0.8.0] - 2013-10-26
129
+ ### Added
130
+ - Initial release on GitHub.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dateblock
3
- Version: 2.0.0
3
+ Version: 2.2.0
4
4
  Summary: Block (sleep) until a cron-style moment in time
5
5
  Home-page: https://github.com/caronc/dateblock
6
6
  Author: Chris Caron
@@ -49,6 +49,10 @@ Dynamic: summary
49
49
  [![Paypal](https://img.shields.io/badge/paypal-donate-green.svg)](https://www.paypal.com/donate/?hosted_button_id=CR6YF7KLQWQ5E)
50
50
  [![PyPI](https://img.shields.io/pypi/v/dateblock.svg)](https://pypi.org/project/dateblock/)
51
51
  [![Python](https://img.shields.io/pypi/pyversions/dateblock.svg)](https://pypi.org/project/dateblock/)
52
+ [![npm](https://img.shields.io/npm/v/@caronc/dateblock.svg)](https://www.npmjs.com/package/@caronc/dateblock)
53
+ [![Node.js](https://img.shields.io/node/v/@caronc/dateblock.svg)](https://www.npmjs.com/package/@caronc/dateblock)
54
+ [![Packagist](https://img.shields.io/packagist/v/caronc/dateblock.svg)](https://packagist.org/packages/caronc/dateblock)
55
+ [![PHP](https://img.shields.io/packagist/dependency-v/caronc/dateblock/php.svg)](https://packagist.org/packages/caronc/dateblock)
52
56
 
53
57
  Dateblock
54
58
  =========
@@ -58,11 +62,11 @@ The difference is very subtle but can prove to be very useful.
58
62
 
59
63
  It offers a few new features that the Internet Systems Consortium (ICS) version
60
64
  does not (refering to /etc/crontab style). Dateblock specifically offers the ability
61
- to wake/unblock on a _specific second_ and/or _drift_ for certain period afterwards
62
- your calculated time is met (kind of like combining _sleep_ and _ICS Cron_ into one).
65
+ to wake/unblock on a _specific second_ and/or _drift_ a number of seconds after
66
+ (or before) your calculated time is met (kind of like combining _sleep_ and _ICS Cron_ into one).
63
67
 
64
- Python bindings are additionally included supporting all of the standard datetime
65
- formats and objects!
68
+ Python, PHP and Node.js bindings are additionally included, supporting the
69
+ standard date and time objects of each language!
66
70
 
67
71
  ## Quick Start
68
72
  The `dateblock` command is a C++ tool; install it from the distribution
@@ -83,6 +87,18 @@ The Python library is on PyPI (Linux, macOS and Windows):
83
87
  pip install dateblock
84
88
  ```
85
89
 
90
+ The PHP extension installs with [PIE](https://github.com/php/pie) (Linux and
91
+ macOS with a 64-bit `time_t`, PHP 8.0 and newer):
92
+ ```bash
93
+ pie install caronc/dateblock
94
+ ```
95
+
96
+ The Node.js package is on npm (Node.js 20 and newer, on a system with a
97
+ 64-bit `time_t`):
98
+ ```bash
99
+ npm install @caronc/dateblock
100
+ ```
101
+
86
102
  Packages for Fedora, RHEL/CentOS/Alma/Rocky 9 and 10, Debian and Arch Linux
87
103
  can be built from this repository; see [Installation](#installation).
88
104
 
@@ -99,12 +115,15 @@ __Allowed options__:
99
115
  -n [ --minute ] arg Minute (0-59)
100
116
  -o [ --hour ] arg Hour (0-23)
101
117
  -d [ --dom ] arg Day of Month (1-31)
102
- -m [ --month ] arg Month (1-12) {Jan=1,...,Dec=12}
103
- -w [ --dow ] arg Day of Week (0-6) {Sun=0,...,Sat=6}
118
+ -m [ --month ] arg Month (1-12 or Jan-Dec)
119
+ -w [ --dow ] arg Day of Week (0-6 or Sun-Sat; Sun=0 or 7)
104
120
  -c [ --cron ] arg Cron string formatting
105
- -x [ --drift ] arg Additional drift time (in seconds).
121
+ -x [ --drift ] arg Additional drift time (in seconds); a negative
122
+ drift wakes up that much earlier.
106
123
  -z [ --timezone ] arg Timezone to read the schedule in (ie:
107
124
  America/Toronto); defaults to this computer's.
125
+ -C [ --count ] arg List the next N times (1-1000) instead of
126
+ waiting; nothing is run.
108
127
 
109
128
  Anything after the options (or after --) is a command to run once the
110
129
  time is reached.
@@ -116,9 +135,13 @@ A variety of syntax is accepted by this tool such as:
116
135
  */x (or /x) (Modulus) where 'x' is represented numerically.
117
136
  x-y (or y-x) (Range) where 'x' and 'y' are are represented numerically.
118
137
  x,y (Separator) where 'x' and 'y' are are represented numerically.
138
+ Mon-Fri, Jan (Names) the month and the day of the week can be written
139
+ as names (Jan-Dec and Sun-Sat, in any case).
140
+ 7 (Sunday) as in crontab, a day of the week of 7 is Sunday
141
+ too, so Fri-7 is Friday to Sunday.
119
142
  ```
120
143
 
121
- __Note__: With the exception of the drift option (+), all variations of the syntax
144
+ __Note__: With the exception of the drift option (+ or -), all variations of the syntax
122
145
  mentioned above can be mixed if separated using the 'comma' (Separator)
123
146
  operator. ie: */a,b,c-d,/e is valid.
124
147
  However: x-y-z is not valid, nor is /x/y, /x-y or a '*' mixed with
@@ -129,7 +152,7 @@ __Note__: With the exception of the drift option (+), all variations of the synt
129
152
  The __--cron__(__-c__) switch allows one to specify the standard cron formatting:
130
153
  ```
131
154
  drift time ----------------------------------------------+
132
- day of week (0 - 6) (Sunday=0) -----------------------+ |
155
+ day of week (0 - 7) (Sunday=0 or 7) ------------------+ |
133
156
  month (1 - 12) ------------------------------------+ | |
134
157
  day of month (1 - 31) --------------------------+ | | |
135
158
  hour (0 - 23) -------------------------------+ | | | |
@@ -143,6 +166,16 @@ Substitute an asterisk (*) as a placeholder for arguments you are not
143
166
  interested in. Asterisks are automatically placed in strings missing all 6
144
167
  arguments (separated by white space).
145
168
 
169
+ The crontab shortcuts work too (with or without `--isc`). Without `--isc`
170
+ one can be followed by a drift (ie: `@daily +30` or `@daily -30`):
171
+ ```
172
+ @hourly the start of every hour
173
+ @daily (or @midnight) every day at 00:00
174
+ @weekly every Sunday at 00:00
175
+ @monthly the 1st of every month at 00:00
176
+ @yearly (or @annually) every January 1st at 00:00
177
+ ```
178
+
146
179
  The __--isc__ (__-i__) switch makes the cron interpretation equivalent to
147
180
  what it is today (ISC stands for Internet Systems Consortium). Hence:
148
181
  ```
@@ -152,7 +185,7 @@ what it is today (ISC stands for Internet Systems Consortium). Hence:
152
185
  | +----------------------- hour (0 - 23)
153
186
  | | +----------------- day of month (1 - 31)
154
187
  | | | +----------- month (1 - 12)
155
- | | | | +----- day of week (0 - 6) (Sunday=0)
188
+ | | | | +----- day of week (0 - 7) (Sunday=0 or 7)
156
189
  | | | | |
157
190
  - - - - -
158
191
  * * * * *
@@ -177,6 +210,25 @@ Current Time : 2026-10-24 22:05:00 JST (Sat)
177
210
  Block Until : 2026-10-25 09:00:00 JST (Sun)
178
211
  ```
179
212
 
213
+ ### Listing the next few times:
214
+ __--count__ (__-C__) lists the next few times a schedule matches, without
215
+ waiting. It is the quickest way to check a schedule, and with __--isc__
216
+ (__-i__) a handy way to learn how a crontab entry behaves:
217
+ ```bash
218
+ dateblock -C 5 -i -c "0 9 * * Mon-Fri"
219
+ Current Time : 2026-10-30 16:53:37 (Fri)
220
+ Next Times : 2026-11-02 09:00:00 (Mon)
221
+ 2026-11-03 09:00:00 (Tue)
222
+ 2026-11-04 09:00:00 (Wed)
223
+ 2026-11-05 09:00:00 (Thu)
224
+ 2026-11-06 09:00:00 (Fri)
225
+ ```
226
+ - Up to 1000 times can be listed. The first is the one dateblock would
227
+ wait for.
228
+ - Nothing is run: a command after the options is only shown.
229
+ - In the rare case that no later time exists (ie: past the last date the
230
+ computer can show), the list just ends early and a note says so.
231
+
180
232
  ### Running a command:
181
233
  Put a command (and its arguments) after the options, and dateblock runs it
182
234
  once the time is reached:
@@ -208,12 +260,13 @@ every minute. You could however achieve the previous example using a drift
208
260
  value of '60' (seconds) and a cron (minute) entry of '*/10'.
209
261
 
210
262
  In a way, drifting is a little like executing a cron and then sleeping for
211
- an additional period right afterwards. However this is a much more elegant
263
+ an additional period right afterwards (a negative drift wakes up that much
264
+ sooner instead). However this is a much more elegant
212
265
  solution with a more precise blocking period.
213
266
 
214
267
  Some things to consider about drifting:
215
268
 
216
- - Drifting is always calculated 'after' a specified cron.
269
+ - Drifting is always calculated from the time the cron matches.
217
270
  - You can not specify a drifting value on it's own without a cron entry to go
218
271
  with it.
219
272
  - A drift value is always specified in seconds.
@@ -245,6 +298,16 @@ Some things to consider about drifting:
245
298
  ```dateblock -c '* */5 +60'``` is the same as writing ```dateblock -c '* */5 * * * * 60'```
246
299
  Once you invoke the __+__ character however, any entries found afterwards
247
300
  will be treated as an error.
301
+ - A drift can be negative; each matched time then moves _back_ that many
302
+ seconds instead of forward.
303
+ - A reminder 3 days (259200 seconds) before rent is due on the 1st:
304
+ ```dateblock -c '0 0 9 1 * * -259200'``` wakes at 9:00 on the 28th, 29th
305
+ or 26th, however long the month is.
306
+ - ```dateblock -c '0 0 9 25 12 * -518400'``` (or ```-x -518400```) wakes at
307
+ 9:00 on December 19th (6 days before December 25th).
308
+ - Like _+_, an entry starting with _-_ jumps to the drift.
309
+ - An early time that has already passed is skipped, like any past match.
310
+ - Drifts go from -2147483647 to 2147483647.
248
311
 
249
312
  ### Examples
250
313
  The following would block until a minute divisible by 10 was reached. Minutes
@@ -292,7 +355,7 @@ dateblock -c "* 5 * * * * 20"
292
355
  dateblock -n 5 -x 20
293
356
 
294
357
  # You can skip to the drift portion by just denoting a plus (+) as the last
295
- # entry specified. This is interpreted as a drift time.
358
+ # entry specified (or a minus (-) for a negative drift). This is interpreted as a drift time.
296
359
  dateblock -c "* 5 +20"
297
360
  ```
298
361
  The expression is considered invalid if more entries are found after the drift
@@ -301,6 +364,12 @@ period. However this is still valid:
301
364
  dateblock -c "* 5 * * * * +20"
302
365
  ```
303
366
 
367
+ A negative drift wakes up early; this blocks until 4:40 past each hour (20
368
+ seconds before the 5 minute mark):
369
+ ```bash
370
+ dateblock -n 5 -x -20
371
+ ```
372
+
304
373
  ### DateBlock Python Bindings
305
374
  The DateBlock python bindings are really easy to use too:
306
375
  ```python
@@ -324,6 +393,9 @@ result = dateblock("* /20", ref=relative, block=False)
324
393
  # had you not set the isc flag)
325
394
  result = dateblock("/1", isc=True)
326
395
 
396
+ # A negative drift wakes up early: 6 days before 9:00 on December 25th
397
+ result = dateblock("0 0 9 25 12 * -518400", block=False)
398
+
327
399
  # Dateblock supports date, time and epoch time too!
328
400
  #
329
401
  # Date: (yyyy, mm, dd)
@@ -354,6 +426,147 @@ A few things worth knowing:
354
426
  - While blocking, other Python threads keep running and Ctrl-C
355
427
  (`KeyboardInterrupt`) works as expected.
356
428
 
429
+ With asyncio, use `await dateblock.wait(...)` instead. It takes the same
430
+ `cron`, `ref` and `isc` arguments, returns the same `datetime`, and lets
431
+ your other tasks keep running while it waits (no thread needed):
432
+ ```python
433
+ import asyncio
434
+ import dateblock
435
+
436
+ async def main():
437
+ # Wait for the next 20 minute mark
438
+ result = await dateblock.wait("* /20")
439
+ print("Unblocked at %s" % result.strftime("%Y-%m-%d %H:%M:%S"))
440
+
441
+ # Stop waiting early: give up after 10 seconds
442
+ try:
443
+ await asyncio.wait_for(dateblock.wait("0 0 9"), 10)
444
+ except asyncio.TimeoutError:
445
+ print("Gave up waiting")
446
+
447
+ asyncio.run(main())
448
+ ```
449
+
450
+ - Cancelling the task (or a timeout, as above) stops the wait.
451
+ - A long wait checks the real clock once a minute, so it still ends on
452
+ time if the computer sleeps or the clock is changed. That costs very
453
+ little, but if you keep thousands of waits going at once, prefer one
454
+ task that waits and then hands the work out.
455
+
456
+ To see the next few times without waiting, use `dateblock.upcoming()`. It
457
+ takes the same `cron`, `ref` and `isc`, plus a `count` (just the next one
458
+ unless given, at most 1000), and returns a tuple of `datetime`s, earliest first:
459
+ ```python
460
+ import dateblock
461
+
462
+ for when in dateblock.upcoming("0 9 * * Mon-Fri", 3, isc=True):
463
+ print(when.strftime("%a %Y-%m-%d %H:%M"))
464
+ ```
465
+
466
+ - The `datetime`s are the same kind `dateblock()` returns: aware ones in
467
+ `ref`'s own timezone, otherwise naive ones in this computer's.
468
+ - When the clocks go back and a time happens twice, both are listed; the
469
+ second naive one has `fold=1`, so its `timestamp()` is right.
470
+ - The tuple is shorter than `count` only when no later time can be shown
471
+ (ie: past the year 9999).
472
+ - `dateblock.COUNT_DEFAULT` (1) and `dateblock.COUNT_MAX` (1000) hold the
473
+ limits.
474
+
475
+ ### DateBlock PHP Bindings
476
+ The PHP extension adds a `dateblock()` function that works the same way
477
+ (and `dateblock_upcoming()`, below):
478
+ ```php
479
+ <?php
480
+ // Returns the moment it will unblock at (a DateTimeImmutable)
481
+ $result = dateblock('* /20', block: false);
482
+ echo 'Blocking until ', $result->format('Y-m-d H:i:s'), "\n";
483
+ dateblock('* /20');
484
+
485
+ // Work it out from another moment (a DateTime, DateTimeImmutable or
486
+ // seconds since the epoch)
487
+ $result = dateblock('* /20', false, new DateTimeImmutable('-4 days'));
488
+ $result = dateblock('/5', false, 13424236);
489
+
490
+ // A regular crontab entry: the start of each minute
491
+ $result = dateblock('* * * * *', isc: true);
492
+
493
+ // A negative drift wakes up early: 6 days before 9:00 on December 25th
494
+ $result = dateblock('0 0 9 25 12 * -518400', block: false);
495
+
496
+ // Timezones: the cron is read in the timezone of the reference, and the
497
+ // result comes back in that same timezone. This waits for 9:00 in Tokyo.
498
+ $tokyo = new DateTimeImmutable('now', new DateTimeZone('Asia/Tokyo'));
499
+ $result = dateblock('0 0 9', ref: $tokyo);
500
+ ```
501
+
502
+ A few things worth knowing:
503
+ - Without a `DateTime`/`DateTimeImmutable` reference, the cron is read in
504
+ PHP's default timezone (`date.timezone`, see
505
+ `date_default_timezone_get()`), not the computer's.
506
+ - An invalid cron string throws a `ValueError` saying what is wrong; a cron
507
+ that can never happen (such as February 31st) throws a
508
+ `RuntimeException`.
509
+ - Signal handlers set with `pcntl_signal()` run once it returns; Ctrl-C
510
+ still ends the script straight away unless a handler is set for it.
511
+
512
+ `dateblock_upcoming()` lists the next few times without waiting. It takes
513
+ the same `$cron`, `$ref` and `$isc`, plus a `$count` (just the next one
514
+ unless given, at most 1000), and returns an array of `DateTimeImmutable`, earliest first,
515
+ in the same timezone `dateblock()` would use:
516
+ ```php
517
+ <?php
518
+ foreach (dateblock_upcoming('0 9 * * Mon-Fri', 3, isc: true) as $when) {
519
+ echo $when->format('D Y-m-d H:i'), "\n";
520
+ }
521
+ ```
522
+ The array is shorter than `$count` only when no later time exists. The
523
+ limits are in `DATEBLOCK_COUNT_DEFAULT` and `DATEBLOCK_COUNT_MAX`.
524
+
525
+ ### DateBlock Node.js Bindings
526
+ The Node.js package waits without blocking: `dateblock()` returns a promise,
527
+ and the rest of your program keeps running in the meantime.
528
+ ```javascript
529
+ import { dateblock, next, upcoming } from '@caronc/dateblock';
530
+ // or, in CommonJS: const { dateblock, next, upcoming } = require('@caronc/dateblock');
531
+
532
+ // When is the next 20 minute mark? (a Date; nothing waits)
533
+ const when = next('* /20');
534
+
535
+ // Wait for it
536
+ await dateblock('* /20');
537
+
538
+ // Work it out from another moment (a Date, or milliseconds since the epoch)
539
+ next('* /20', { ref: new Date(Date.now() - 4 * 86400000) });
540
+
541
+ // A regular crontab entry: the start of each minute
542
+ next('* * * * *', { isc: true });
543
+
544
+ // A negative drift wakes up early: 6 days before 9:00 on December 25th
545
+ next('0 0 9 25 12 * -518400');
546
+
547
+ // Timezones: 9:00 in Tokyo, whatever timezone this computer is in
548
+ await dateblock('0 0 9', { timeZone: 'Asia/Tokyo' });
549
+
550
+ // The next 3 weekday mornings (an array of Dates; nothing waits)
551
+ upcoming('0 9 * * Mon-Fri', { isc: true, count: 3 });
552
+
553
+ // Stop waiting early with an AbortSignal
554
+ const controller = new AbortController();
555
+ dateblock('0 0 9', { signal: controller.signal }).catch(() => {});
556
+ controller.abort();
557
+ ```
558
+
559
+ A few things worth knowing:
560
+ - Without `timeZone`, the cron is read in the same timezone JavaScript's
561
+ `Date` uses.
562
+ - An invalid cron string throws a `SyntaxError` saying what is wrong; a cron
563
+ that can never happen (such as February 31st), an unknown timezone or a
564
+ reference too far away throws a `RangeError`.
565
+ - `upcoming()` takes `next()`'s options plus `count` (just the next one
566
+ unless given, at most 1000; also exported as `COUNT_DEFAULT` and `COUNT_MAX`). The array
567
+ is shorter than `count` only when no later time fits in a `Date`.
568
+ - TypeScript types are included.
569
+
357
570
  ## Installation
358
571
  ### From PyPI (the Python library)
359
572
  ```bash
@@ -364,6 +577,36 @@ is compiled straight into it, so nothing else is needed). The `dateblock`
364
577
  command is the C++ tool; install it from the packages or build it from
365
578
  source as shown below.
366
579
 
580
+ ### With PIE (the PHP extension)
581
+ ```bash
582
+ pie install caronc/dateblock
583
+ ```
584
+ PIE builds the extension on your computer (the C++ code is compiled straight
585
+ into it), so it needs a C++ compiler and the PHP development files (ie:
586
+ `php-devel` or `php-dev`), and then turns it on (or tells you how).
587
+
588
+ Like the rest of dateblock, it needs a 64-bit `time_t`: every 64-bit
589
+ system has one, and so does current 32-bit ARM Linux. Older 32-bit systems
590
+ can't hold dates past 2038, so the build stops there with an error (see
591
+ [INSTALL.md](https://github.com/caronc/dateblock/blob/master/INSTALL.md)).
592
+
593
+ ### From npm (the Node.js package)
594
+ ```bash
595
+ npm install @caronc/dateblock
596
+ ```
597
+ It comes ready built for Linux (x64 and arm64, including Alpine), macOS
598
+ (Intel and Apple silicon) and Windows (x64 and arm64): npm installs the
599
+ one for your computer, so nothing is compiled and there is no install step
600
+ to approve. Anywhere else, build it once after installing (this needs a
601
+ C++ compiler and Python; see
602
+ [node-gyp](https://github.com/nodejs/node-gyp#installation)); the error
603
+ you get without it says so too:
604
+ ```bash
605
+ npm explore @caronc/dateblock -- npm run build
606
+ ```
607
+ It needs a 64-bit `time_t` too, so it won't build on older 32-bit systems
608
+ (see [INSTALL.md](https://github.com/caronc/dateblock/blob/master/INSTALL.md)).
609
+
367
610
  ### From Source
368
611
  Assuming you have a C++ compiler and the standard development tools that
369
612
  usually go with it (make, autoconf, automake and libtool), then the
@@ -389,6 +632,20 @@ straight into the Python module):
389
632
  pip install .
390
633
  ```
391
634
 
635
+ To build the PHP extension from your checkout (it needs the PHP development
636
+ files; the C++ code is compiled straight into it unless you add
637
+ `--with-libdateblock` to use the installed library instead):
638
+ ```bash
639
+ cd php
640
+ phpize
641
+ ./configure
642
+ make
643
+ make test
644
+ sudo make install
645
+ ```
646
+ Then turn it on by adding `extension=dateblock` to your `php.ini` (or a new
647
+ file in its `conf.d/` directory).
648
+
392
649
  ### Building with Docker
393
650
  Don't want to install the build tools? If you have
394
651
  [Docker](https://www.docker.com/) (or [Podman](https://podman.io/)) and