コード例 #1
0
        /// <summary>
        /// Gets the appointment collection
        /// </summary>
        /// <returns>Appointment collection</returns>
        internal ObservableCollection <Meeting> GetAppointments()
        {
            NSDate     today    = new NSDate();
            NSCalendar calendar = NSCalendar.CurrentCalendar;

            appointmentCollection = new ObservableCollection <Meeting>();
            SetEventCollection();
            RandomNumbers();
            SetFromCollection();
            SetToCollection();
            SetColorCollection();

            for (int i = 0; i < 15; i++)
            {
                meeting           = new Meeting();
                meeting.Color     = colorCollection[i];
                meeting.EventName = (NSString)eventCollection[i];
                meeting.From      = fromCollection[i];

                // To create all day appointments
                if (i % 6 == 0 && i != 0)
                {
                    meeting.IsAllDay = true;
                }

                // To create two days span appointment
                if (i % 5 == 0 && i != 0)
                {
                    toCollection[i] = fromCollection[i];
                    var dateComponent = calendar.Components(NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day | NSCalendarUnit.Hour | NSCalendarUnit.Minute | NSCalendarUnit.Second, toCollection[i]);
                    dateComponent.Day = dateComponent.Day + 2;
                    toCollection[i]   = calendar.DateFromComponents(dateComponent);
                }

                // To create 24 hour span appointments
                if (i % 7 == 0)
                {
                    toCollection[i] = fromCollection[i];
                    var dateComponent = calendar.Components(NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day | NSCalendarUnit.Hour | NSCalendarUnit.Minute | NSCalendarUnit.Second, toCollection[i]);
                    dateComponent.Hour   = dateComponent.Hour + 23;
                    dateComponent.Minute = dateComponent.Minute + 59;
                    toCollection[i]      = calendar.DateFromComponents(dateComponent);
                }

                // To create minimum height appointments
                if (eventCollection[i].Contains("alert"))
                {
                    toCollection[i]       = fromCollection[i];
                    meeting.MinimumHeight = 20;
                }

                meeting.To = toCollection[i];
                appointmentCollection.Add(meeting);
            }

            return(appointmentCollection);
        }
コード例 #2
0
        private ObservableCollection <ScheduleAppointment> CreateAppointments()
        {
            NSDate     today    = new NSDate();
            NSCalendar calendar = NSCalendar.CurrentCalendar;
            // Get the year, month, day from the date
            NSDateComponents components = calendar.Components(
                NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, today);

            // Set the hour, minute, second
            components.Hour   = 10;
            components.Minute = 0;
            components.Second = 0;
            NSDate startDate = calendar.DateFromComponents(components);
            // Get the year, month, day from the date
            NSDateComponents endDateComponents = calendar.Components(NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, today);

            // Set the hour, minute, second
            endDateComponents.Hour   = 12;
            endDateComponents.Minute = 0;
            endDateComponents.Second = 0;
            NSDate endDate = calendar.DateFromComponents(endDateComponents);
            ScheduleAppointment appointment = new ScheduleAppointment();

            appointment.StartTime             = startDate;
            appointment.EndTime               = endDate;
            appointment.Subject               = new NSString("Jeni's B'Day Celebration");
            appointment.AppointmentBackground = UIColor.FromRGB(0xA2, 0xC1, 0x39);
            NSDateComponents components1 = calendar.Components(NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, today);

            // Set the hour, minute, second
            components1.Hour   = 11;
            components1.Minute = 0;
            components1.Second = 0;
            components1.Day    = components1.Day + 1;
            NSDate startDate1 = calendar.DateFromComponents(components1);
            // Get the year, month, day from the date
            NSDateComponents endDateComponents1 = calendar.Components(NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, today);

            // Set the hour, minute, second
            endDateComponents1.Hour   = 13;
            endDateComponents1.Minute = 30;
            endDateComponents1.Second = 0;
            endDateComponents1.Day    = endDateComponents1.Day + 1;
            NSDate endDate1 = calendar.DateFromComponents(endDateComponents1);
            ScheduleAppointment appointment1 = new ScheduleAppointment();

            appointment1.StartTime             = startDate1;
            appointment1.EndTime               = endDate1;
            appointment1.Subject               = new NSString("Checkup");
            appointment1.AppointmentBackground = UIColor.FromRGB(0xD8, 0x00, 0x73);
            ObservableCollection <ScheduleAppointment> appCollection = new ObservableCollection <ScheduleAppointment>();

            appCollection.Add(appointment);
            appCollection.Add(appointment1);
            return(appCollection);
        }
コード例 #3
0
ファイル: DragDrop.cs プロジェクト: wukimus/xamarin-demos
        /// <summary>
        /// create appointments.
        /// </summary>
        /// <returns></returns>
        private IEnumerable <ScheduleAppointment> CreateAppointments()
        {
            NSDate today = new NSDate();

            SetColors();
            SetSubjects();
            List <ScheduleAppointment> appCollection = new List <ScheduleAppointment>();
            NSCalendar calendar = NSCalendar.CurrentCalendar;

            // Get the year, month, day from the date
            NSDateComponents components = calendar.Components(
                NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, today);

            // Set the hour, minute, second
            components.Hour   = 10;
            components.Minute = 0;
            components.Second = 0;

            // Get the year, month, day from the date
            NSDateComponents endDateComponents = calendar.Components(NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, today);

            // Set the hour, minute, second
            endDateComponents.Hour   = 12;
            endDateComponents.Minute = 0;
            endDateComponents.Second = 0;
            Random randomNumber = new Random();

            for (int i = 0; i < 10; i++)
            {
                components.Hour        = randomNumber.Next(10, 16);
                endDateComponents.Hour = components.Hour + randomNumber.Next(1, 1);
                NSDate startDate = calendar.DateFromComponents(components);
                NSDate endDate   = calendar.DateFromComponents(endDateComponents);
                ScheduleAppointment appointment = new ScheduleAppointment();
                appointment.StartTime             = startDate;
                appointment.EndTime               = endDate;
                components.Day                    = components.Day + 1;
                endDateComponents.Day             = endDateComponents.Day + 1;
                appointment.Subject               = (NSString)subjectCollection[i];
                appointment.AppointmentBackground = colorCollection[i];
                if (i == 10 || i == 7)
                {
                    appointment.IsAllDay = true;
                }

                appCollection.Add(appointment);
            }

            return(appCollection);
        }
コード例 #4
0
        private NSDate GetDate(NSDate visibleDate, NSDate startTimeDate)
        {
            NSCalendar       calendar             = NSCalendar.CurrentCalendar;
            NSDate           today1               = new NSDate();
            NSDateComponents visibleDateCompoents = calendar.Components(
                NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, visibleDate);
            NSDateComponents startDateCompoents = calendar.Components(
                NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day | NSCalendarUnit.Hour | NSCalendarUnit.Minute | NSCalendarUnit.Second, startTimeDate);

            visibleDateCompoents.Hour   = startDateCompoents.Hour;
            visibleDateCompoents.Minute = startDateCompoents.Minute;
            visibleDateCompoents.Second = startDateCompoents.Second;
            return(calendar.DateFromComponents(visibleDateCompoents));
        }
コード例 #5
0
        public void DateComponentsTest()
        {
            var cal = new NSCalendar(NSCalendarType.Gregorian);
            var now = DateTime.Now.ToUniversalTime();
            NSDateComponents comps;

            comps = cal.Components(NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, (NSDate)now);
            Assert.AreEqual(now.Year, comps.Year, "a year");
            Assert.AreEqual(now.Month, comps.Month, "a month");
            Assert.AreEqual(now.Day, comps.Day, "a day");

            comps = cal.Components(NSCalendarUnit.Hour, (NSDate)now.AddHours(-1), (NSDate)now, NSDateComponentsWrappingBehavior.None);
            Assert.AreEqual(1, comps.Hour, "b hour");
        }
コード例 #6
0
        private void EditorView_TouchUpInside(object sender, EventArgs e)
        {
            ScheduleEditor.Editor.Hidden = false;
            Schedule.Hidden   = true;
            HeaderView.Hidden = true;
            TableView.Hidden  = true;

            NSDate     today    = new NSDate();
            NSCalendar calendar = NSCalendar.CurrentCalendar;

            // Get the year, month, day from the date
            NSDateComponents components = calendar.Components(
                NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, today);
            NSDate startDate = calendar.DateFromComponents(components);

            ScheduleEditor.LabelSubject.Text  = "Subject";
            ScheduleEditor.LabelLocation.Text = "Location";
            String startDate1 = DateTime.Parse(startDate.ToString()).ToString();

            ScheduleEditor.PickerStartDate.SetDate(startDate, true);
            ScheduleEditor.ButtonStartDate.SetTitle(startDate1, UIControlState.Normal);
            String endDate = DateTime.Parse(startDate.AddSeconds(3600).ToString()).ToString();

            ScheduleEditor.PickerEndDate.SetDate(startDate.AddSeconds(3600), true);
            ScheduleEditor.ButtonEndDate.SetTitle(endDate, UIControlState.Normal);
        }
コード例 #7
0
        private void SetMonthSettings()
        {
            monthSettings = new MonthViewSettings();

            NSDate     today    = new NSDate();
            NSCalendar calendar = NSCalendar.CurrentCalendar;

            // Get the year, month, day from the date
            NSDateComponents components = calendar.Components(
                NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, today);

            // Set the hour, minute, second
            schedule.MonthViewSettings  = monthSettings;
            monthSettings.BlackoutDates = new NSMutableArray();
            if (switchBlackOutDates != null && switchBlackOutDates.On)
            {
                components.Day -= 3;
                for (int i = 0; i < 3; i++)
                {
                    NSDate startDate = calendar.DateFromComponents(components);
                    components.Day += 1;
                    schedule.MonthViewSettings.BlackoutDates.Add(startDate);
                }
            }

            if (switchWeekNumber != null && switchWeekNumber.On)
            {
                schedule.MonthViewSettings.ShowWeekNumber = true;
            }
            else
            {
                schedule.MonthViewSettings.ShowWeekNumber = false;
            }
        }
コード例 #8
0
        private void EditorView_TouchUpInside(object sender, EventArgs e)
        {
            scheduleEditor.Editor.Hidden = false;
            schedule.Hidden   = true;
            headerView.Hidden = true;
            tableView.Hidden  = true;

            NSDate     today    = new NSDate();
            NSCalendar calendar = NSCalendar.CurrentCalendar;
            // Get the year, month, day from the date
            NSDateComponents components = calendar.Components(
                NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, today);
            NSDate startDate = calendar.DateFromComponents(components);

            scheduleEditor.label_subject.Text  = "Subject";
            scheduleEditor.label_location.Text = "Location";
            String _sDate = DateTime.Parse((startDate.ToString())).ToString();

            scheduleEditor.picker_startDate.SetDate(startDate, true);
            scheduleEditor.button_startDate.SetTitle(_sDate, UIControlState.Normal);
            String _eDate = DateTime.Parse((startDate.AddSeconds(3600).ToString())).ToString();

            scheduleEditor.picker_endDate.SetDate(startDate.AddSeconds(3600), true);
            scheduleEditor.button_endDate.SetTitle(_eDate, UIControlState.Normal);
        }
コード例 #9
0
        public CalendarBlackoutDates()
        {
            //Calendar
            calendar1              = new SFCalendar();
            calendar1.ViewMode     = SFCalendarViewMode.SFCalendarViewModeMonth;
            calendar1.HeaderHeight = 40;
            this.AddSubview(calendar1);

            //Setting BlackOutDates
            NSDate     today    = new NSDate();
            NSCalendar calendar = NSCalendar.CurrentCalendar;
            // Get the year, month, day from the date
            NSDateComponents components = calendar.Components(
                NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, today);

            // Set the hour, minute, second

            calendar1.BlackoutDates = new NSMutableArray();

            for (int i = 0; i < 5; i++)
            {
                NSDate startDate = calendar.DateFromComponents(components);
                components.Day += 1;
                calendar1.BlackoutDates.Add(startDate);
            }

            appView = new UITableView();
            appView.RegisterClassForCellReuse(typeof(UITableViewCell), "Cell");
            if ((UIDevice.CurrentDevice).UserInterfaceIdiom == UIUserInterfaceIdiom.Pad)
            {
                calendarView.AddSubview(calendar1);
                this.AddSubview(calendarView);
            }
            this.AddSubview(appView);
        }
コード例 #10
0
        public static int _getDayOfWeekWithDate(NSDate date)
        {
            var gregorian         = new NSCalendar(NSCalendarType.Gregorian);
            var weekDayComponents = gregorian.Components(NSCalendarUnit.Weekday, date);

            return((int)weekDayComponents.Weekday);
        }
コード例 #11
0
        public static DateTime NSDateToDateTime(NSDate date)
        {
            var calendar   = new NSCalendar(NSCalendarType.Gregorian);
            var components = calendar.Components(NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day | NSCalendarUnit.Hour | NSCalendarUnit.Minute | NSCalendarUnit.Second, date);

            return(new DateTime((int)components.Year, (int)components.Month, (int)components.Day, (int)components.Hour, (int)components.Minute, (int)components.Second));
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            this.CurrentFrame = new CGRect(0, 0, UIScreen.MainScreen.Bounds.Size.Width, UIScreen.MainScreen.Bounds.Size.Height);
            this.AddButton();
            //Creating an instance for SfSchedule control
            SFSchedule schedule = new SFSchedule();

            schedule.Frame        = new CGRect(0, removeExceptionAppointment.Frame.Bottom, this.CurrentFrame.Size.Width, this.CurrentFrame.Size.Height - removeExceptionAppointment.Frame.Bottom);
            schedule.ScheduleView = SFScheduleView.SFScheduleViewWeek;

            NSCalendar calendar = new NSCalendar(NSCalendarType.Gregorian);
            NSDate     today    = NSDate.Now;
            // Get the year, month, day from the date
            NSDateComponents startDateComponents = calendar.Components(NSCalendarUnit.Year |
                                                                       NSCalendarUnit.Month |
                                                                       NSCalendarUnit.Day, today);

            // Set the year, month, day, hour, minute, second
            startDateComponents.Year   = 2017;
            startDateComponents.Month  = 09;
            startDateComponents.Day    = 03;
            startDateComponents.Hour   = 10;
            startDateComponents.Minute = 0;
            startDateComponents.Second = 0;

            //setting start time for the event
            NSDate startDate = calendar.DateFromComponents(startDateComponents);

            //setting end time for the event
            NSDate endDate = startDate.AddSeconds(2 * 60 * 60);

            // set moveto date to schedule
            schedule.MoveToDate(startDate);

            // Set the exception dates.
            var exceptionDate1 = startDate;
            var exceptionDate2 = startDate.AddSeconds(2 * 24 * 60 * 60);

            exceptionDate3 = startDate.AddSeconds(4 * 24 * 60 * 60);

            // Add Schedule appointment
            ScheduleAppointment recurrenceAppointment = new ScheduleAppointment();

            recurrenceAppointment.Id                       = 1;
            recurrenceAppointment.StartTime                = startDate;
            recurrenceAppointment.EndTime                  = endDate;
            recurrenceAppointment.Subject                  = (NSString)"Occurs Daily";
            recurrenceAppointment.AppointmentBackground    = UIColor.Blue;
            recurrenceAppointment.RecurrenceRule           = (NSString)"FREQ=DAILY;COUNT=20";
            recurrenceAppointment.RecurrenceExceptionDates = new System.Collections.ObjectModel.ObservableCollection <NSDate> {
                exceptionDate1,
                exceptionDate2,
                exceptionDate3
            };

            scheduleAppointmentCollection.Add(recurrenceAppointment);
            schedule.ItemsSource = scheduleAppointmentCollection;
            this.View.AddSubview(schedule);
        }
コード例 #13
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
// >> getting-started-calendar-cs
            TKCalendar calendarView = new TKCalendar(this.View.Bounds);

            calendarView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
            this.View.AddSubview(calendarView);
// << getting-started-calendar-cs

            calendarDelegate = new CalendarDelegate();

// >> getting-started-assigndatasource-cs
            calendarView.DataSource = new CalendarDataSource(this);
// << getting-started-assigndatasource-cs

// >> getting-started-event-cs
            events = new List <TKCalendarEvent> ();
            NSCalendar calendar = new NSCalendar(NSCalendarType.Gregorian);
            NSDate     date     = NSDate.Now;

            Random r = new Random();

            for (int i = 0; i < 3; i++)
            {
                TKCalendarEvent ev = new TKCalendarEvent();
                ev.Title = "Sample event";
                NSDateComponents components = calendar.Components(NSCalendarUnit.Day | NSCalendarUnit.Month | NSCalendarUnit.Year, date);
                components.Day = r.Next() % 20;
                ev.StartDate   = calendar.DateFromComponents(components);
                ev.EndDate     = calendar.DateFromComponents(components);
                ev.EventColor  = UIColor.Red;
                events.Add(ev);
            }
// << getting-started-event-cs

// >> getting-started-minmaxdate-cs
            calendarView.MinDate = TKCalendar.DateWithYear(2010, 1, 1, calendar);
            calendarView.MaxDate = TKCalendar.DateWithYear(2016, 12, 31, calendar);
// << getting-started-minmaxdate-cs

//			calendarDelegate.events = this.events;
            calendarView.Delegate = calendarDelegate;

// >> getting-started-navigatetodate-cs
            NSDateComponents newComponents = new NSDateComponents();

            newComponents.Year  = 2015;
            newComponents.Month = 5;
            newComponents.Day   = 1;
            NSDate newDate = calendarView.Calendar.DateFromComponents(newComponents);

// >> navigation-navigate-cs
            calendarView.NavigateToDate(newDate, true);
// << navigation-navigate-cs
// << getting-started-navigatetodate-cs

            calendarView.ReloadData();
        }
コード例 #14
0
        private int GetEndDateHour(NSDate endTimeDate)
        {
            NSCalendar       calendar          = NSCalendar.CurrentCalendar;
            NSDateComponents endDateComponents = calendar.Components(
                NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day | NSCalendarUnit.Hour | NSCalendarUnit.Minute | NSCalendarUnit.Second, endTimeDate);

            return((int)endDateComponents.Hour);
        }
コード例 #15
0
        public static DateTime ToDateTimeUTC(this NSDate nsdate)
        {
            NSCalendar calendar = NSCalendar.CurrentCalendar;
            var        date     = calendar.Components(NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day | NSCalendarUnit.Hour | NSCalendarUnit.Minute | NSCalendarUnit.Second, nsdate);

            date.TimeZone = NSTimeZone.FromName(@"UTC");
            return(new DateTime((int)date.Year, (int)date.Month, (int)date.Day, (int)date.Hour, (int)date.Minute, (int)date.Second, DateTimeKind.Utc));
        }
コード例 #16
0
        private int GetStartDateHour(NSDate startTimeDate)
        {
            NSCalendar       calendar           = NSCalendar.CurrentCalendar;
            NSDateComponents startDateCompoents = calendar.Components(
                NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day | NSCalendarUnit.Hour | NSCalendarUnit.Minute | NSCalendarUnit.Second, startTimeDate);

            return((int)startDateCompoents.Hour);
        }
コード例 #17
0
        public void DateComponentsTest()
        {
            var cal = new NSCalendar(NSCalendarType.Gregorian);
            var now = DateTime.UtcNow;
            NSDateComponents comps;

            cal.TimeZone = NSTimeZone.FromName("UTC");
            comps        = cal.Components(NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, (NSDate)now);
            Assert.AreEqual((nint)now.Year, comps.Year, "a year");
            Assert.AreEqual((nint)now.Month, comps.Month, "a month");
            Assert.AreEqual((nint)now.Day, comps.Day, "a day");

            var dayCompare = now;

            comps = cal.Components(NSCalendarUnit.Hour, (NSDate)dayCompare.AddHours(-1), (NSDate)dayCompare, NSDateComponentsWrappingBehavior.None);
            Assert.AreEqual((nint)1, comps.Hour, "b hour");
        }
コード例 #18
0
        private ObservableCollection <ScheduleAppointment> GetChineseAppointments()
        {
            NSDate today = new NSDate();

            viewModel.SetColors();
            viewModel.SetChineseCollectionSubjects();
            ObservableCollection <ScheduleAppointment> appCollection = new ObservableCollection <ScheduleAppointment>();
            NSCalendar calendar = NSCalendar.CurrentCalendar;

            // Get the year, month, day from the date
            NSDateComponents components = calendar.Components(
                NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, today);

            // Set the hour, minute, second
            components.Hour   = 10;
            components.Minute = 0;
            components.Second = 0;

            // Get the year, month, day from the date
            NSDateComponents endDateComponents = calendar.Components(NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, today);

            // Set the hour, minute, second
            endDateComponents.Hour   = 12;
            endDateComponents.Minute = 0;
            endDateComponents.Second = 0;
            Random randomNumber = new Random();

            for (int i = 0; i < 10; i++)
            {
                components.Hour        = randomNumber.Next(10, 16);
                endDateComponents.Hour = components.Hour + randomNumber.Next(1, 3);
                NSDate startDate = calendar.DateFromComponents(components);
                NSDate endDate   = calendar.DateFromComponents(endDateComponents);
                ScheduleAppointment appointment = new ScheduleAppointment();
                appointment.StartTime             = startDate;
                appointment.EndTime               = endDate;
                components.Day                    = components.Day + 1;
                endDateComponents.Day             = endDateComponents.Day + 1;
                appointment.Subject               = (NSString)viewModel.ChineseCollection[i];
                appointment.AppointmentBackground = viewModel.ColorCollection[i];

                appCollection.Add(appointment);
            }

            return(appCollection);
        }
コード例 #19
0
        private int GetDayOfWeek(NSDate visibleDate)
        {
            NSCalendar       calendar             = NSCalendar.CurrentCalendar;
            NSDate           today1               = new NSDate();
            NSDateComponents visibleDateCompoents = calendar.Components(
                NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day | NSCalendarUnit.Weekday, visibleDate);

            return((int)visibleDateCompoents.Weekday);
        }
コード例 #20
0
        private void PrevMonthBtnClicked(object sender, EventArgs args)
        {
            NSCalendar       cal   = NSCalendar.CurrentCalendar;
            NSDateComponents comps = cal.Components(NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, _calendar.CurrentDate);

            comps.Month          -= 1;
            _calendar.CurrentDate = cal.DateFromComponents(comps);
            UpdateMonthTitle();
        }
コード例 #21
0
        NSMutableArray getEnglishAppointments()
        {
            NSDate today = new NSDate();

            setColors();
            setEnglishCollectionSubjects();
            NSMutableArray appCollection = new NSMutableArray();
            NSCalendar     calendar      = NSCalendar.CurrentCalendar;
            // Get the year, month, day from the date
            NSDateComponents components = calendar.Components(
                NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, today);

            // Set the hour, minute, second
            components.Hour   = 10;
            components.Minute = 0;
            components.Second = 0;

            // Get the year, month, day from the date
            NSDateComponents endDateComponents = calendar.Components(NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, today);

            // Set the hour, minute, second
            endDateComponents.Hour   = 12;
            endDateComponents.Minute = 0;
            endDateComponents.Second = 0;
            Random randomNumber = new Random();

            for (int i = 0; i < 10; i++)
            {
                components.Hour        = randomNumber.Next(10, 16);
                endDateComponents.Hour = components.Hour + randomNumber.Next(1, 3);
                NSDate        startDate   = calendar.DateFromComponents(components);
                NSDate        endDate     = calendar.DateFromComponents(endDateComponents);
                SFAppointment appointment = new SFAppointment();
                appointment.StartTime             = startDate;
                appointment.EndTime               = endDate;
                components.Day                    = components.Day + 1;
                endDateComponents.Day             = endDateComponents.Day + 1;
                appointment.Subject               = (NSString)englishCollection[i];
                appointment.AppointmentBackground = colorCollection[i];
                appCollection.Add(appointment);
            }
            return(appCollection);
        }
コード例 #22
0
        public int _getDayOfWeek()
        {
            var timeStamp = DateTime.Now.GetUnixEpoch();

            var date      = NSDate.FromTimeIntervalSinceReferenceDate(timeStamp);
            var gregorian = new NSCalendar(NSCalendarType.Gregorian);

            var weekDayComponents = gregorian.Components(NSCalendarUnit.Weekday, date);

            return((int)weekDayComponents.Weekday);
        }
コード例 #23
0
        private void Schedule_AppointmentsForDate(object sender, AppointmentsForDateEventArgs e)
        {
            NSCalendar       calendar   = NSCalendar.CurrentCalendar;
            NSDateComponents components = calendar.Components(NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, (NSDate)e.Date);

            components.Hour   = 23;
            components.Minute = 59;
            components.Second = 59;
            NSDate      rangeEndDateWithTime = calendar.DateFromComponents(components);
            NSPredicate predicate            = NSPredicate.FromFormat(@"(startTime <= %@) AND (startTime >= %@)", rangeEndDateWithTime, (NSDate)e.Date);
        }
コード例 #24
0
        private NSDate GetBreakDate(NSDate visibleDate, int hour, int mins, int secs)
        {
            NSCalendar       calendar             = NSCalendar.CurrentCalendar;
            NSDate           today1               = new NSDate();
            NSDateComponents visibleDateCompoents = calendar.Components(
                NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, visibleDate);

            visibleDateCompoents.Hour   = hour;
            visibleDateCompoents.Minute = mins;
            visibleDateCompoents.Second = secs;
            return(calendar.DateFromComponents(visibleDateCompoents));
        }
コード例 #25
0
        private void MoveToDate_TouchUpInside(object sender, EventArgs e)
        {
            tableView.Hidden = true;
            NSDate     today    = new NSDate();
            NSCalendar calendar = NSCalendar.CurrentCalendar;
            // Get the year, month, day from the date
            NSDateComponents components = calendar.Components(
                NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, today);
            NSDate startDate = calendar.DateFromComponents(components);

            schedule.MoveToDate(startDate);
        }
コード例 #26
0
        public static MotionActivityQuery FromDate(NSDate date, int offset)
        {
            NSCalendar       currentCalendar = NSCalendar.CurrentCalendar;
            NSDateComponents timeComponents  = currentCalendar.Components(
                NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, date);

            timeComponents.Hour = 0;
            timeComponents.Day  = timeComponents.Day + offset;

            NSDate queryStart = currentCalendar.DateFromComponents(timeComponents);

            timeComponents.Day = timeComponents.Day + 1;
            NSDate queryEnd = currentCalendar.DateFromComponents(timeComponents);

            return(new MotionActivityQuery(queryStart, queryEnd, offset == 0));
        }
コード例 #27
0
        private void SetEndTime()
        {
            endTimeCollection = new List <NSDate>();

            NSCalendar       calendar          = NSCalendar.CurrentCalendar;
            NSDate           today             = new NSDate();
            NSDateComponents endDateComponents = calendar.Components(
                NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, today);

            endDateComponents.Hour   = 10;
            endDateComponents.Minute = 0;
            endDateComponents.Second = 0;

            NSDateComponents endDateComponents1 = calendar.Components(
                NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, today);

            endDateComponents1.Hour   = 11;
            endDateComponents1.Minute = 0;
            endDateComponents1.Second = 0;

            NSDateComponents endDateComponents2 = calendar.Components(
                NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, today);

            endDateComponents2.Hour   = 12;
            endDateComponents2.Minute = 0;
            endDateComponents2.Second = 0;

            NSDateComponents endDateComponents3 = calendar.Components(
                NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, today);

            endDateComponents3.Hour   = 14;
            endDateComponents3.Minute = 0;
            endDateComponents3.Second = 0;

            NSDateComponents endDateComponents4 = calendar.Components(
                NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, today);

            endDateComponents4.Hour   = 15;
            endDateComponents4.Minute = 0;
            endDateComponents4.Second = 0;

            NSDateComponents endDateComponents5 = calendar.Components(
                NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, today);

            endDateComponents5.Hour   = 16;
            endDateComponents5.Minute = 0;
            endDateComponents5.Second = 0;

            endTimeCollection.Add(calendar.DateFromComponents(endDateComponents));
            endTimeCollection.Add(calendar.DateFromComponents(endDateComponents1));
            endTimeCollection.Add(calendar.DateFromComponents(endDateComponents2));
            endTimeCollection.Add(calendar.DateFromComponents(endDateComponents3));
            endTimeCollection.Add(calendar.DateFromComponents(endDateComponents4));
            endTimeCollection.Add(calendar.DateFromComponents(endDateComponents5));
        }
コード例 #28
0
        private void SetStartTime()
        {
            startTimeCollection = new List <NSDate>();
            NSCalendar       calendar            = NSCalendar.CurrentCalendar;
            NSDate           today               = new NSDate();
            NSDateComponents startDateComponents = calendar.Components(
                NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, today);

            startDateComponents.Hour   = 9;
            startDateComponents.Minute = 1;
            startDateComponents.Second = 0;

            NSDateComponents startDateComponents1 = calendar.Components(
                NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, today);

            startDateComponents1.Hour   = 10;
            startDateComponents1.Minute = 1;
            startDateComponents1.Second = 0;

            NSDateComponents startDateComponents2 = calendar.Components(
                NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, today);

            startDateComponents2.Hour   = 11;
            startDateComponents2.Minute = 11;
            startDateComponents2.Second = 0;

            NSDateComponents startDateComponents3 = calendar.Components(
                NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, today);

            startDateComponents3.Hour   = 13;
            startDateComponents3.Minute = 1;
            startDateComponents3.Second = 0;

            NSDateComponents startDateComponents4 = calendar.Components(
                NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, today);

            startDateComponents4.Hour   = 14;
            startDateComponents4.Minute = 1;
            startDateComponents4.Second = 0;

            NSDateComponents startDateComponents5 = calendar.Components(
                NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, today);

            startDateComponents5.Hour   = 15;
            startDateComponents5.Minute = 11;
            startDateComponents5.Second = 0;

            startTimeCollection.Add(calendar.DateFromComponents(startDateComponents));
            startTimeCollection.Add(calendar.DateFromComponents(startDateComponents1));
            startTimeCollection.Add(calendar.DateFromComponents(startDateComponents2));
            startTimeCollection.Add(calendar.DateFromComponents(startDateComponents3));
            startTimeCollection.Add(calendar.DateFromComponents(startDateComponents4));
            startTimeCollection.Add(calendar.DateFromComponents(startDateComponents5));
        }
コード例 #29
0
        /// <summary>
        /// check the appointment with in non accessible block region.
        /// </summary>
        /// <param name="dropTime"></param>
        /// <returns></returns>
        private bool IsInNonAccessRegion(NSDate dropTime)
        {
            NSCalendar       calendar = NSCalendar.CurrentCalendar;
            NSDateComponents start    = calendar.Components(NSCalendarUnit.Year |
                                                            NSCalendarUnit.Month |
                                                            NSCalendarUnit.Day |
                                                            NSCalendarUnit.Hour |
                                                            NSCalendarUnit.Minute |
                                                            NSCalendarUnit.Second, dropTime);

            if (schedule.WeekViewSettings.NonAccessibleBlockCollection.GetItem <NonAccessibleBlock>(0).StartHour == start.Hour ||
                schedule.WeekViewSettings.NonAccessibleBlockCollection.GetItem <NonAccessibleBlock>(0).StartHour - 1 == start.Hour && start.Minute > 0)
            {
                return(true);
            }
            return(false);
        }
コード例 #30
0
        private void UpdateMonthTitle()
        {
            NSDateFormatter dateFormatter = new NSDateFormatter();

            dateFormatter.DateFormat = "MMMM";
            lblCurrentMonth.Text     = dateFormatter.ToString(_calendar.CurrentDate);

            NSCalendar       cal   = NSCalendar.CurrentCalendar;
            NSDateComponents comps = cal.Components(NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, _calendar.CurrentDate);

            comps.Month += 1;
            var nextMonth = cal.DateFromComponents(comps);

            btnNextMonth.SetTitle(dateFormatter.ToString(nextMonth) + " >", UIControlState.Normal);
            comps.Month -= 2;
            var prevMonth = cal.DateFromComponents(comps);

            btnPrevMonth.SetTitle("< " + dateFormatter.ToString(prevMonth), UIControlState.Normal);
        }