Exemplo n.º 1
0
        /// <summary>
        /// Returns the daylight changes for UTC (never).
        /// </summary>
        public override DaylightTime GetDaylightChanges(int year)
        {
            // We need a start and stop time
            DateTime start, end;
            Calendar cal = new GregorianCalendar();

            // 2007+ at this point has a slightly different start/stop
            if (year >= 2007)
            {
                start = new DateTime(year, 4, 1, 2, 0, 0);
                end = new DateTime(year, 11, 1, 2, 0, 0);
            }
            else
            {
                start = new DateTime(year, 3, 1, 2, 0, 0);
                end = new DateTime(year, 12, 1, 2, 0, 0);
            }

            // Move forward for the start date until we have a sunday
            while (cal.GetDayOfWeek(start) != DayOfWeek.Sunday)
                start = cal.AddDays(start, 1);

            // Move backwards from the end date to the last sunday
            while (cal.GetDayOfWeek(end) != DayOfWeek.Sunday)
                start = cal.AddDays(end, 1);

            // Create it
            return new DaylightTime(start, end,
                new TimeSpan(stOffset - dtOffset, 0, 0));
        }
        public async Task <List <IndicatorData> > LastWeek()
        {
            var dt       = DateTime.Now;
            var dtSunday = new System.Globalization.GregorianCalendar().AddDays(dt, -((int)dt.DayOfWeek) - 7);
            var dtFriday = dtSunday.AddDays(6);

            return(await this.dbContext.Set <IndicatorData>()
                   .Where(r => r.ReleaseDateTime >= dtSunday && r.ReleaseDateTime <= dtFriday)
                   .OrderBy(r => r.ReleaseDateTime)
                   .ToListAsync());
        }
 /// <summary>
 /// Inherited code: Requires comment.
 /// </summary>
 /// <param name="time">Inherited code: Requires comment 1.</param>
 /// <param name="days">Inherited code: Requires comment 2.</param>
 /// <returns>Inherited code: Requires comment 3.</returns>
 public static DateTime? AddDays(DateTime time, int days)
 {
     System.Globalization.Calendar cal = new GregorianCalendar();
     try
     {
         return cal.AddDays(time, days);
     }
     catch (ArgumentException)
     {
         return null;
     }
 }
Exemplo n.º 4
0
        private bool ParseTrek(ClockToken[] dt, ref System.Int32 parsePos, TclDateTime calendar)
        // calendar object to set
        {
            int pos = parsePos;

            if (pos + 3 < dt.Length && dt[pos].is_Renamed(ClockToken.STARDATE) && dt[pos + 1].UNumber && dt[pos + 2].is_Renamed('.') && dt[pos + 3].UNumber)
            {
                GregorianCalendar gcal = new GregorianCalendar();
                int trekYear = dt[pos + 1].Int / 1000 + 2323 - 377;
                int trekDay = 1 + ((dt[pos + 1].Int % 1000) * (gcal.IsLeapYear(trekYear) ? 366 : 365)) / 1000;
                int trekSeconds = dt[pos + 3].Int * 144 * 60;
                calendar.year = trekYear;
                calendar.dateTime = gcal.AddDays(calendar.dateTime, trekDay);
                calendar.second = trekSeconds;
                parsePos = pos + 4;
                return true;
            }
            return false;
        }
Exemplo n.º 5
0
        private void VerifySelectDaySingleRangeMouseHover(Calendar calendar)
        {
            //Assumes that the Calendar is Gregorian
            CalendarDayButton b;
            System.Globalization.Calendar cal = new GregorianCalendar();
            int start, end;
            DateTime r1, r2;

            r1 = new DateTime(2003, 10, 10);
            r2 = new DateTime(2003, 11, 1);

            Clear();
            calendar.DisplayDate = r1;
            b = calendar.FindDayButtonFromDay(r1);
            start = b.Index;
            calendar.TestHook.MonthControl.TestHook.Cell_MouseLeftButtonDown(b, null);
            calendar.TestHook.MonthControl.TestHook.Cell_MouseLeave(b, null);

            while (DateTime.Compare(r2, r1) > 0)
            {
                r1 = cal.AddDays(r1, 1);
                b = calendar.FindDayButtonFromDay(r1);
                calendar.TestHook.MonthControl.TestHook.Cell_MouseEnter(b, null);
                calendar.TestHook.MonthControl.TestHook.Cell_MouseLeave(b, null);
            }
            end = b.Index;
            Assert.IsTrue(calendar.SelectedDates.Count == 0);

            //check if the buttons are highlighted
            for (int i = start; i <= end; i++)
            {
                Assert.IsTrue(((CalendarDayButton)calendar.TestHook.MonthControl.MonthView.Children[i]).IsSelected);
            }

            b = calendar.FindDayButtonFromDay(r2);
            calendar.TestHook.MonthControl.TestHook.Cell_MouseLeftButtonUp(b, null);

            Assert.IsTrue(_addedDays.Count == 23);
            Assert.IsTrue(_eventCount == 1);

            Assert.IsTrue(DateTimeHelper.CompareYearMonth(calendar.DisplayDate, r2) == 0);
            Assert.IsTrue(calendar.SelectedDates.Count == 23);
            Assert.IsTrue(CompareDates(calendar.SelectedDates[0], calendar.SelectedDate.Value));

            _isLoaded = false;
        }
Exemplo n.º 6
0
 private void ProcessUpKey() 
 {
     System.Globalization.Calendar _cal = new GregorianCalendar();
     if (this.DisplayMode == CalendarMode.Month) 
     {
         DateTime selectedDate = _cal.AddDays(this.SelectedDate.GetValueOrDefault(DateTime.Today), -7);
         if (IsValidDate(this, selectedDate)) 
         { 
             OnDayClick(selectedDate);
         } 
     }
     else
     { 
         Debug.Assert(this.DisplayMode == CalendarMode.Year);
         DateTime selectedMonth = _cal.AddMonths(this._selectedMonth, -4);
         OnSelectedMonthChanged(selectedMonth); 
     } 
 }
Exemplo n.º 7
0
 private void ProcessEndKey() 
 { 
     System.Globalization.Calendar _cal = new GregorianCalendar();
     if (this.DisplayMode == CalendarMode.Month) 
     {
         if (this.DisplayDate != null)
         { 
             DateTime selectedDate = new DateTime(((DateTime)this.DisplayDate).Year, ((DateTime)this.DisplayDate).Month, 1);
             selectedDate = _cal.AddMonths(selectedDate, 1);
             selectedDate = _cal.AddDays(selectedDate, -1); 
             if (IsValidDate(this, selectedDate)) 
             {
                 OnDayClick(selectedDate); 
             }
         }
     } 
     else
     {
         Debug.Assert(this.DisplayMode == CalendarMode.Year); 
         DateTime selectedMonth = new DateTime(this._selectedMonth.Year, 12, 1); 
         OnSelectedMonthChanged(selectedMonth);
     } 
 }