Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(BaseDataGenerator): add get_random_timedelta method to the gener… #52

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion sage_tools/repository/generator/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import io
import random
import secrets
from datetime import datetime, timezone
from datetime import datetime, timezone, timedelta
from typing import Any, List, Set, Type, TypeVar

from django.db.models import Model
Expand Down Expand Up @@ -417,3 +417,17 @@ def add_to_m2m(
except IndexError:
raise IndexError("`objs` is empty. Please ensure population is not None.")
attr.add(*items_to_add)

def get_random_timedelta(self, min_minutes=0, max_minutes=1):
"""
Scenario:
Create a random duration within a specified range of minutes for varied
applications.

Algorithm:
Converts a given minute range to seconds and generates a random duration
within this range, returning it as a timedelta object.
"""
max_seconds = max_minutes * 60
min_seconds = min_minutes * 60
return timedelta(seconds=random.randint(min_seconds, max_seconds))
Loading