/// <summary> /// Gets the TripStartTime converted to a DateTime /// </summary> /// <param name="midnightRolloverMode">Whether the function should operate in Midnight Rollover Mode</param> /// <returns>The TripStartTime</returns> public virtual DateTime GetTripStartTime(bool midnightRolloverMode) { var startTimeSpan = SourceTrip.GetTripStartTimeTimespan(); if (startTimeSpan.Days <= 0) { return(Today.AddMinutes(startTimeSpan.TotalMinutes)); } int year = Today.Year; int month = Today.Month; DateTime startTime = new DateTime(year, month, 1, startTimeSpan.Hours, startTimeSpan.Minutes, 0); // Because we start at the first day of the month, we have to subtract the first day int day = Today.Day - 1; // To handle the fact that Midnight times still operate on the 24 hour clock of the previous day (24:00->28:00) // Then we'll handle the times differently depending on what hour of the day it is if (midnightRolloverMode) { day += (startTimeSpan.Days - 1); } else { day += startTimeSpan.Days; } // Return the Start Time with the days added back in return(startTime.AddDays(day)); }