public static void Main() { // Creates and initializes a JulianCalendar. JulianCalendar myCal = new JulianCalendar(); // Displays the header. Console.Write("YEAR\t"); for (int y = 2001; y <= 2005; y++) { Console.Write("\t{0}", y); } Console.WriteLine(); // Displays the value of the CurrentEra property. Console.Write("CurrentEra:"); for (int y = 2001; y <= 2005; y++) { Console.Write("\t{0}", myCal.GetDaysInMonth(y, 2, JulianCalendar.CurrentEra)); } Console.WriteLine(); // Displays the values in the Eras property. for (int i = 0; i < myCal.Eras.Length; i++) { Console.Write("Era {0}:\t", myCal.Eras[i]); for (int y = 2001; y <= 2005; y++) { Console.Write("\t{0}", myCal.GetDaysInMonth(y, 2, myCal.Eras[i])); } Console.WriteLine(); } }
public void DateTimeExt_TestEndOfMonth() { var current = DateTime.UtcNow; var processed = current.ToEndOfMonth(); Assert.AreEqual(current.Year, processed.Year); Assert.AreEqual(current.Month, processed.Month); Assert.AreEqual(julian.GetDaysInMonth(current.Year, current.Month), processed.Day); Assert.AreEqual(23, processed.Hour); Assert.AreEqual(59, processed.Minute); Assert.AreEqual(59, processed.Second); Assert.AreEqual(999, processed.Millisecond); }
public static Tuple <DateTime, DateTime> ToQuarterRange(this DateTime dateTime) { var j = new JulianCalendar(); int currentDay = dateTime.DayOfYear; int indexDay = 0; for (int i = 1; i <= 12; i++) { indexDay += j.GetDaysInMonth(dateTime.Year, i); if (indexDay >= currentDay) { if (i >= 0 && i <= 3) { var endMonthNum = 3; return(new Tuple <DateTime, DateTime>(dateTime.ToStartOfYear(), new DateTime(dateTime.Year, endMonthNum, j.GetDaysInMonth(dateTime.Year, endMonthNum)).ToEndOfDay())); } else if (i >= 4 && i <= 6) { var endMonthNum = 6; return(new Tuple <DateTime, DateTime>(new DateTime(dateTime.Year, 4, 1).ToStartOfDay(), new DateTime(dateTime.Year, endMonthNum, j.GetDaysInMonth(dateTime.Year, endMonthNum)).ToEndOfDay())); } else if (i >= 7 && i <= 9) { var endMonthNum = 9; return(new Tuple <DateTime, DateTime>(new DateTime(dateTime.Year, 7, 1).ToStartOfDay(), new DateTime(dateTime.Year, endMonthNum, j.GetDaysInMonth(dateTime.Year, endMonthNum)).ToEndOfDay())); } else { var endMonthNum = 12; return(new Tuple <DateTime, DateTime>(new DateTime(dateTime.Year, 10, 1).ToStartOfDay(), new DateTime(dateTime.Year, endMonthNum, j.GetDaysInMonth(dateTime.Year, endMonthNum)).ToEndOfDay())); } } } return(null); }
public static void Main() { // Creates and initializes a JulianCalendar. JulianCalendar myCal = new JulianCalendar(); // Creates a holder for the last day of the second month (February). int iLastDay; // Displays the header. Console.Write("YEAR\t"); for (int y = 2001; y <= 2005; y++) { Console.Write("\t{0}", y); } Console.WriteLine(); // Checks five years in the current era. Console.Write("CurrentEra:"); for (int y = 2001; y <= 2005; y++) { iLastDay = myCal.GetDaysInMonth(y, 2, JulianCalendar.CurrentEra); Console.Write("\t{0}", myCal.IsLeapDay(y, 2, iLastDay, JulianCalendar.CurrentEra)); } Console.WriteLine(); // Checks five years in each of the eras. for (int i = 0; i < myCal.Eras.Length; i++) { Console.Write("Era {0}:\t", myCal.Eras[i]); for (int y = 2001; y <= 2005; y++) { iLastDay = myCal.GetDaysInMonth(y, 2, myCal.Eras[i]); Console.Write("\t{0}", myCal.IsLeapDay(y, 2, iLastDay, myCal.Eras[i])); } Console.WriteLine(); } }
public static DateTime ToEndOfMonth(this DateTime dateTime) { return(new DateTime(dateTime.Year, dateTime.Month, julianCalendar.GetDaysInMonth(dateTime.Year, dateTime.Month)).ToEndOfDay()); }