Skip to content

Commit

Permalink
Merge pull request #52 from MohmdFo/main
Browse files Browse the repository at this point in the history
feat(BaseDataGenerator): add get_random_timedelta method to the gener…
  • Loading branch information
sepehr-akbarzadeh authored Sep 27, 2024
2 parents 84e5b41 + 775389c commit ac56058
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 ac56058

Please sign in to comment.