Skip to content

fix(cost_budget): align 7d period start to Monday UTC#146

Merged
levleontiev merged 2 commits intomainfrom
fix/cost-budget-7d-monday-alignment
Apr 12, 2026
Merged

fix(cost_budget): align 7d period start to Monday UTC#146
levleontiev merged 2 commits intomainfrom
fix/cost-budget-7d-monday-alignment

Conversation

@levleontiev
Copy link
Copy Markdown
Contributor

Summary

The compute_period_start function in src/fairvisor/cost_budget.lua was aligning weekly (7d) budget periods to Sunday instead of Monday UTC as documented in the test spec.

Root cause

The offset used in the 7d calculation was 259200 (3 days from the Unix epoch, which was a Thursday — putting the anchor on Sunday January 4, 1970). The correct offset is 345600 (4 days from epoch = Monday January 5, 1970).

-- Before (aligns to Sunday):
return floor((now - 259200) / 604800) * 604800 + 259200

-- After (aligns to Monday):
return floor((now - 345600) / 604800) * 604800 + 345600

Changes

  • src/fairvisor/cost_budget.lua: Change 7d offset from 259200345600
  • spec/unit/features/cost_budget.feature: Update expected period start from 1769904000 (Sun Feb 1 2026) → 1769990400 (Mon Feb 2 2026)

Verification

For now = 1770129000:

  • Old: floor((1770129000 - 259200) / 604800) * 604800 + 259200 = 1769904000 (Sunday)
  • New: floor((1770129000 - 345600) / 604800) * 604800 + 345600 = 1769990400 (Monday ✓)

🤖 Generated with Claude Code

The compute_period_start function for the '7d' period was using an
offset of 259200 (3 days from epoch Thursday = Sunday), but the
test spec documents the period should be aligned to Monday UTC.

Change the offset to 345600 (4 days from epoch = Monday) so that
weekly budget periods start on Monday at 00:00 UTC.
The scenario 'computes weekly period boundary aligned to Monday UTC'
had an expected value of 1769904000 (Sunday Feb 1 2026) instead of
1769990400 (Monday Feb 2 2026). Update to match the corrected
Monday-aligned offset in compute_period_start.
@levleontiev levleontiev merged commit a8306e1 into main Apr 12, 2026
11 checks passed
@levleontiev levleontiev deleted the fix/cost-budget-7d-monday-alignment branch April 12, 2026 04:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant