Skip to content

Commit

Permalink
feat: Dynamic shift of working hours don't exceed end time or precede…
Browse files Browse the repository at this point in the history
… start time
  • Loading branch information
sonjek committed Apr 7, 2024
1 parent 82fb607 commit 3c71a9e
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@ func IsInWorkingHours(timeWindow string) bool {
return true
}

startTimeBefore := MakeRandomTime(parts[0])
endTimeAfter := MakeRandomTime(parts[1])
// Generate a datetime 3-14 minutes earlier than the specified time
startTimeBefore := MakeRandomTime(parts[0], false)

// Generate a datetime 3-14 minutes later than the specified time
endTimeAfter := MakeRandomTime(parts[1], true)

currentTime := time.Now()

// Check if the current time is within the dynamic range
Expand All @@ -46,7 +50,7 @@ func IsInWorkingHours(timeWindow string) bool {
return false
}

func MakeRandomTime(inputTime string) time.Time {
func MakeRandomTime(inputTime string, isPositive bool) time.Time {

Check warning on line 53 in internal/utils/utils.go

View workflow job for this annotation

GitHub Actions / lint

flag-parameter: parameter 'isPositive' seems to be a control flag, avoid control coupling (revive)
// Parse input time like 19:00 to date time
parsedTime, err := time.Parse(timeLayout, inputTime)
if err != nil {
Expand All @@ -58,7 +62,7 @@ func MakeRandomTime(inputTime string) time.Time {
randomInterval := time.Duration(rand.N(12)+3) * time.Minute

// Randomly decide whether to add or subtract the interval
if rand.N(2) == 0 {
if isPositive {
parsedTime = parsedTime.Add(randomInterval)
} else {
parsedTime = parsedTime.Add(-randomInterval)
Expand Down

0 comments on commit 3c71a9e

Please sign in to comment.