/* PERIODS AND COMPLETION */

        public List <PeriodStruct> CreatePeriods(string[] periodText)
        {
            List <PeriodStruct> periods = new List <PeriodStruct>();

            for (int i = 1; i < periodText.Length; i++)
            {
                PeriodStruct  ps    = new PeriodStruct();
                List <string> lines = periodText[i].Split(new[] { '\r', '\n' }).ToList();
                for (int j = 0; j < lines.Count; j++)
                {
                    try
                    {
                        if (String.IsNullOrWhiteSpace(lines[j]))
                        {
                            lines.RemoveAt(j);
                        }
                    }
                    catch (Exception e)
                    {
                        System.Diagnostics.Debug.Write(e.Message);
                    }
                }
                ps.name       = identifyName(lines.ToArray());
                ps.room       = identifyRoom(lines.ToArray());
                ps.startTime  = identifyStart(lines.ToArray());
                ps.switchTime = ps.startTime;
                ps.switchTime.AddMinutes(5);
                ps.endTime = identifyEnd(lines.ToArray());
                periods.Add(ps);
            }

            periods.Sort((x, y) => DateTime.Compare(x.startTime, y.startTime));

            return(periods);
        }
        public Boolean checkTime(PeriodStruct period, TimeSpan endTime, TimeSpan current)
        {
            if (current >= period.switchTime.TimeOfDay && current <= endTime)
            {
                return(true);
            }

            return(false);
        }
        public void refreshIcon(CalendarDay day)
        {
            currentPeriod = initializePeriodStruct(day.date);
            string nl = System.Environment.NewLine;

            currentPeriod = getPeriodAtCurrentTime(day);

            trayIcon.Icon = GetIcon(currentPeriod.name, currentPeriod.room);
        }
        public PeriodStruct initializePeriodStruct(DateTime date)
        {
            PeriodStruct period = new PeriodStruct();

            period.name       = "None";
            period.room       = "";
            period.startTime  = date.Date;
            period.switchTime = period.startTime;
            period.endTime    = date.Date;
            period.endTime.AddHours(23);
            period.endTime.AddMinutes(59);
            period.endTime.AddSeconds(59);
            return(period);
        }
        public PeriodStruct getPeriodAtCurrentTime(CalendarDay day)
        {
            PeriodStruct current = initializePeriodStruct(day.date);

            for (int i = 0; i < day.periods.Count; i++)
            {
                DateTime endTime = day.periods[i].endTime;
                if (i < day.periods.Count - 1)
                {
                    endTime = day.periods[i + 1].switchTime;
                }

                if (checkTime(day.periods[i], endTime.TimeOfDay, System.DateTime.Now.TimeOfDay))
                {
                    if (i < day.periods.Count - 1)
                    {
                        current = day.periods[i + 1];
                    }
                    else
                    {
                        current = day.periods[i];
                    }
                }
            }

            if (current.name == "Nil")
            {
                if (System.DateTime.Now <= day.periods[0].startTime)
                {
                    current = day.periods[0];
                }
                else if (System.DateTime.Now >= day.periods[day.periods.Count - 1].endTime)
                {
                    current = day.periods[day.periods.Count - 1];
                }
            }

            return(current);
        }
        /* TIME */

        public Boolean checkDate(PeriodStruct period, DateTime current)
        {
            return(period.startTime.Date == current.Date);
        }