This commit is contained in:
stuzer05 2023-02-27 16:49:29 +02:00
parent e20e23b60a
commit 37e8e8ddaf
No known key found for this signature in database
GPG Key ID: A6ABAAA9268F9F4F
1 changed files with 30 additions and 22 deletions

View File

@ -2540,37 +2540,45 @@ func (issue *Issue) TimeEstimateFromStr(timeStr string) int64 {
timeTotal := 0
// Time match regex
rOnlyHours := regexp.MustCompile(`^([\d]+)$`)
rWeeks := regexp.MustCompile(`([\d]+)w`)
rDays := regexp.MustCompile(`([\d]+)d`)
rHours := regexp.MustCompile(`([\d]+)h`)
rMinutes := regexp.MustCompile(`([\d]+)m`)
// Find time weeks
timeStrMatches := rWeeks.FindStringSubmatch(timeStr)
if len(timeStrMatches) > 0 {
raw, _ := strconv.Atoi(timeStrMatches[1])
timeTotal += raw * (60 * 60 * 24 * 7)
}
// Find time days
timeStrMatches = rDays.FindStringSubmatch(timeStr)
if len(timeStrMatches) > 0 {
raw, _ := strconv.Atoi(timeStrMatches[1])
timeTotal += raw * (60 * 60 * 24)
}
// Find time hours
timeStrMatches = rHours.FindStringSubmatch(timeStr)
// If single number entered, assume hours
timeStrMatches := rOnlyHours.FindStringSubmatch(timeStr)
if len(timeStrMatches) > 0 {
raw, _ := strconv.Atoi(timeStrMatches[1])
timeTotal += raw * (60 * 60)
}
} else {
// Find time weeks
timeStrMatches = rWeeks.FindStringSubmatch(timeStr)
if len(timeStrMatches) > 0 {
raw, _ := strconv.Atoi(timeStrMatches[1])
timeTotal += raw * (60 * 60 * 24 * 7)
}
// Find time minutes
timeStrMatches = rMinutes.FindStringSubmatch(timeStr)
if len(timeStrMatches) > 0 {
raw, _ := strconv.Atoi(timeStrMatches[1])
timeTotal += raw * (60)
// Find time days
timeStrMatches = rDays.FindStringSubmatch(timeStr)
if len(timeStrMatches) > 0 {
raw, _ := strconv.Atoi(timeStrMatches[1])
timeTotal += raw * (60 * 60 * 24)
}
// Find time hours
timeStrMatches = rHours.FindStringSubmatch(timeStr)
if len(timeStrMatches) > 0 {
raw, _ := strconv.Atoi(timeStrMatches[1])
timeTotal += raw * (60 * 60)
}
// Find time minutes
timeStrMatches = rMinutes.FindStringSubmatch(timeStr)
if len(timeStrMatches) > 0 {
raw, _ := strconv.Atoi(timeStrMatches[1])
timeTotal += raw * (60)
}
}
return int64(timeTotal)