Magic numbers for date calculations should be named constants #9

Open
opened 2025-11-15 03:44:12 +00:00 by snegov · 0 comments
Owner

Magic numbers for date calculations should be named constants

Priority: Low
Component: backup.py
Type: Code Quality

Description

The retention policy calculations use magic numbers (30 for days/month, 365 for days/year) directly in the code, making it less readable and maintainable.

Location

curateipsum/backup.py:208-214

Current Code

if keep_monthly is not None:
    thresholds["monthly"] = ((now - timedelta(days=30*keep_monthly))
                             .replace(day=1, hour=0, minute=0, second=0)
                             .strftime(BACKUP_ENT_FMT))
if keep_yearly is not None:
    thresholds["yearly"] = (
        (now - timedelta(days=365*keep_yearly))
        .replace(month=1, day=1, hour=0, minute=0, second=0)
        .strftime(BACKUP_ENT_FMT)
    )

Proposed Solution

DAYS_PER_MONTH = 30  # Approximate for retention calculations
DAYS_PER_YEAR = 365  # Approximate for retention calculations

# Then use:
thresholds["monthly"] = ((now - timedelta(days=DAYS_PER_MONTH * keep_monthly))

Impact

Low - Code quality issue, doesn't affect functionality.

# Magic numbers for date calculations should be named constants **Priority:** Low **Component:** backup.py **Type:** Code Quality ## Description The retention policy calculations use magic numbers (30 for days/month, 365 for days/year) directly in the code, making it less readable and maintainable. ## Location `curateipsum/backup.py:208-214` ## Current Code ```python if keep_monthly is not None: thresholds["monthly"] = ((now - timedelta(days=30*keep_monthly)) .replace(day=1, hour=0, minute=0, second=0) .strftime(BACKUP_ENT_FMT)) if keep_yearly is not None: thresholds["yearly"] = ( (now - timedelta(days=365*keep_yearly)) .replace(month=1, day=1, hour=0, minute=0, second=0) .strftime(BACKUP_ENT_FMT) ) ``` ## Proposed Solution ```python DAYS_PER_MONTH = 30 # Approximate for retention calculations DAYS_PER_YEAR = 365 # Approximate for retention calculations # Then use: thresholds["monthly"] = ((now - timedelta(days=DAYS_PER_MONTH * keep_monthly)) ``` ## Impact **Low** - Code quality issue, doesn't affect functionality.
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: snegov/cura-te-ipsum#9