Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Deploy AIOS web (React glide grid + FastAPI slice)
Browse files- RELEASES.json +7 -1
- VERSION +1 -1
- platform/aios_grid.py +161 -50
- web/src/customer-grid/DatePicker.tsx +50 -28
- web/src/customer-grid/types.ts +6 -3
RELEASES.json
CHANGED
|
@@ -1,6 +1,12 @@
|
|
| 1 |
{
|
| 2 |
-
"current": "
|
| 3 |
"releases": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
{
|
| 5 |
"version": "v67",
|
| 6 |
"sha": "3b22419",
|
|
|
|
| 1 |
{
|
| 2 |
+
"current": "v68 (62b065a)",
|
| 3 |
"releases": [
|
| 4 |
+
{
|
| 5 |
+
"version": "v68",
|
| 6 |
+
"sha": "62b065a",
|
| 7 |
+
"date": "2026-09-01",
|
| 8 |
+
"subject": "release v68: unified holiday date offsets"
|
| 9 |
+
},
|
| 10 |
{
|
| 11 |
"version": "v67",
|
| 12 |
"sha": "3b22419",
|
VERSION
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
|
|
|
|
| 1 |
+
v68 (62b065a)
|
platform/aios_grid.py
CHANGED
|
@@ -690,21 +690,23 @@ _RECURRENCE_KINDS = frozenset({'daily', 'weekly', 'monthly', 'yearly', 'holiday'
|
|
| 690 |
# a COLUMN, every record computes its own answer from its own anchor value. That is the
|
| 691 |
# per-record behaviour the instruction asks for, without a per-record rule store.
|
| 692 |
#
|
| 693 |
-
# ⚠ THE KIND IS `anchored`, NOT `offset`.
|
| 694 |
-
#
|
| 695 |
-
#
|
| 696 |
-
#
|
| 697 |
-
_ANCHORED_UNITS = frozenset({'day', 'business_day', 'week', 'month'})
|
| 698 |
_ANCHORED_RELATIONS = frozenset({'on', 'after', 'before'})
|
|
|
|
| 699 |
# A calendar appears here only when the server really evaluates it. The Date picker reads this
|
| 700 |
# same registry, so a selector cannot promise a country whose recurrence becomes a no-op later.
|
| 701 |
#
|
| 702 |
# ⭐⭐ W46-T33 (owner instruction 13, ruling R11: fixed-date plus floating "plus religious
|
| 703 |
# holidays too including jewish holidays"). A recurrence may now name ONE holiday instead of a
|
| 704 |
-
# whole national calendar, and the
|
| 705 |
-
#
|
| 706 |
# than a second one, so `_PUBLIC_HOLIDAY_CALENDARS` admits them at the field door, the Date
|
| 707 |
-
# picker reads them off the same wire, and `recurrence_preview`
|
|
|
|
| 708 |
# `group` is what lets the picker head its two option groups without a client-side copy of the
|
| 709 |
# list; it is additive, so an older client that ignores it still renders a flat, correct list.
|
| 710 |
PUBLIC_HOLIDAY_CALENDARS = (
|
|
@@ -729,7 +731,10 @@ PUBLIC_HOLIDAY_CALENDARS = (
|
|
| 729 |
{'code': 'PASSOVER', 'label': 'Passover', 'group': 'holiday'},
|
| 730 |
)
|
| 731 |
_PUBLIC_HOLIDAY_CALENDARS = frozenset(item['code'] for item in PUBLIC_HOLIDAY_CALENDARS)
|
| 732 |
-
|
|
|
|
|
|
|
|
|
|
| 733 |
|
| 734 |
|
| 735 |
def _iso_day(value):
|
|
@@ -934,10 +939,9 @@ def _canada_public_holidays(year):
|
|
| 934 |
return frozenset(days)
|
| 935 |
|
| 936 |
|
| 937 |
-
# A preview
|
| 938 |
-
#
|
| 939 |
-
#
|
| 940 |
-
# (code, year), so remembering them cannot change an answer.
|
| 941 |
_HOLIDAY_CACHE = {}
|
| 942 |
|
| 943 |
|
|
@@ -1095,16 +1099,46 @@ def clean_date_recurrence(raw, condition_fields=None):
|
|
| 1095 |
continue
|
| 1096 |
if calendar == 'TENANT' and not tenant_holidays:
|
| 1097 |
continue
|
| 1098 |
-
|
| 1099 |
-
|
| 1100 |
-
|
| 1101 |
-
|
| 1102 |
-
|
| 1103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1104 |
elif kind == 'anchored':
|
| 1105 |
-
# ⚠
|
| 1106 |
-
#
|
| 1107 |
-
#
|
|
|
|
| 1108 |
#
|
| 1109 |
# An unknown unit or relation drops the rule, exactly as an unknown calendar does
|
| 1110 |
# above, rather than degrading to a default the person never chose. `interval` was
|
|
@@ -1155,25 +1189,59 @@ def _shift_months(day, amount):
|
|
| 1155 |
total = (day.year * 12 + day.month - 1) + amount
|
| 1156 |
year, month = divmod(total, 12)
|
| 1157 |
month += 1
|
|
|
|
|
|
|
| 1158 |
# The last day of `month` is the day before the first of the next one, without importing
|
| 1159 |
-
# `calendar` for a single call.
|
| 1160 |
-
last
|
|
|
|
| 1161 |
return _dt.date(year, month, min(day.day, last))
|
| 1162 |
|
| 1163 |
|
| 1164 |
def _business_day_shift(start, amount, holidays):
|
| 1165 |
"""Move by business days, excluding weekends and this tenant's declared holidays."""
|
| 1166 |
if amount == 0:
|
| 1167 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1168 |
direction = 1 if amount > 0 else -1
|
| 1169 |
remaining, day = abs(amount), start
|
| 1170 |
-
|
| 1171 |
-
|
| 1172 |
-
|
| 1173 |
-
|
|
|
|
|
|
|
|
|
|
| 1174 |
return day
|
| 1175 |
|
| 1176 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1177 |
def _anchored_occurrence(start, rule, tenant_holidays=frozenset()):
|
| 1178 |
"""The ONE date an ``anchored`` rule names, computed straight from the anchor date.
|
| 1179 |
|
|
@@ -1188,9 +1256,42 @@ def _anchored_occurrence(start, rule, tenant_holidays=frozenset()):
|
|
| 1188 |
unit = rule.get('unit', 'day')
|
| 1189 |
if unit == 'month':
|
| 1190 |
return _shift_months(start, amount)
|
|
|
|
|
|
|
| 1191 |
if unit == 'business_day':
|
| 1192 |
return _business_day_shift(start, amount, tenant_holidays)
|
| 1193 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1194 |
|
| 1195 |
|
| 1196 |
def _recurrence_matches(day, start, rule):
|
|
@@ -1231,7 +1332,10 @@ def recurrence_preview(raw, today=None, count=None, condition_fields=None):
|
|
| 1231 |
ends = config.get('ends') or {'kind': 'never'}
|
| 1232 |
# A preview of at most fifty values needs no unbounded search. Ten years also makes an
|
| 1233 |
# unavailable public calendar visibly empty instead of spinning a request forever.
|
| 1234 |
-
|
|
|
|
|
|
|
|
|
|
| 1235 |
# ⛔ "After N occurrences" COUNTS FROM `startDate`, NOT FROM TODAY: occurrences already in the
|
| 1236 |
# past have spent the allowance. Counting from today is the obvious implementation and it is
|
| 1237 |
# wrong in a way that looks perfectly reasonable — a weekly Monday schedule begun 2026-01-01
|
|
@@ -1244,7 +1348,7 @@ def recurrence_preview(raw, today=None, count=None, condition_fields=None):
|
|
| 1244 |
lower = max(start, now)
|
| 1245 |
if ends['kind'] == 'on':
|
| 1246 |
horizon = min(horizon, _iso_day(ends.get('date')) or horizon)
|
| 1247 |
-
found
|
| 1248 |
holiday_rules = [rule for rule in config['rules'] if rule['kind'] == 'holiday']
|
| 1249 |
anchored_rules = [rule for rule in config['rules'] if rule['kind'] == 'anchored']
|
| 1250 |
ordinary_rules = [rule for rule in config['rules']
|
|
@@ -1259,27 +1363,34 @@ def recurrence_preview(raw, today=None, count=None, condition_fields=None):
|
|
| 1259 |
for value in config.get('tenantHolidays', []))
|
| 1260 |
for rule in anchored_rules:
|
| 1261 |
occurrence = _anchored_occurrence(start, rule, tenant_holidays)
|
| 1262 |
-
if occurrence is not None and occurrence <= horizon:
|
| 1263 |
found.add(occurrence)
|
| 1264 |
-
#
|
| 1265 |
-
#
|
| 1266 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1267 |
if any(_recurrence_matches(day, start, rule) for rule in ordinary_rules):
|
| 1268 |
found.add(day)
|
| 1269 |
-
|
| 1270 |
-
|
| 1271 |
-
# adjacent years makes those boundary dates real rather than silently absent.
|
| 1272 |
-
for holiday_year in (day.year - 1, day.year, day.year + 1):
|
| 1273 |
-
if holiday_year < start.year or (holiday_year - start.year) % rule['interval']:
|
| 1274 |
-
continue
|
| 1275 |
-
holidays = ({_dt.date.fromisoformat(value) for value in config.get('tenantHolidays', [])
|
| 1276 |
-
if value.startswith(f"{holiday_year:04d}-")}
|
| 1277 |
-
if rule['calendar'] == 'TENANT'
|
| 1278 |
-
else public_holidays(rule['calendar'], holiday_year))
|
| 1279 |
-
for holiday in holidays:
|
| 1280 |
-
occurrence = holiday + _dt.timedelta(days=rule['offset'])
|
| 1281 |
-
if occurrence == day and occurrence >= start:
|
| 1282 |
-
found.add(day)
|
| 1283 |
day += _dt.timedelta(days=1)
|
| 1284 |
allowed = sorted(found)[:limit]
|
| 1285 |
return [item.isoformat() for item in allowed if item >= now][:want]
|
|
|
|
| 690 |
# a COLUMN, every record computes its own answer from its own anchor value. That is the
|
| 691 |
# per-record behaviour the instruction asks for, without a per-record rule store.
|
| 692 |
#
|
| 693 |
+
# ⚠ THE KIND IS `anchored`, NOT `offset`. Holiday and anchored rules now share the human
|
| 694 |
+
# quantity/unit/before-on-after vocabulary, but their anchors remain different: a holiday names
|
| 695 |
+
# a calendar occurrence while an anchored rule names a record value. Keeping the kinds distinct
|
| 696 |
+
# stops a holiday rule from quietly becoming a per-row field rule.
|
| 697 |
+
_ANCHORED_UNITS = frozenset({'day', 'business_day', 'weekday', 'week', 'month', 'year'})
|
| 698 |
_ANCHORED_RELATIONS = frozenset({'on', 'after', 'before'})
|
| 699 |
+
_HOLIDAY_OFFSET_UNITS = _ANCHORED_UNITS
|
| 700 |
# A calendar appears here only when the server really evaluates it. The Date picker reads this
|
| 701 |
# same registry, so a selector cannot promise a country whose recurrence becomes a no-op later.
|
| 702 |
#
|
| 703 |
# ⭐⭐ W46-T33 (owner instruction 13, ruling R11: fixed-date plus floating "plus religious
|
| 704 |
# holidays too including jewish holidays"). A recurrence may now name ONE holiday instead of a
|
| 705 |
+
# whole national calendar, and the unified quantity/unit/before-on-after offset applies to it.
|
| 706 |
+
# The granular codes live in THIS registry rather
|
| 707 |
# than a second one, so `_PUBLIC_HOLIDAY_CALENDARS` admits them at the field door, the Date
|
| 708 |
+
# picker reads them off the same wire, and `recurrence_preview` resolves every choice from that
|
| 709 |
+
# one registry.
|
| 710 |
# `group` is what lets the picker head its two option groups without a client-side copy of the
|
| 711 |
# list; it is additive, so an older client that ignores it still renders a flat, correct list.
|
| 712 |
PUBLIC_HOLIDAY_CALENDARS = (
|
|
|
|
| 731 |
{'code': 'PASSOVER', 'label': 'Passover', 'group': 'holiday'},
|
| 732 |
)
|
| 733 |
_PUBLIC_HOLIDAY_CALENDARS = frozenset(item['code'] for item in PUBLIC_HOLIDAY_CALENDARS)
|
| 734 |
+
# The three old spellings are READ ONLY migration input. `clean_date_recurrence` always emits
|
| 735 |
+
# the unified quantity/unit/relation form below, so no new saved rule carries the disconnected
|
| 736 |
+
# +/-1 shape that Wave 48's audit rejected.
|
| 737 |
+
_HOLIDAY_LEGACY_RELATIONS = {'day_before': -1, 'day_on': 0, 'day_after': 1}
|
| 738 |
|
| 739 |
|
| 740 |
def _iso_day(value):
|
|
|
|
| 939 |
return frozenset(days)
|
| 940 |
|
| 941 |
|
| 942 |
+
# A preview generates its finite set of holiday source years once. An uncached lunisolar
|
| 943 |
+
# computation would otherwise repeat for every editor preview. The values are immutable
|
| 944 |
+
# frozensets of a pure function of (code, year), so remembering them cannot change an answer.
|
|
|
|
| 945 |
_HOLIDAY_CACHE = {}
|
| 946 |
|
| 947 |
|
|
|
|
| 1099 |
continue
|
| 1100 |
if calendar == 'TENANT' and not tenant_holidays:
|
| 1101 |
continue
|
| 1102 |
+
# W48-T11: Holidays must use the SAME quantity/unit/before-on-after sentence as a
|
| 1103 |
+
# date offset. The former +/-1 relation is still accepted only long enough to turn
|
| 1104 |
+
# existing rules into this one canonical shape. It never reaches a response or a
|
| 1105 |
+
# fresh save unchanged.
|
| 1106 |
+
raw_relation = str(raw_rule.get('relation') or '').strip().lower()
|
| 1107 |
+
legacy_offset = _HOLIDAY_LEGACY_RELATIONS.get(raw_relation)
|
| 1108 |
+
if legacy_offset is not None:
|
| 1109 |
+
relation = 'before' if legacy_offset < 0 else ('after' if legacy_offset > 0 else 'on')
|
| 1110 |
+
offset, unit = abs(legacy_offset), 'day'
|
| 1111 |
+
elif raw_relation in _ANCHORED_RELATIONS:
|
| 1112 |
+
relation = raw_relation
|
| 1113 |
+
unit = str(raw_rule.get('unit') or 'day').strip().lower()
|
| 1114 |
+
if unit not in _HOLIDAY_OFFSET_UNITS:
|
| 1115 |
+
continue
|
| 1116 |
+
offset = raw_rule.get('offset', 0 if relation == 'on' else None)
|
| 1117 |
+
if (not isinstance(offset, int) or isinstance(offset, bool)
|
| 1118 |
+
or (relation == 'on' and offset != 0)
|
| 1119 |
+
or (relation != 'on' and not 1 <= offset <= 366)):
|
| 1120 |
+
continue
|
| 1121 |
+
# The hidden unit/count must not survive an "on" choice in storage. A rule is
|
| 1122 |
+
# therefore read back exactly as the editor renders it.
|
| 1123 |
+
if relation == 'on':
|
| 1124 |
+
unit = 'day'
|
| 1125 |
+
else:
|
| 1126 |
+
# Legacy rules written before the relation words carried only a signed day
|
| 1127 |
+
# offset. Convert those deterministically; an unsigned value above one with no
|
| 1128 |
+
# unit/direction is malformed rather than guessed.
|
| 1129 |
+
legacy_offset = raw_rule.get('offset', 0)
|
| 1130 |
+
if (not isinstance(legacy_offset, int) or isinstance(legacy_offset, bool)
|
| 1131 |
+
or legacy_offset not in (-1, 0, 1)):
|
| 1132 |
+
continue
|
| 1133 |
+
relation = ('before' if legacy_offset < 0
|
| 1134 |
+
else ('after' if legacy_offset > 0 else 'on'))
|
| 1135 |
+
offset, unit = abs(legacy_offset), 'day'
|
| 1136 |
+
rule.update({'calendar': calendar, 'offset': offset, 'unit': unit, 'relation': relation})
|
| 1137 |
elif kind == 'anchored':
|
| 1138 |
+
# ⚠ Anchored and holiday rules share the readable before/on/after words, but their
|
| 1139 |
+
# anchors differ: this branch moves from a record date while holiday moves from a
|
| 1140 |
+
# calendar occurrence. The kinds stay exclusive and each branch writes only its
|
| 1141 |
+
# own keys.
|
| 1142 |
#
|
| 1143 |
# An unknown unit or relation drops the rule, exactly as an unknown calendar does
|
| 1144 |
# above, rather than degrading to a default the person never chose. `interval` was
|
|
|
|
| 1189 |
total = (day.year * 12 + day.month - 1) + amount
|
| 1190 |
year, month = divmod(total, 12)
|
| 1191 |
month += 1
|
| 1192 |
+
if not 1 <= year <= 9999:
|
| 1193 |
+
return None
|
| 1194 |
# The last day of `month` is the day before the first of the next one, without importing
|
| 1195 |
+
# `calendar` for a single call. December 9999 cannot ask Python for January 10000, so its
|
| 1196 |
+
# known last day stays local instead of turning a valid editor input into a server error.
|
| 1197 |
+
last = 31 if month == 12 else (_dt.date(year, month + 1, 1) - _dt.timedelta(days=1)).day
|
| 1198 |
return _dt.date(year, month, min(day.day, last))
|
| 1199 |
|
| 1200 |
|
| 1201 |
def _business_day_shift(start, amount, holidays):
|
| 1202 |
"""Move by business days, excluding weekends and this tenant's declared holidays."""
|
| 1203 |
if amount == 0:
|
| 1204 |
+
return start
|
| 1205 |
+
direction = 1 if amount > 0 else -1
|
| 1206 |
+
remaining, day = abs(amount), start
|
| 1207 |
+
try:
|
| 1208 |
+
while remaining:
|
| 1209 |
+
day += _dt.timedelta(days=direction)
|
| 1210 |
+
if day.weekday() < 5 and day not in holidays:
|
| 1211 |
+
remaining -= 1
|
| 1212 |
+
except OverflowError:
|
| 1213 |
+
return None
|
| 1214 |
+
return day
|
| 1215 |
+
|
| 1216 |
+
|
| 1217 |
+
def _weekday_shift(start, amount):
|
| 1218 |
+
"""Move by weekdays, excluding weekends but deliberately not tenant holidays."""
|
| 1219 |
+
if amount == 0:
|
| 1220 |
+
return start
|
| 1221 |
direction = 1 if amount > 0 else -1
|
| 1222 |
remaining, day = abs(amount), start
|
| 1223 |
+
try:
|
| 1224 |
+
while remaining:
|
| 1225 |
+
day += _dt.timedelta(days=direction)
|
| 1226 |
+
if day.weekday() < 5:
|
| 1227 |
+
remaining -= 1
|
| 1228 |
+
except OverflowError:
|
| 1229 |
+
return None
|
| 1230 |
return day
|
| 1231 |
|
| 1232 |
|
| 1233 |
+
def _shift_years(day, amount):
|
| 1234 |
+
"""Move calendar years while clamping a leap-day to February's last valid day."""
|
| 1235 |
+
year = day.year + amount
|
| 1236 |
+
if not 1 <= year <= 9999:
|
| 1237 |
+
return None
|
| 1238 |
+
try:
|
| 1239 |
+
return day.replace(year=year)
|
| 1240 |
+
except ValueError:
|
| 1241 |
+
# The only legal source-day failure is 29 February into a non-leap year.
|
| 1242 |
+
return _dt.date(year, 2, 28)
|
| 1243 |
+
|
| 1244 |
+
|
| 1245 |
def _anchored_occurrence(start, rule, tenant_holidays=frozenset()):
|
| 1246 |
"""The ONE date an ``anchored`` rule names, computed straight from the anchor date.
|
| 1247 |
|
|
|
|
| 1256 |
unit = rule.get('unit', 'day')
|
| 1257 |
if unit == 'month':
|
| 1258 |
return _shift_months(start, amount)
|
| 1259 |
+
if unit == 'year':
|
| 1260 |
+
return _shift_years(start, amount)
|
| 1261 |
if unit == 'business_day':
|
| 1262 |
return _business_day_shift(start, amount, tenant_holidays)
|
| 1263 |
+
if unit == 'weekday':
|
| 1264 |
+
return _weekday_shift(start, amount)
|
| 1265 |
+
try:
|
| 1266 |
+
return start + _dt.timedelta(days=amount * (7 if unit == 'week' else 1))
|
| 1267 |
+
except OverflowError:
|
| 1268 |
+
return None
|
| 1269 |
+
|
| 1270 |
+
|
| 1271 |
+
def _holiday_occurrence(holiday, rule, tenant_holidays=frozenset()):
|
| 1272 |
+
"""The exact date one unified holiday-offset rule names.
|
| 1273 |
+
|
| 1274 |
+
`weekday` intentionally ignores tenant holidays while `business_day` skips both weekends
|
| 1275 |
+
and the tenant's declared dates. The distinction is visible in the editor and keeps the
|
| 1276 |
+
server preview authoritative for the rule the person actually chose.
|
| 1277 |
+
"""
|
| 1278 |
+
relation = rule.get('relation', 'on')
|
| 1279 |
+
if relation == 'on':
|
| 1280 |
+
return holiday
|
| 1281 |
+
amount = rule['offset'] * (1 if relation == 'after' else -1)
|
| 1282 |
+
unit = rule.get('unit', 'day')
|
| 1283 |
+
if unit == 'month':
|
| 1284 |
+
return _shift_months(holiday, amount)
|
| 1285 |
+
if unit == 'year':
|
| 1286 |
+
return _shift_years(holiday, amount)
|
| 1287 |
+
if unit == 'business_day':
|
| 1288 |
+
return _business_day_shift(holiday, amount, tenant_holidays)
|
| 1289 |
+
if unit == 'weekday':
|
| 1290 |
+
return _weekday_shift(holiday, amount)
|
| 1291 |
+
try:
|
| 1292 |
+
return holiday + _dt.timedelta(days=amount * (7 if unit == 'week' else 1))
|
| 1293 |
+
except OverflowError:
|
| 1294 |
+
return None
|
| 1295 |
|
| 1296 |
|
| 1297 |
def _recurrence_matches(day, start, rule):
|
|
|
|
| 1332 |
ends = config.get('ends') or {'kind': 'never'}
|
| 1333 |
# A preview of at most fifty values needs no unbounded search. Ten years also makes an
|
| 1334 |
# unavailable public calendar visibly empty instead of spinning a request forever.
|
| 1335 |
+
try:
|
| 1336 |
+
horizon = max(start, now) + _dt.timedelta(days=3660)
|
| 1337 |
+
except OverflowError:
|
| 1338 |
+
horizon = _dt.date.max
|
| 1339 |
# ⛔ "After N occurrences" COUNTS FROM `startDate`, NOT FROM TODAY: occurrences already in the
|
| 1340 |
# past have spent the allowance. Counting from today is the obvious implementation and it is
|
| 1341 |
# wrong in a way that looks perfectly reasonable — a weekly Monday schedule begun 2026-01-01
|
|
|
|
| 1348 |
lower = max(start, now)
|
| 1349 |
if ends['kind'] == 'on':
|
| 1350 |
horizon = min(horizon, _iso_day(ends.get('date')) or horizon)
|
| 1351 |
+
found = set()
|
| 1352 |
holiday_rules = [rule for rule in config['rules'] if rule['kind'] == 'holiday']
|
| 1353 |
anchored_rules = [rule for rule in config['rules'] if rule['kind'] == 'anchored']
|
| 1354 |
ordinary_rules = [rule for rule in config['rules']
|
|
|
|
| 1363 |
for value in config.get('tenantHolidays', []))
|
| 1364 |
for rule in anchored_rules:
|
| 1365 |
occurrence = _anchored_occurrence(start, rule, tenant_holidays)
|
| 1366 |
+
if occurrence is not None and start <= occurrence <= horizon:
|
| 1367 |
found.add(occurrence)
|
| 1368 |
+
# A holiday's source year can differ from its result year when the chosen unit is years. We
|
| 1369 |
+
# generate each authoritative occurrence once, then let the ordinary-rule scan merge it with
|
| 1370 |
+
# daily/weekly/monthly values. Stopping that scan merely because holidays filled the preview
|
| 1371 |
+
# would drop an earlier ordinary occurrence, so it intentionally walks the finite horizon.
|
| 1372 |
+
for rule in holiday_rules:
|
| 1373 |
+
extra_years = rule['offset'] if rule.get('unit') == 'year' and rule.get('relation') != 'on' else 0
|
| 1374 |
+
for holiday_year in range(start.year, min(9999, horizon.year + extra_years) + 1):
|
| 1375 |
+
if (holiday_year - start.year) % rule['interval']:
|
| 1376 |
+
continue
|
| 1377 |
+
holidays = ({_dt.date.fromisoformat(value) for value in config.get('tenantHolidays', [])
|
| 1378 |
+
if value.startswith(f"{holiday_year:04d}-")}
|
| 1379 |
+
if rule['calendar'] == 'TENANT'
|
| 1380 |
+
else public_holidays(rule['calendar'], holiday_year))
|
| 1381 |
+
for holiday in holidays:
|
| 1382 |
+
occurrence = _holiday_occurrence(holiday, rule, tenant_holidays)
|
| 1383 |
+
# Outside an `ends: after` rule the old day scan began at `lower`, so adding
|
| 1384 |
+
# earlier calendar occurrences here would let past holidays consume the preview
|
| 1385 |
+
# limit before today's dates were considered.
|
| 1386 |
+
if occurrence is not None and lower <= occurrence <= horizon:
|
| 1387 |
+
found.add(occurrence)
|
| 1388 |
+
day = lower
|
| 1389 |
+
while ordinary_rules and day <= horizon:
|
| 1390 |
if any(_recurrence_matches(day, start, rule) for rule in ordinary_rules):
|
| 1391 |
found.add(day)
|
| 1392 |
+
if day == _dt.date.max:
|
| 1393 |
+
break
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1394 |
day += _dt.timedelta(days=1)
|
| 1395 |
allowed = sorted(found)[:limit]
|
| 1396 |
return [item.isoformat() for item in allowed if item >= now][:want]
|
web/src/customer-grid/DatePicker.tsx
CHANGED
|
@@ -14,25 +14,25 @@ const RULE_KINDS = ["daily", "weekly", "monthly", "monthly_ordinal", "yearly", "
|
|
| 14 |
// another date field". The other date field is the recurrence's EXISTING `anchorField`, so there
|
| 15 |
// is no second anchor concept and no per-rule anchor; because that anchor is a column, every
|
| 16 |
// record computes its own answer from its own value.
|
| 17 |
-
//
|
| 18 |
-
//
|
| 19 |
-
//
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
// and one word for two vocabularies is the confusion this surface keeps paying for.
|
| 23 |
-
type AnchoredUnit = "day" | "business_day" | "week" | "month";
|
| 24 |
-
type AnchoredRelation = "on" | "after" | "before";
|
| 25 |
type DateRule = Omit<DateRecurrenceRule, "kind"> & {
|
| 26 |
kind: DateRecurrenceRule["kind"] | "anchored";
|
| 27 |
-
unit?: AnchoredUnit;
|
| 28 |
-
relation?: AnchoredRelation;
|
| 29 |
};
|
| 30 |
type RuleKind = DateRule["kind"] | "monthly_ordinal";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
// W46-T33: a holiday rule may now name ONE holiday instead of a whole national calendar, so the
|
| 32 |
-
// code is any string the server's registry admits and `group` says which heading it belongs
|
| 33 |
-
// under. This LOCAL type widens; `types.ts` does not, because the granular id rides the existing
|
| 34 |
-
// `calendar` field, `clean_date_recurrence` is what validates it, and widening the shared shape
|
| 35 |
-
// would ask three parity gates to agree about a value only the server can judge.
|
| 36 |
type CalendarOption = { code: string; label: string; group?: "calendar" | "holiday" };
|
| 37 |
// The two entries the server is certain to send, so the first paint before the preview call
|
| 38 |
// returns is never an empty dropdown. The seventeen single holidays are NOT copied here: the
|
|
@@ -57,12 +57,21 @@ function iso(date: Date): string { return date.toISOString().slice(0, 10); }
|
|
| 57 |
function addMonths(date: Date, amount: number): Date { const out = new Date(date); out.setUTCMonth(out.getUTCMonth() + amount); return out; }
|
| 58 |
function bounded(value: unknown, lower: number, upper: number, fallback: number): number { const number = Math.round(Number(value)); return Number.isFinite(number) ? Math.max(lower, Math.min(upper, number)) : fallback; }
|
| 59 |
function ruleKind(rule: DateRule): RuleKind { return rule.kind === "monthly" && rule.ordinal !== undefined ? "monthly_ordinal" : rule.kind; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
function newRule(kind: RuleKind, selected: Date): DateRule {
|
| 61 |
if (kind === "weekly") return { kind, interval: 1, weekdays: [((selected.getUTCDay() + 6) % 7)] };
|
| 62 |
if (kind === "monthly_ordinal") return { kind: "monthly", interval: 1, ordinal: 1, weekday: 0 };
|
| 63 |
if (kind === "monthly") return { kind, interval: 1, day: selected.getUTCDate() };
|
| 64 |
if (kind === "yearly") return { kind, interval: 1, month: selected.getUTCMonth() + 1, day: selected.getUTCDate() };
|
| 65 |
-
if (kind === "holiday") return { kind, interval: 1, calendar: "US", offset: 0 };
|
| 66 |
// ⛔ Never emit `interval: 0`: `clean_date_recurrence` bounds it to 1..366 and SILENTLY DROPS
|
| 67 |
// the whole rule below that, so an "on" relation still carries 1.
|
| 68 |
if (kind === "anchored") return { kind, interval: 1, unit: "day", relation: "after" };
|
|
@@ -118,22 +127,29 @@ function ruleSentence(rule: DateRule, calendars: CalendarOption[]): string {
|
|
| 118 |
if (kind === "yearly") return `every ${unit("year")} on ${MONTHS[bounded(rule.month ?? 1, 1, 12, 1) - 1]} ${rule.day ?? 1}`;
|
| 119 |
if (kind === "holiday") {
|
| 120 |
const option = calendars.find((item) => item.code === (rule.calendar ?? "US"));
|
| 121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
// W47-T28: on a holiday rule `interval` counts YEARS, which the card now says out loud, so
|
| 123 |
// the sentence says it too. At 1 the phrase is left exactly as it was, because every year is
|
| 124 |
// what a holiday rule already means and repeating it reads as noise.
|
| 125 |
const cadence = every === 1 ? "" : `, every ${every} years`;
|
| 126 |
// A single holiday reads as itself. "each holiday in Christmas Day" is what the calendar
|
| 127 |
// phrasing becomes once a rule can name one day, and it is not a sentence anybody wrote.
|
| 128 |
-
if (option?.group === "holiday") return `
|
| 129 |
-
return `
|
| 130 |
}
|
| 131 |
if (kind === "anchored") {
|
| 132 |
// `unit()` above drops the count at 1, which reads right for "every day" and wrong for
|
| 133 |
// "1 day after", so an anchored rule spells its own phrase out.
|
| 134 |
const relation = rule.relation ?? "after";
|
| 135 |
if (relation === "on") return "on the anchor date";
|
| 136 |
-
|
|
|
|
| 137 |
}
|
| 138 |
return `every ${unit("day")}`;
|
| 139 |
}
|
|
@@ -397,7 +413,7 @@ export function DatePicker({ anchor, field, fields, pid, scopeKey, value, today,
|
|
| 397 |
<div className="w46-recur-controls">
|
| 398 |
{(rule.relation ?? "after") !== "on" && <>
|
| 399 |
<input className="cg-input w46-recur-count" min="1" max="366" type="number" aria-label={`Distance from the anchor ${index + 1}`} value={rule.interval ?? 1} onChange={(event) => updateRule(index, { interval: bounded(event.target.value, 1, 366, 1) })} />
|
| 400 |
-
<select className="cg-select" value={rule.unit ?? "day"} aria-label={`Distance unit ${index + 1}`} onChange={(event) => updateRule(index, { unit: event.target.value as AnchoredUnit })}><option value="day">days</option><option value="business_day">business days</option><option value="week">weeks</option><option value="month">months</option></select>
|
| 401 |
</>}
|
| 402 |
{/* Switching to "on" carries `interval: 1` with it. The count input goes away, and a
|
| 403 |
stale 5 left behind it would be saved and then read back as a distance nobody
|
|
@@ -411,20 +427,26 @@ export function DatePicker({ anchor, field, fields, pid, scopeKey, value, today,
|
|
| 411 |
{anchorField === field.key && <div className="w46-recur-row"><span className="w46-recur-word">Choose the date field this counts from.</span></div>}
|
| 412 |
{(rule.relation ?? "after") === "before" && <div className="w46-recur-row"><span className="w46-recur-word">A date that has already passed is left empty.</span></div>}
|
| 413 |
</> : rule.kind === "holiday" ? <>
|
| 414 |
-
{/*
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
(`(holiday_year - start.year) % rule['interval']` in `recurrence_preview`), so the
|
| 418 |
-
row says the word year out loud. The two selects below are the wave-46 ones, moved
|
| 419 |
-
and not rewritten; the grouping keeps single days out of the federal calendars. */}
|
| 420 |
<div className="w46-recur-row">
|
| 421 |
<span className="w46-recur-label">Holidays</span>
|
| 422 |
<div className="w46-recur-controls">
|
| 423 |
-
<select className="cg-select" value={rule.calendar ?? "US"} aria-label="Public calendar" onChange={(event) => updateRule(index, { calendar: event.target.value
|
| 424 |
const members = calendars.filter((calendar) => (calendar.group ?? "calendar") === group);
|
| 425 |
return members.length ? <optgroup key={heading} label={heading}>{members.map((calendar) => <option key={calendar.code} value={calendar.code}>{calendar.label}</option>)}</optgroup> : null;
|
| 426 |
})}</select>
|
| 427 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 428 |
</div>
|
| 429 |
</div>
|
| 430 |
<div className="w46-recur-row">
|
|
|
|
| 14 |
// another date field". The other date field is the recurrence's EXISTING `anchorField`, so there
|
| 15 |
// is no second anchor concept and no per-rule anchor; because that anchor is a column, every
|
| 16 |
// record computes its own answer from its own value.
|
| 17 |
+
// `anchored` remains local because only the server validates its anchor semantics. Its shared
|
| 18 |
+
// quantity/unit/relation vocabulary now lives in `types.ts` too, so holiday and anchored editors
|
| 19 |
+
// cannot drift into incompatible control shapes again.
|
| 20 |
+
type AnchoredUnit = NonNullable<DateRecurrenceRule["unit"]>;
|
| 21 |
+
type AnchoredRelation = NonNullable<DateRecurrenceRule["relation"]>;
|
|
|
|
|
|
|
|
|
|
| 22 |
type DateRule = Omit<DateRecurrenceRule, "kind"> & {
|
| 23 |
kind: DateRecurrenceRule["kind"] | "anchored";
|
|
|
|
|
|
|
| 24 |
};
|
| 25 |
type RuleKind = DateRule["kind"] | "monthly_ordinal";
|
| 26 |
+
const OFFSET_UNIT_LABELS: Record<AnchoredUnit, string> = {
|
| 27 |
+
day: "day",
|
| 28 |
+
business_day: "business day",
|
| 29 |
+
weekday: "weekday",
|
| 30 |
+
week: "week",
|
| 31 |
+
month: "month",
|
| 32 |
+
year: "year",
|
| 33 |
+
};
|
| 34 |
// W46-T33: a holiday rule may now name ONE holiday instead of a whole national calendar, so the
|
| 35 |
+
// code is any string the server's registry admits and `group` says which heading it belongs under.
|
|
|
|
|
|
|
|
|
|
| 36 |
type CalendarOption = { code: string; label: string; group?: "calendar" | "holiday" };
|
| 37 |
// The two entries the server is certain to send, so the first paint before the preview call
|
| 38 |
// returns is never an empty dropdown. The seventeen single holidays are NOT copied here: the
|
|
|
|
| 57 |
function addMonths(date: Date, amount: number): Date { const out = new Date(date); out.setUTCMonth(out.getUTCMonth() + amount); return out; }
|
| 58 |
function bounded(value: unknown, lower: number, upper: number, fallback: number): number { const number = Math.round(Number(value)); return Number.isFinite(number) ? Math.max(lower, Math.min(upper, number)) : fallback; }
|
| 59 |
function ruleKind(rule: DateRule): RuleKind { return rule.kind === "monthly" && rule.ordinal !== undefined ? "monthly_ordinal" : rule.kind; }
|
| 60 |
+
function holidayRelation(rule: DateRule): AnchoredRelation {
|
| 61 |
+
if (rule.relation === "before" || rule.relation === "on" || rule.relation === "after") return rule.relation;
|
| 62 |
+
const legacyOffset = Number(rule.offset ?? 0);
|
| 63 |
+
return legacyOffset < 0 ? "before" : legacyOffset > 0 ? "after" : "on";
|
| 64 |
+
}
|
| 65 |
+
function holidayOffset(rule: DateRule): number {
|
| 66 |
+
return bounded(Math.abs(Number(rule.offset ?? 1)) || 1, 1, 366, 1);
|
| 67 |
+
}
|
| 68 |
+
function offsetUnitLabel(unit: AnchoredUnit | undefined): string { return OFFSET_UNIT_LABELS[unit ?? "day"]; }
|
| 69 |
function newRule(kind: RuleKind, selected: Date): DateRule {
|
| 70 |
if (kind === "weekly") return { kind, interval: 1, weekdays: [((selected.getUTCDay() + 6) % 7)] };
|
| 71 |
if (kind === "monthly_ordinal") return { kind: "monthly", interval: 1, ordinal: 1, weekday: 0 };
|
| 72 |
if (kind === "monthly") return { kind, interval: 1, day: selected.getUTCDate() };
|
| 73 |
if (kind === "yearly") return { kind, interval: 1, month: selected.getUTCMonth() + 1, day: selected.getUTCDate() };
|
| 74 |
+
if (kind === "holiday") return { kind, interval: 1, calendar: "US", offset: 0, unit: "day", relation: "on" };
|
| 75 |
// ⛔ Never emit `interval: 0`: `clean_date_recurrence` bounds it to 1..366 and SILENTLY DROPS
|
| 76 |
// the whole rule below that, so an "on" relation still carries 1.
|
| 77 |
if (kind === "anchored") return { kind, interval: 1, unit: "day", relation: "after" };
|
|
|
|
| 127 |
if (kind === "yearly") return `every ${unit("year")} on ${MONTHS[bounded(rule.month ?? 1, 1, 12, 1) - 1]} ${rule.day ?? 1}`;
|
| 128 |
if (kind === "holiday") {
|
| 129 |
const option = calendars.find((item) => item.code === (rule.calendar ?? "US"));
|
| 130 |
+
// The server converts the retired signed +/-1 form before returning it. This fallback keeps
|
| 131 |
+
// a just-opened legacy draft intelligible until that read completes; every fresh save uses
|
| 132 |
+
// the quantity/unit/relation form below.
|
| 133 |
+
const relation = holidayRelation(rule);
|
| 134 |
+
const offset = relation === "on" ? 0 : holidayOffset(rule);
|
| 135 |
+
const offsetWord = offsetUnitLabel(rule.unit);
|
| 136 |
+
const amount = relation === "on" ? "on" : `${offset} ${offsetWord}${offset === 1 ? "" : "s"} ${relation}`;
|
| 137 |
// W47-T28: on a holiday rule `interval` counts YEARS, which the card now says out loud, so
|
| 138 |
// the sentence says it too. At 1 the phrase is left exactly as it was, because every year is
|
| 139 |
// what a holiday rule already means and repeating it reads as noise.
|
| 140 |
const cadence = every === 1 ? "" : `, every ${every} years`;
|
| 141 |
// A single holiday reads as itself. "each holiday in Christmas Day" is what the calendar
|
| 142 |
// phrasing becomes once a rule can name one day, and it is not a sentence anybody wrote.
|
| 143 |
+
if (option?.group === "holiday") return `${amount} ${option.label}${cadence}`;
|
| 144 |
+
return `${amount} each holiday in ${option?.label ?? "public holidays"}${cadence}`;
|
| 145 |
}
|
| 146 |
if (kind === "anchored") {
|
| 147 |
// `unit()` above drops the count at 1, which reads right for "every day" and wrong for
|
| 148 |
// "1 day after", so an anchored rule spells its own phrase out.
|
| 149 |
const relation = rule.relation ?? "after";
|
| 150 |
if (relation === "on") return "on the anchor date";
|
| 151 |
+
const unitLabel = offsetUnitLabel(rule.unit);
|
| 152 |
+
return `${every} ${unitLabel}${every === 1 ? "" : "s"} ${relation} the anchor date`;
|
| 153 |
}
|
| 154 |
return `every ${unit("day")}`;
|
| 155 |
}
|
|
|
|
| 413 |
<div className="w46-recur-controls">
|
| 414 |
{(rule.relation ?? "after") !== "on" && <>
|
| 415 |
<input className="cg-input w46-recur-count" min="1" max="366" type="number" aria-label={`Distance from the anchor ${index + 1}`} value={rule.interval ?? 1} onChange={(event) => updateRule(index, { interval: bounded(event.target.value, 1, 366, 1) })} />
|
| 416 |
+
<select className="cg-select" value={rule.unit ?? "day"} aria-label={`Distance unit ${index + 1}`} onChange={(event) => updateRule(index, { unit: event.target.value as AnchoredUnit })}><option value="day">days</option><option value="business_day">business days</option><option value="weekday">weekdays</option><option value="week">weeks</option><option value="month">months</option><option value="year">years</option></select>
|
| 417 |
</>}
|
| 418 |
{/* Switching to "on" carries `interval: 1` with it. The count input goes away, and a
|
| 419 |
stale 5 left behind it would be saved and then read back as a distance nobody
|
|
|
|
| 427 |
{anchorField === field.key && <div className="w46-recur-row"><span className="w46-recur-word">Choose the date field this counts from.</span></div>}
|
| 428 |
{(rule.relation ?? "after") === "before" && <div className="w46-recur-row"><span className="w46-recur-word">A date that has already passed is left empty.</span></div>}
|
| 429 |
</> : rule.kind === "holiday" ? <>
|
| 430 |
+
{/* W48C-T11: Holidays is no longer a disconnected +/-1 control. Calendar, quantity,
|
| 431 |
+
unit and before/on/after are one sentence, exactly like the server's canonical
|
| 432 |
+
rule. `interval` remains the separate cadence in years below. */}
|
|
|
|
|
|
|
|
|
|
| 433 |
<div className="w46-recur-row">
|
| 434 |
<span className="w46-recur-label">Holidays</span>
|
| 435 |
<div className="w46-recur-controls">
|
| 436 |
+
<select className="cg-select" value={rule.calendar ?? "US"} aria-label="Public calendar" onChange={(event) => updateRule(index, { calendar: event.target.value })}>{CALENDAR_GROUPS.map(([group, heading]) => {
|
| 437 |
const members = calendars.filter((calendar) => (calendar.group ?? "calendar") === group);
|
| 438 |
return members.length ? <optgroup key={heading} label={heading}>{members.map((calendar) => <option key={calendar.code} value={calendar.code}>{calendar.label}</option>)}</optgroup> : null;
|
| 439 |
})}</select>
|
| 440 |
+
{holidayRelation(rule) !== "on" && <>
|
| 441 |
+
<input className="cg-input w46-recur-count" min="1" max="366" type="number" aria-label={`Holiday offset quantity ${index + 1}`} value={holidayOffset(rule)} onChange={(event) => updateRule(index, { offset: bounded(event.target.value, 1, 366, 1) })} />
|
| 442 |
+
<select className="cg-select" value={rule.unit ?? "day"} aria-label={`Holiday offset unit ${index + 1}`} onChange={(event) => updateRule(index, { unit: event.target.value as AnchoredUnit })}><option value="day">days</option><option value="business_day">business days</option><option value="weekday">weekdays</option><option value="week">weeks</option><option value="month">months</option><option value="year">years</option></select>
|
| 443 |
+
</>}
|
| 444 |
+
<select className="cg-select" value={holidayRelation(rule)} aria-label={`Holiday offset relation ${index + 1}`} onChange={(event) => {
|
| 445 |
+
const relation = event.target.value as AnchoredRelation;
|
| 446 |
+
updateRule(index, relation === "on"
|
| 447 |
+
? { relation, offset: 0, unit: "day" }
|
| 448 |
+
: { relation, offset: holidayOffset(rule) });
|
| 449 |
+
}}><option value="before">before</option><option value="on">on</option><option value="after">after</option></select>
|
| 450 |
</div>
|
| 451 |
</div>
|
| 452 |
<div className="w46-recur-row">
|
web/src/customer-grid/types.ts
CHANGED
|
@@ -117,9 +117,12 @@ export type DateRecurrenceRule = {
|
|
| 117 |
ordinal?: -1 | 1 | 2 | 3 | 4 | 5;
|
| 118 |
weekday?: number;
|
| 119 |
/** Only an API-supplied public or tenant calendar can be saved. */
|
| 120 |
-
calendar?:
|
| 121 |
-
/**
|
| 122 |
-
offset?:
|
|
|
|
|
|
|
|
|
|
| 123 |
};
|
| 124 |
|
| 125 |
export type DateRecurrence = {
|
|
|
|
| 117 |
ordinal?: -1 | 1 | 2 | 3 | 4 | 5;
|
| 118 |
weekday?: number;
|
| 119 |
/** Only an API-supplied public or tenant calendar can be saved. */
|
| 120 |
+
calendar?: string;
|
| 121 |
+
/** The positive quantity for a holiday offset; zero is valid only when relation is `on`. */
|
| 122 |
+
offset?: number;
|
| 123 |
+
/** The offset vocabulary shared by holiday and anchored Date rules. */
|
| 124 |
+
unit?: "day" | "business_day" | "weekday" | "week" | "month" | "year";
|
| 125 |
+
relation?: "before" | "on" | "after";
|
| 126 |
};
|
| 127 |
|
| 128 |
export type DateRecurrence = {
|