Ejemplo n.º 1
0
        private void UpdateDaysState(OrgEvent orgEvent)
        {
            if (orgEvent == null
                ||
                (!orgEvent.StartTime.HasValue ||
                 !orgEvent.EndTime.HasValue)
                ||
                (orgEvent.StartTime.Value.Date ==
                 orgEvent.EndTime.Value.Date))
            {
                DaysCount  = 0;
                CurrentDay = null;
            }
            else
            {
                var startDate = orgEvent.StartTime.Value;
                var endDate   = orgEvent.EndTime.Value;

                DaysCount = DateTimeExtensions.DaysCount(
                    orgEvent.StartTime,
                    orgEvent.EndTime);

                if (startDate <= DateTime.Now.Date &&
                    DateTime.Now.Date <= endDate)
                {
                    CurrentDay = (DateTime.Now.Date - startDate).Days + 1;
                }
                else
                {
                    CurrentDay = null; // Maybe persist day on refresh
                }
            }
        }
Ejemplo n.º 2
0
        public static NSAttributedString GetOrgEventDateString(
            this OrgEvent orgEvent,
            UIColor textColor,
            int?currentDay  = null,
            bool isVertical = true)
        {
            if (orgEvent == null || !orgEvent.StartTime.HasValue)
            {
                return(new NSAttributedString());
            }

            var daysCount = DateTimeExtensions.DaysCount(orgEvent.StartTime, orgEvent.EndTime);
            var result    = new NSMutableAttributedString();

            var startDate = orgEvent.StartTime.Value.AddDays((currentDay ?? 1) - 1);
            var endDate   = orgEvent.EndTime.HasValue ? orgEvent.EndTime.Value : DateTime.MinValue;

            result.Append(
                new NSAttributedString(
                    string.Format("{0:MMM}{1}", startDate, Environment.NewLine).ToUpper(),
                    isVertical
                        ? Theme.OrgEventMonthFont
                        : Theme.OrgEventMonthLandscapeFont,
                    textColor,
                    null,
                    null,
                    new NSMutableParagraphStyle {
                Alignment = UITextAlignment.Center
            }));

            if (daysCount > 1 && currentDay == null)
            {
                result.Append(
                    new NSAttributedString(
                        string.Format("{0}-{1}", startDate.Day, endDate.Day),
                        isVertical
                            ? Theme.OrgEventTwoDaysFont
                            : Theme.OrgEventTwoDaysLandscapeFont,
                        textColor,
                        null,
                        null,
                        new NSMutableParagraphStyle {
                    Alignment          = UITextAlignment.Center,
                    LineHeightMultiple = 0.85f
                }));
            }
            else
            {
                result.Append(
                    new NSAttributedString(
                        string.Format("{0}", startDate.Day),
                        isVertical
                            ? Theme.OrgEventDayFont
                            : Theme.OrgEventDayLandscapeFont,
                        textColor,
                        null,
                        null,
                        new NSMutableParagraphStyle {
                    Alignment          = UITextAlignment.Center,
                    LineHeightMultiple = 0.9f
                }));
            }

            return(result);
        }