Skip to content

Commit

Permalink
feat(BaseDataGenerator): add get_random_timedelta method to the gener…
Browse files Browse the repository at this point in the history
…ator
  • Loading branch information
MohmdFo committed Sep 26, 2024
1 parent 84e5b41 commit 775389c
Showing 1 changed file with 15 additions and 1 deletion.
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))

0 comments on commit 775389c

Please sign in to comment.