private void DrawBarsForLocation(long originSeconds, Instant originInstant, Instant endInstant, Location location, int y) { LocalDateTime dt1 = originInstant.InZone(location.TimeZone).Date.AtMidnight(); LocalDateTime dt2 = endInstant.InZone(location.TimeZone).LocalDateTime; Debug.Assert(dt1 < dt2); if (dt1.DayOfWeekend(location.Country) == 2) { DrawBar(originSeconds, location, dt1, dt1.PlusDays(1), BarSize.Weekend, "Weekend;W", y); } for (LocalDateTime dt = dt1; dt < dt2; dt = dt.PlusDays(1)) { int dayOfWeekend = dt.DayOfWeekend(location.Country); if (dayOfWeekend == 1) { DrawBar(originSeconds, location, dt, dt.PlusDays(2), BarSize.Weekend, "Weekend;W", y); } if (dayOfWeekend == 1 || dayOfWeekend == 2) { continue; } EarlyClose?earlyClose = location.EarlyCloses.Where(x => x.DateTime.Date == dt.Date).SingleOrDefault(); Holiday? holiday = Holidays.TryGetHoliday(location.Country, location.Region, dt.Date); if (holiday is not null && earlyClose is null) { DrawBar(originSeconds, location, dt, dt.PlusDays(1), BarSize.Holiday, "Holiday: " + holiday.Name + ";Holiday;H", y); continue; } foreach (Bar bar in location.Bars) { LocalDateTime start = dt.Date + bar.Start; LocalDateTime end = dt.Date + bar.End; if (earlyClose is not null) { if (earlyClose.DateTime.TimeOfDay <= bar.Start) { continue; } if (earlyClose.DateTime.TimeOfDay < bar.End) { end = earlyClose.DateTime; } } string label = bar.Label; if (string.IsNullOrEmpty(label)) { label = location.Name + " TIME"; } if (label.Contains("TIME")) { label = label.Replace("TIME", Clock.GetCurrentInstant().InZone(location.TimeZone).ToString("H:mm", null)); } DrawBar(originSeconds, location, start, end, bar.BarSize, label, y); } } }
public static bool IsWeekend(this LocalDateTime dt, string country) => dt.DayOfWeekend(country) != 0;