tylerstambaugh / SegmentSniper

3 stars 1 forks source link

Create helpers class for utility functions in GetSnipeSegmentsByActivityIdActionHandler #362

Closed tylerstambaugh closed 2 months ago

tylerstambaugh commented 3 months ago

private XomsTimes GetXomTimeFromStrings(Xoms xoms) { return new XomsTimes { KomTime = GetTimeFromString(xoms.Kom), QomTime = GetTimeFromString(xoms.Qom) }; }

private int GetTimeFromString(string time) { time = RemoveLetters(time);

  int returnTime = 0;
  string[] timeParts = time.Split(':');

  for (int i = 0; i <= timeParts.Length - 1; i++)
  {
      int factor = (int)Math.Pow(60, i);
      returnTime += int.Parse(timeParts[timeParts.Length - (i + 1)]) * factor;
  }
  return returnTime;

}

private string RemoveLetters(string input) { Regex regex = new Regex("[^0-9:]"); return regex.Replace(input, ""); }

private class XomsTimes { public int KomTime { get; set; } public int QomTime { get; set; } }

private string ConvertTimeInSeconds(int seconds) { int hours = seconds / 3600; int minutes = seconds / 60 - (hours 60); int remainingSeconds = seconds - ((hours 3600) + (minutes * 60));

  var timeAsString = "";
  if(hours > 0)
  {
      timeAsString = $"{hours:D2}:{minutes:D2}:{Math.Abs(remainingSeconds):D2}";
  }
  if(hours == 0)
  {
      timeAsString = $"{minutes:D2}:{Math.Abs(remainingSeconds):D2}";
  }
  if (remainingSeconds < 0)
  {
      timeAsString = $"-{timeAsString}";
  }

  return timeAsString;

}

should be put into their own helper class.

tylerstambaugh commented 2 months ago

this has been implemented