|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Microsoft.Extensions.Logging;
-
- namespace BlackRockReportFunction.Helpers
- {
- public static class Formaters
- {
- public static string getSumOfRecordTimes(List<TimeOnly> recordTimes)
- {
- int totalHours = 0;
- int totalMinutes = 0;
- int totalSeconds = 0;
-
- // Calculate Seconds
- int totalRecordsSeconds = recordTimes.Sum(record => record.Second);
- totalSeconds = totalRecordsSeconds % 60;
- totalMinutes += totalRecordsSeconds / 60;
-
- // Calculate Minutes
- int totalRecordsMinutes = recordTimes.Sum(record => record.Minute);
-
- totalMinutes = totalMinutes + (totalRecordsMinutes % 60);
- totalHours += totalRecordsMinutes / 60;
-
- // Calculate Hours
- int totalRecordHours = recordTimes.Sum(record => record.Hour);
- totalHours += totalRecordHours;
-
- return string.Format("{0}:{1}:{2}",
- totalHours > 9 ? totalHours : string.Format("0{0}", totalHours),
- totalMinutes > 9 ? totalMinutes : string.Format("0{0}", totalMinutes),
- totalSeconds > 9 ? totalSeconds : string.Format("0{0}", totalSeconds));
- }
-
- public static string getDecimalHours(string recordHoursSum)
- {
- var components = recordHoursSum.Split(':').ToList();
-
- var hours = (components[0].Length == 2 && components[0].First() == '0')
- ? components[0].ToCharArray()[1].ToString()
- : components[0];
-
- var totalMinutes = Convert.ToDecimal(components[1]) + (Convert.ToDecimal(components[2]) / 60);
-
- var minutesPercent = Convert.ToInt32(Math.Floor(totalMinutes * 100 / 60)).ToString();
- if (minutesPercent.Length == 1)
- {
- minutesPercent = string.Format("0{0}", minutesPercent);
- }
-
- return string.Format("{0}:{1}", hours, minutesPercent);
- }
-
- public static string getDecimalHours(TimeOnly recordTime)
- {
- return getDecimalHours(string.Format("{0}:{1}:{2}", recordTime.Hour, recordTime.Minute, recordTime.Second));
- }
-
- public static string getRecordTime(TimeOnly recordTime)
- {
- return string.Format("{0}:{1}:{2}", recordTime.Hour, recordTime.Minute, recordTime.Second);
- }
-
- public static string getTotalSum(List<string> personsSums)
- {
- var totalHours = 0;
- var totalMinutes = 0;
- var totalSeconds = 0;
-
- foreach(var personSum in personsSums)
- {
- var components = personSum.Split(':').Select(Int32.Parse).ToList();
-
- //add new person time
- totalSeconds += components[2] % 60;
- totalMinutes += components[2] / 60;
-
- //clean up new sum
- totalMinutes += totalSeconds / 60;
- totalSeconds = totalSeconds % 60;
-
- //add new person time
- totalMinutes += components[1] % 60;
- totalHours += components[1] / 60;
-
- //clean up new time
- totalHours += totalMinutes / 60;
- totalMinutes = totalMinutes % 60;
-
- //add new person time
- totalHours += components[0];
- }
-
- return string.Format("{0}:{1}:{2}",
- totalHours > 9 ? totalHours : string.Format("0{0}", totalHours),
- totalMinutes > 9 ? totalMinutes : string.Format("0{0}", totalMinutes),
- totalSeconds > 9 ? totalSeconds : string.Format("0{0}", totalSeconds));
- }
-
- public static string getTotalDecimalHours(List<string> usersDecimalHours)
- {
- var minutesPercent = 0;
- var hours = 0;
- foreach(var userDecimalHours in usersDecimalHours)
- {
- var components = userDecimalHours.Split(':');
- minutesPercent += Convert.ToInt32(components[1]);
- hours += Convert.ToInt32(components[0]);
- }
-
- hours += minutesPercent / 100;
- minutesPercent = minutesPercent % 100;
-
- return string.Format("{0}:{1}", hours, minutesPercent);
- }
- }
- }
|