public AvailabilityFactory(CleanerMatchResultVM cleaner, Int32 serviceGapMins, JobTypeEnum serviceType, IList <String> serviceZone) { Cleaner = cleaner ?? throw new ArgumentException("No cleaner specified.", nameof(Cleaner)); if (serviceGapMins <= 0) { throw new ArgumentException("Invalid service gap requested.", nameof(ServiceGapMinutes)); } if (serviceZone == null || serviceZone.Count == 0) { throw new ArgumentException("Invalid service suburb/zone requested.", nameof(ServiceZone)); } ServiceDay = cleaner.SelectedRosterDay; if (cleaner.SelectedServiceDate.HasValue && cleaner.SelectedServiceDate != default(DateTime)) { ServiceDateUTC = cleaner.SelectedServiceDate.Value.ToUTC(); } else if (JobType == JobTypeEnum.Fortnighly || JobType == JobTypeEnum.Weekly) { // calculate next date ServiceDateUTC = DateTimeWrapper.FindNextDateForDay((DayOfWeek)ServiceDay); } JobType = serviceType; ServiceGapMinutes = serviceGapMins; ServiceZone = serviceZone; }
private CleanerMatchResultVM PopulateCleanerAvailability(CleanerMatchResultVM item) { if (!criteria.FilterZonesNone && !ApplyZoneFilter(item)) { return(null); } item.DisplayHomeBase = String.IsNullOrWhiteSpace(item.PhysicalAddress.Suburb) ? "no booking" : item.PhysicalAddress.Suburb; // Style Formatting FormatStyleForHome(item); FormatStyleForWeekday(item); // All data loaded - calculate cleaner's current availability AvailabilityFactory factory = new AvailabilityFactory(item, criteria.ServiceLengthMins, JobType, SearchZoneList); try { item.ScheduledJobs = factory.GetCleanerDaySchedule(); item.TeamSize = factory.CleanerTeamSize; if (factory.SuitableTimeSlots == 0) { return(null); } if (JobType == JobTypeEnum.Fortnighly || JobType == JobTypeEnum.Weekly) { var leaveDates = AvailabilityFactory.GetCleanerLeaveDates(new Guid(item.Id), true).FirstOrDefault <CleanerLeaveVM>(); if (leaveDates != null) { item.CleanerOnLeave = ((DayOfWeek)criteria.ServiceDayValue).IsDayInRange(leaveDates.StartDate, leaveDates.EndDate); item.LeaveDates = DateTimeWrapper.FormatDateRange(leaveDates.StartDate, leaveDates.EndDate); } } } catch (NoTeamRosteredException nex) { LogHelper log = new LogHelper(); log.Log(LogHelper.LogLevels.Warning, $"Cleaner not rostered - but should not be checked", nameof(PopulateCleanerAvailability), nex, item, null); return(null); } catch (NoSuitableGapAvailable nex2) { item.CustomErrorMessage = nex2.Message; } catch { throw; } factory = null; return(item); }
/// <summary> /// Sets formatting style for day of the week based on even / odd wweeks /// </summary> /// <param name="cleaner">Cleaner.</param> private void FormatStyleForWeekday(CleanerMatchResultVM cleaner) { cleaner.StyleWeekday = ""; if (cleaner == null) { return; } if (criteria.OneOffJob || criteria.VacateClean) { cleaner.StyleWeekday = criteria.ServiceDate.WeekYearStyle(); } else { cleaner.StyleWeekday = DateTimeWrapper.FindNextDateForDay((DayOfWeek)criteria.ServiceDayValue).WeekYearStyle(); } return; }
internal static string DisplayCultureSettings(string seperator = "\n") { StringBuilder output = new StringBuilder(); DateTime _serverDateTime = DateTime.Now; Instant _nodeDateTime = DateTimeWrapper.NowInstance; output.Append($"FROM SERVER LOCATION:{seperator}"); output.Append($"Current server DateTime (DateTime.Now): {_serverDateTime.ToString()}{seperator}"); output.Append($"{seperator}"); output.Append($"UTC:{seperator}"); output.Append($"Current NodeTime UTC (DateTimeWrapper.Now): {_nodeDateTime.ToString()}{seperator}"); output.Append($"UTC for user's current date time (DateTimeWrapper.ToUTC: {_serverDateTime.ToUTC()}{seperator}"); output.Append($"{seperator}"); output.Append($"FROM USER LOCATION (BROWSER):{seperator}"); output.Append($"Current time at user location (DateTimeWrapper.DisplayLocalNow Method): {DateTimeWrapper.DisplayLocalNow()}{seperator}"); output.Append($"Current time at user location (DateTimeWrapper.ToUser Extension): {_nodeDateTime.ToDateTimeUtc().ToUser()}{seperator}"); output.Append($"{seperator}"); output.Append($"DATE ONLY - USER LOCATION:{seperator}"); output.Append($"Current date at user location (DateTimeWrapper.ToUserDate Method): {DateTimeWrapper.NowUtc.ToUser().Date}{seperator}"); output.Append($"Current date at UTC location (DateTimeWrapper.ToUtcDate Extension): {_nodeDateTime.ToDateTimeUtc().ToUTC().Date}{seperator}"); output.Append($"{seperator}"); output.Append($"FROM BROWSER:{seperator}"); output.Append($"User Country Code: {UserCountryCode()}{seperator}"); output.Append($"Default Time Zone: {DateTimeZoneProviders.Tzdb.GetSystemDefault().ToString()}{seperator}"); output.Append($"User Timezone Name (Browser): {UserTimeZoneName()}{seperator}"); output.Append($"User Timezone (Browser): {GetDateTimeZone().ToString()}{seperator}"); output.Append($"User Timezone Offset in minutes: {UserTimeZoneOffsetMins().ToString()}{seperator}"); output.Append($"{seperator}"); output.Append($"User Timezones (from Country Code):{seperator}{LogHelper.GetObjectData(GetTimeZonesByCountry())}{seperator}"); output.Append($"{seperator}"); //output.Append($"{seperator}"); //output.Append($"DEBUG:{seperator}"); //var _debug = _debugDetails.Replace("|", $"{seperator}"); //output.Append($"{_debug}"); //output.Append($"{seperator}"); return(output.ToString()); }