<commit_before>using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
using Newtonsoft.Json;
using notifier.Languages;
using notifier.Properties;

namespace notifier {
	class Scheduler {

		#region #attributes

		/// <summary>
		/// Day list using Monday as first day of week
		/// </summary>
		public readonly List<DayOfWeek> Days = Enum.GetValues(typeof(DayOfWeek)).Cast<DayOfWeek>().OrderBy(day => { return (day - DayOfWeek.Monday + 7) % 7; }).ToList();

		/// <summary>
		/// Time type possibilities
		/// </summary>
		public enum TimeType : uint {
			Start = 0,
			End = 1
		}

		/// <summary>
		/// List of slots for the scheduler
		/// </summary>
		private readonly List<TimeSlot> Slots;

		/// <summary>
		/// Reference to the main interface
		/// </summary>
		private readonly Main UI;

		#endregion

		#region #methods

		/// <summary>
		/// Class constructor
		/// </summary>
		/// <param name="form">Reference to the application main window</param>
		public Scheduler(ref Main form) {
			UI = form;

			// init the slots depending on the user settings
			Slots = Settings.Default.SchedulerTimeSlot != "" ? JsonConvert.DeserializeObject<List<TimeSlot>>(Settings.Default.SchedulerTimeSlot) : new List<TimeSlot>();

			// display the default day of week based on today
			UI.fieldDayOfWeek.SelectedIndex = Days.IndexOf(DateTime.Now.DayOfWeek);

			// display the start time and end time for today
			DisplayTimeSlotProperties(GetTimeSlot());
		}

		/// <summary>
		/// Display the time slot properties on the interface
		/// </summary>
		public void DisplayTimeSlotProperties(TimeSlot slot) {

			// if no time slot is defined, the synchronization will work all the day
			if (slot == null) {
				UI.fieldStartTime.SelectedIndex = 0;
				UI.fieldEndTime.SelectedIndex = 0;
				UI.labelDuration.Text = Translation.theday;

				return;
			}

			// if time slot of 0 hours is defined, the synchronization will be paused all the day
			if (slot.TotalHours == 0) {
				UI.fieldStartTime.SelectedIndex = 1;
				UI.fieldEndTime.SelectedIndex = 1;
				UI.labelDuration.Text = Translation.off;

				return;
			}

			// display the time slot properties
			UI.fieldStartTime.Text = slot.Start.ToString(@"h\:mm");
			UI.fieldEndTime.Text = slot.End.ToString(@"h\:mm");
			UI.labelDuration.Text = slot.TotalHours.ToString(CultureInfo.CurrentCulture) + " " + Translation.hours;
		}

		/// <summary>
		/// Update the scheduler properties depending on the type of time
		/// </summary>
		/// <param name="type">Type of time</param>
		public async Task Update(TimeType type) {

			// get the selected day of week
			DayOfWeek day = GetDayOfWeek(UI.fieldDayOfWeek.SelectedIndex);

			// check for the infinite or off time options
			bool durationInfinite = (type == TimeType.Start && UI.fieldStartTime.SelectedIndex == 0) || (type == TimeType.End && UI.fieldEndTime.SelectedIndex == 0);
			bool durationOff = (type == TimeType.Start && UI.fieldStartTime.SelectedIndex == 1) || (type == TimeType.End && UI.fieldEndTime.SelectedIndex == 1);

			// remove the time slot for the selected day
			if (durationInfinite || durationOff) {

				// remove the time slot from the scheduler
				if (durationInfinite) {

					// remove the time slot from the scheduler
					RemoveTimeSlot(day);

					// udpate the interface
					UI.fieldStartTime.SelectedIndex = 0;
					UI.fieldEndTime.SelectedIndex = 0;
					UI.labelDuration.Text = Translation.theday;
				} else {

					// set the time slot to 0 in the scheduler (mean no synchronization)
					SetTimeSlot(day, new TimeSpan(0, 0, 0), new TimeSpan(0, 0, 0));

					// udpate the interface
					UI.fieldStartTime.SelectedIndex = 1;
					UI.fieldEndTime.SelectedIndex = 1;
					UI.labelDuration.Text = Translation.off;
				}

				// synchronize the inbox if the selected day of week is today
				if (GetDayOfWeek(UI.fieldDayOfWeek.SelectedIndex) == DateTime.Now.DayOfWeek) {
					await UI.GmailService.Inbox.Sync();
				}

				return;
			}

			// update the end time depending on the start time
			if (type == TimeType.Start) {
				if (UI.fieldStartTime.SelectedIndex > UI.fieldEndTime.SelectedIndex || UI.fieldEndTime.SelectedIndex == 0) {
					UI.fieldEndTime.SelectedIndex = UI.fieldStartTime.SelectedIndex;
				}
			}

			// update the start time depending on the end time
			if (type == TimeType.End) {
				if (UI.fieldEndTime.SelectedIndex < UI.fieldStartTime.SelectedIndex || UI.fieldStartTime.SelectedIndex == 0) {
					UI.fieldStartTime.SelectedIndex = UI.fieldEndTime.SelectedIndex;
				}
			}

			// define the start and end time of the time slot
			TimeSpan start = TimeSpan.Parse(UI.fieldStartTime.Text);
			TimeSpan end = TimeSpan.Parse(UI.fieldEndTime.Text);

			// add or update the time slot
			TimeSlot slot = SetTimeSlot(day, start, end);

			// update the duration label
			UI.labelDuration.Text = slot.TotalHours.ToString(CultureInfo.CurrentCulture) + " " + Translation.hours;

			// synchronize the inbox if the selected day of week is today
			if (GetDayOfWeek(UI.fieldDayOfWeek.SelectedIndex) == DateTime.Now.DayOfWeek) {
				await UI.GmailService.Inbox.Sync();
			}
		}
<commit_msg>Fix independent start/end time selection<commit_after>using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
using Newtonsoft.Json;
using notifier.Languages;
using notifier.Properties;

namespace notifier {
	class Scheduler {

		#region #attributes

		/// <summary>
		/// Day list using Monday as first day of week
		/// </summary>
		public readonly List<DayOfWeek> Days = Enum.GetValues(typeof(DayOfWeek)).Cast<DayOfWeek>().OrderBy(day => { return (day - DayOfWeek.Monday + 7) % 7; }).ToList();

		/// <summary>
		/// Time type possibilities
		/// </summary>
		public enum TimeType : uint {
			Start = 0,
			End = 1
		}

		/// <summary>
		/// List of slots for the scheduler
		/// </summary>
		private readonly List<TimeSlot> Slots;

		/// <summary>
		/// Reference to the main interface
		/// </summary>
		private readonly Main UI;

		#endregion

		#region #methods

		/// <summary>
		/// Class constructor
		/// </summary>
		/// <param name="form">Reference to the application main window</param>
		public Scheduler(ref Main form) {
			UI = form;

			// init the slots depending on the user settings
			Slots = Settings.Default.SchedulerTimeSlot != "" ? JsonConvert.DeserializeObject<List<TimeSlot>>(Settings.Default.SchedulerTimeSlot) : new List<TimeSlot>();

			// display the default day of week based on today
			UI.fieldDayOfWeek.SelectedIndex = Days.IndexOf(DateTime.Now.DayOfWeek);

			// display the start time and end time for today
			DisplayTimeSlotProperties(GetTimeSlot());
		}

		/// <summary>
		/// Display the time slot properties on the interface
		/// </summary>
		public void DisplayTimeSlotProperties(TimeSlot slot) {

			// if no time slot is defined, the synchronization will work all the day
			if (slot == null) {
				UI.fieldStartTime.SelectedIndex = 0;
				UI.fieldEndTime.SelectedIndex = 0;
				UI.labelDuration.Text = Translation.theday;

				return;
			}

			// if time slot of 0 hours is defined, the synchronization will be paused all the day
			if (slot.TotalHours == 0) {
				UI.fieldStartTime.SelectedIndex = 1;
				UI.fieldEndTime.SelectedIndex = 1;
				UI.labelDuration.Text = Translation.off;

				return;
			}

			// display the time slot properties
			UI.fieldStartTime.Text = slot.Start.ToString(@"h\:mm");
			UI.fieldEndTime.Text = slot.End.ToString(@"h\:mm");
			UI.labelDuration.Text = slot.TotalHours.ToString(CultureInfo.CurrentCulture) + " " + Translation.hours;
		}

		/// <summary>
		/// Update the scheduler properties depending on the type of time
		/// </summary>
		/// <param name="type">Type of time</param>
		public async Task Update(TimeType type) {

			// get the selected day of week
			DayOfWeek day = GetDayOfWeek(UI.fieldDayOfWeek.SelectedIndex);

			// check for the infinite or off time options
			bool durationInfinite = (type == TimeType.Start && UI.fieldStartTime.SelectedIndex == 0) || (type == TimeType.End && UI.fieldEndTime.SelectedIndex == 0);
			bool durationOff = (type == TimeType.Start && UI.fieldStartTime.SelectedIndex == 1) || (type == TimeType.End && UI.fieldEndTime.SelectedIndex == 1);

			// remove the time slot for the selected day
			if (durationInfinite || durationOff) {

				// remove the time slot from the scheduler
				if (durationInfinite) {

					// remove the time slot from the scheduler
					RemoveTimeSlot(day);

					// udpate the interface
					UI.fieldStartTime.SelectedIndex = 0;
					UI.fieldEndTime.SelectedIndex = 0;
					UI.labelDuration.Text = Translation.theday;
				} else {

					// set the time slot to 0 in the scheduler (mean no synchronization)
					SetTimeSlot(day, new TimeSpan(0, 0, 0), new TimeSpan(0, 0, 0));

					// udpate the interface
					UI.fieldStartTime.SelectedIndex = 1;
					UI.fieldEndTime.SelectedIndex = 1;
					UI.labelDuration.Text = Translation.off;
				}

				// synchronize the inbox if the selected day of week is today
				if (GetDayOfWeek(UI.fieldDayOfWeek.SelectedIndex) == DateTime.Now.DayOfWeek) {
					await UI.GmailService.Inbox.Sync();
				}

				return;
			}

			// update the end time depending on the start time
			if (type == TimeType.Start) {
				if (UI.fieldStartTime.SelectedIndex > UI.fieldEndTime.SelectedIndex || UI.fieldEndTime.SelectedIndex == 0 || UI.fieldEndTime.SelectedIndex == 1) {
					UI.fieldEndTime.SelectedIndex = UI.fieldStartTime.SelectedIndex;
				}
			}

			// update the start time depending on the end time
			if (type == TimeType.End) {
				if (UI.fieldEndTime.SelectedIndex < UI.fieldStartTime.SelectedIndex || UI.fieldStartTime.SelectedIndex == 0 || UI.fieldStartTime.SelectedIndex == 1) {
					UI.fieldStartTime.SelectedIndex = UI.fieldEndTime.SelectedIndex;
				}
			}

			// define the start and end time of the time slot
			TimeSpan start = TimeSpan.Parse(UI.fieldStartTime.Text);
			TimeSpan end = TimeSpan.Parse(UI.fieldEndTime.Text);

			// add or update the time slot
			TimeSlot slot = SetTimeSlot(day, start, end);

			// update the duration label
			UI.labelDuration.Text = slot.TotalHours.ToString(CultureInfo.CurrentCulture) + " " + Translation.hours;

			// synchronize the inbox if the selected day of week is today
			if (GetDayOfWeek(UI.fieldDayOfWeek.SelectedIndex) == DateTime.Now.DayOfWeek) {
				await UI.GmailService.Inbox.Sync();
			}
		}

{'fraction_non_alphanumeric': 0.11628791480460207, 'fraction_numerical': 0.0053247123704478466, 'mean_word_length': 3.2072, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3170503', 'n_tokens_mistral': 3733, 'n_tokens_neox': 3096, 'n_words': 888}