/// <summary> /// get the ealist time or latest time of the given date /// </summary> /// <param name="dateTime">Date time</param> /// <param name="xDaySegment"> DaySegment.Morning:time with 00:00:00,DaySegment.Night: time with 23:59:59,DaySegment.Noon:time with 12:00:00</param> /// <returns></returns> public static DateTime GetAbsDate(DateTime dateTime, DaySegment xDaySegment) { DateTime dt = new DateTime(); if (dateTime == DateTime.MinValue || dateTime == DateTime.MaxValue) { return(dateTime); } switch (xDaySegment) { case DaySegment.Morning: dt = new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, 0, 0, 0); break; case DaySegment.Noon: dt = new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, 12, 0, 0); break; case DaySegment.Night: dt = new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, 23, 59, 59); break; } return(dt); }
/// <summary> /// get the ealist time or latest time of the given date /// </summary> /// <param name="dateTime">Date time</param> /// <param name="xDaySegment"> DaySegment.Morning:time with 00:00:00,DaySegment.Night: time with 23:59:59,DaySegment.Noon:time with 12:00:00</param> /// <returns></returns> public static DateTime GetAbsDate(DateTime dateTime, DaySegment xDaySegment) { DateTime dt = new DateTime(); if (dateTime == DateTime.MinValue || dateTime == DateTime.MaxValue) return dateTime; switch (xDaySegment) { case DaySegment.Morning: dt = new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, 0, 0, 0); break; case DaySegment.Noon: dt = new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, 12, 0, 0); break; case DaySegment.Night: dt = new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, 23, 59, 59); break; } return dt; }
/// <summary> /// Get DateTime,the time only can be /// </summary> /// <param name="xDateString"></param> /// <param name="xDateFormat"></param> /// <param name="xdaySegment"></param> /// <returns></returns> public static DateTime ConvertDate(string xDateString, DateFormat xDateFormat, DaySegment xdaySegment) { return GetAbsDate(ConvertDate(xDateString, xDateFormat), xdaySegment); }
private DateTime UpdateImage(SolarData data, DaySegment segment) { int[] imageList; DateTime segmentStart; DateTime segmentEnd; if (!JsonConfig.settings.darkMode) { switch (segment) { case DaySegment.Sunrise: imageList = ThemeManager.currentTheme.sunriseImageList; segmentStart = data.solarTimes[0]; segmentEnd = data.solarTimes[1]; break; case DaySegment.Day: imageList = ThemeManager.currentTheme.dayImageList; segmentStart = data.solarTimes[1]; segmentEnd = data.solarTimes[2]; break; case DaySegment.Sunset: imageList = ThemeManager.currentTheme.sunsetImageList; segmentStart = data.solarTimes[2]; segmentEnd = data.solarTimes[3]; break; default: imageList = ThemeManager.currentTheme.nightImageList; if (DateTime.Now < data.solarTimes[0]) { SolarData yesterdaysData = SunriseSunsetService.GetSolarData( DateTime.Today.AddDays(-1)); segmentStart = yesterdaysData.solarTimes[3]; segmentEnd = data.solarTimes[0]; } else { segmentStart = data.solarTimes[3]; SolarData tomorrowsData = SunriseSunsetService.GetSolarData( DateTime.Today.AddDays(1)); segmentEnd = tomorrowsData.solarTimes[0]; } break; } } else { imageList = ThemeManager.currentTheme.nightImageList; if (isSunUp) { segmentStart = data.sunriseTime; segmentEnd = data.sunsetTime; } else if (DateTime.Now < data.sunriseTime) { SolarData yesterdaysData = SunriseSunsetService.GetSolarData( DateTime.Today.AddDays(-1)); segmentStart = yesterdaysData.sunsetTime; segmentEnd = data.sunriseTime; } else { segmentStart = data.sunsetTime; SolarData tomorrowsData = SunriseSunsetService.GetSolarData( DateTime.Today.AddDays(1)); segmentEnd = tomorrowsData.sunriseTime; } } TimeSpan segmentLength = segmentEnd - segmentStart; TimeSpan timerLength = new TimeSpan(segmentLength.Ticks / imageList.Length); int imageNumber = GetImageNumber(segmentStart, timerLength); long nextUpdateTicks = segmentStart.Ticks + timerLength.Ticks * (imageNumber + 1); SetWallpaper(imageList[imageNumber]); return(new DateTime(nextUpdateTicks)); }
/// <summary> /// Get DateTime,the time only can be /// </summary> /// <param name="xDateString"></param> /// <param name="xDateFormat"></param> /// <param name="xdaySegment"></param> /// <returns></returns> public static DateTime ConvertDate(string xDateString, DateFormat xDateFormat, DaySegment xdaySegment) { return(GetAbsDate(ConvertDate(xDateString, xDateFormat), xdaySegment)); }