Exemplo n.º 1
0
        public void OnCellSelected(CalendarCell cell)
        {
            int index = cell.transform.GetSiblingIndex();

            int firstDay              = (int)new DateTime(m_Calendar.DateTime.Year, m_Calendar.DateTime.Month, 1).DayOfWeek;
            int numberOfDays          = DateTime.DaysInMonth(m_Calendar.DateTime.Year, m_Calendar.DateTime.Month);
            int numberOfDaysLastMonth = 0;

            if (m_Calendar.DateTime.Month == 1)
            {
                numberOfDaysLastMonth = DateTime.DaysInMonth(m_Calendar.DateTime.Year - 1, 12);
            }
            else
            {
                numberOfDaysLastMonth = DateTime.DaysInMonth(m_Calendar.DateTime.Year, m_Calendar.DateTime.Month - 1);
            }

            if (index < firstDay)
            {
                m_Calendar.DateTime = new DateTime(
                    m_Calendar.DateTime.AddMonths(-1).Year,
                    m_Calendar.DateTime.AddMonths(-1).Month,
                    numberOfDaysLastMonth - firstDay + index + 1,
                    m_Calendar.DateTime.AddMonths(-1).Hour,
                    m_Calendar.DateTime.AddMonths(-1).Minute,
                    m_Calendar.DateTime.AddMonths(-1).Second,
                    m_Calendar.DateTime.AddMonths(-1).Millisecond,
                    m_Calendar.DateTime.AddMonths(-1).Kind);
            }
            else if (index > firstDay + numberOfDays - 1)
            {
                m_Calendar.DateTime = new DateTime(
                    m_Calendar.DateTime.AddMonths(1).Year,
                    m_Calendar.DateTime.AddMonths(1).Month,
                    index - numberOfDays - firstDay + 1,
                    m_Calendar.DateTime.AddMonths(1).Hour,
                    m_Calendar.DateTime.AddMonths(1).Minute,
                    m_Calendar.DateTime.AddMonths(1).Second,
                    m_Calendar.DateTime.AddMonths(1).Millisecond,
                    m_Calendar.DateTime.AddMonths(1).Kind);
            }
            else
            {
                m_Calendar.DateTime = new DateTime(
                    m_Calendar.DateTime.Year,
                    m_Calendar.DateTime.Month,
                    index - firstDay + 1,
                    m_Calendar.DateTime.Hour,
                    m_Calendar.DateTime.Minute,
                    m_Calendar.DateTime.Second,
                    m_Calendar.DateTime.Millisecond,
                    m_Calendar.DateTime.Kind);
            }

            m_Calendar.OnDaySelected();
        }
Exemplo n.º 2
0
        public void OnCellSelected(CalendarCell cell)
        {
            m_Calendar.DateTime = new DateTime(
                int.Parse(cell.m_DayNumber.text),
                m_Calendar.DateTime.Month,
                Mathf.Clamp(m_Calendar.DateTime.Day, 1, DateTime.DaysInMonth(int.Parse(cell.m_DayNumber.text), m_Calendar.DateTime.Month)),
                m_Calendar.DateTime.Hour,
                m_Calendar.DateTime.Minute,
                m_Calendar.DateTime.Second,
                m_Calendar.DateTime.Millisecond,
                m_Calendar.DateTime.Kind);

            m_Calendar.OnYearSelected();
        }
        public void OnCellSelected(CalendarCell cell)
        {
            m_Calendar.DateTime = new DateTime(
                m_Calendar.DateTime.Year,
                cell.transform.GetSiblingIndex() + 1,
                Mathf.Clamp(m_Calendar.DateTime.Day, 1, DateTime.DaysInMonth(m_Calendar.DateTime.Year, cell.transform.GetSiblingIndex() + 1)),
                m_Calendar.DateTime.Hour,
                m_Calendar.DateTime.Minute,
                m_Calendar.DateTime.Second,
                m_Calendar.DateTime.Millisecond,
                m_Calendar.DateTime.Kind);

            m_Calendar.OnMonthSelected();
        }