static void Main(string[] args) { int inYear = 1916; int day, month, year; DateTime date = new DateTime(inYear, 1, 1); date = date.AddDays(255); Calendar julian = new JulianCalendar(); Calendar gregorian = new GregorianCalendar(); if (inYear < 1918) { day = julian.GetDayOfMonth(date); month = julian.GetMonth(date); year = julian.GetYear(date); date = new DateTime(year, month, day); } else { if (inYear == 1918) { date = date.AddDays(-12); } day = gregorian.GetDayOfMonth(date); month = gregorian.GetMonth(date); year = gregorian.GetYear(date); date = new DateTime(year, month, day); } Console.WriteLine(date.ToString("dd.MM.yyyy")); Console.ReadKey(); }
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(); // Checks five years in the current era. Console.Write("CurrentEra:"); for (int y = 2001; y <= 2005; y++) { Console.Write("\t{0}", myCal.IsLeapYear(y, 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++) { Console.Write("\t{0}", myCal.IsLeapYear(y, myCal.Eras[i])); } Console.WriteLine(); } }
private string GetJulianDate(EventCustomerResult eventCustomerResult) { var pdfGeneration = GetPdfGenerationDate(eventCustomerResult); var calendar = new JulianCalendar(); return(pdfGeneration.ToString("yy") + calendar.GetDayOfYear(pdfGeneration).ToString("000")); }
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 SqlString Date2JulianMarkup(SqlBytes input) { if (input.IsNull) { return SqlString.Null; } byte[] inputBytes = input.Value; int year = (inputBytes[0] << 4 | inputBytes[1] >> 4) - 1024; int month = (inputBytes[1] & 0x0F) - 1; int day = inputBytes[2] >> 3; string result; DateTime date = new DateTime(year, month, day); JulianCalendar julianCalendar = new JulianCalendar(); int jYear = julianCalendar.GetYear(date); int jMonthOffset = julianCalendar.GetMonth(date) - 1; int jDay = julianCalendar.GetDayOfMonth(date); if (jYear == year) { result = "[Day[" + date_time_format_info.GetMonthName(month) + "-" + day + "|" + date_time_format_info.GetMonthName(month) + " " + day + "]] (O.S. " + date_time_format_info.GetMonthName(month) + " " + jDay + "), " + "[Year[" + year + "]]"; } else { result = "[Day[" + date_time_format_info.GetMonthName(month) + "-" + day + "|" + date_time_format_info.GetMonthName(month) + " " + day + "]], [Year[" + year + "|" + year + "]], (O.S. " + date_time_format_info.GetMonthName(month) + " " + jDay + ", " + jYear + ")"; } if ((inputBytes[2] & 0x02) == 0) { result = "circa " + result; } if ((inputBytes[2] & 0x04) == 0) { result = "? " + result; } return new SqlString(result); }
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.GetDaysInYear(y, 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.GetDaysInYear(y, myCal.Eras[i])); } Console.WriteLine(); } }
private void dateTimePicker1_ValueChanged(object sender, EventArgs e) { DateTime myDT = new DateTime(dateTimePicker1.Value.Date.Year, dateTimePicker1.Value.Date.Month, dateTimePicker1.Value.Date.Day, new GregorianCalendar()); JulianCalendar myCal = new JulianCalendar(); textBox1.Text = "Day: " + myCal.GetDayOfYear(myDT); }
static void Main(string[] args) { ICalendar grigorian = new GrigorianCalendar(); ICalendar julian = new JulianCalendar(); TestCalendar(grigorian); TestCalendar(julian); }
public static void Main() { var julianCalendar = new JulianCalendar(); var date = new DateTime(1307, 11, 13, julianCalendar); Console.WriteLine(Invariant($"Gregorian: {date:yyyy-MM-dd}")); Console.WriteLine(date.DayOfWeek); }
static string CalculateJulian(int year, int daysToAdd) { var calendar = new JulianCalendar(); var d = new DateTime(year, 1, 1, calendar); var d2 = d.AddDays(daysToAdd - 13); return(FormatDate(d2)); }
private PlotModel plotModelDln(DadosEntrada dados, int julianDate) { JulianCalendar julianCalendar = new JulianCalendar(); DateTime data = new DateTime(DateTime.Now.Year, 1, 1); dados.Data = julianCalendar.AddDays(data, julianDate - 1); return(plotModelDln(dados)); }
//here we generate most of the Paths.meta line excluding the relative path to the file itself static string GetFirstPartOfString() { string result; DateTime currentDate = DateTime.Now; JulianCalendar julianCalendar = new JulianCalendar(); result = currentDate.Year.ToString().Substring(2) + julianCalendar.GetDayOfYear(currentDate).ToString() + setari.Number.ToString("00000") + setari.Separator + currentDate.ToString("yyyy/MM/dd HH:mm:ss") + setari.Separator; return(result); }
/// <summary> /// Converts the date in Gregorian Calendar to a date in Julian Calendar. /// </summary> /// <param name="date">Date in Gregorian Calendar</param> /// <returns> /// Date in Julian Calendar /// </returns> public static Date GregorianToJulian(Date date) { DateTime dt = new DateTime(date.Year, date.Month, (int)date.Day, new GregorianCalendar()); JulianCalendar julianCalendar = new JulianCalendar(); return(new Date( julianCalendar.GetYear(dt), julianCalendar.GetMonth(dt), julianCalendar.GetDayOfMonth(dt))); }
public void TestJulianToDate() { TestDate(JulianCalendar.Create(1842713.0), 333, Month.January, 27.5); TestDate(JulianCalendar.Create(2026871.8), 837, 4, 10.3); TestDate(JulianCalendar.Create(1356001.0), -1000, 7, 12.5); TestDate(JulianCalendar.Create(1355866.5), -1000, 2, 29.0); TestDate(JulianCalendar.Create(1355671.4), -1001, 8, 17.9); TestDate(JulianCalendar.Create(0.0), -4712, 1, 1.5); }
public static void Main() { JulianCalendar julian = new JulianCalendar(); DateTime date1 = new DateTime(1905, 1, 9, julian); Console.WriteLine("Date ({0}): {1:d}", CultureInfo.CurrentCulture.Calendar, date1); Console.WriteLine("Date in Julian calendar: {0:d2}/{1:d2}/{2:d4}", julian.GetMonth(date1), julian.GetDayOfMonth(date1), julian.GetYear(date1)); }
public static void Main() { Thread.CurrentThread.CurrentCulture = new CultureInfo("da-DK"); JulianCalendar jc = new JulianCalendar(); DateTime lastDate = new DateTime(1700, 2, 18, jc); Console.WriteLine("Last date (Gregorian): {0:d}", lastDate); Console.WriteLine("Last date (Julian): {0}-{1}-{2}\n", jc.GetDayOfMonth(lastDate), jc.GetMonth(lastDate), jc.GetYear(lastDate)); DateTime firstDate = lastDate.AddDays(1); Console.WriteLine("First date (Gregorian): {0:d}", firstDate); Console.WriteLine("First date (Julian): {0}-{1}-{2}", jc.GetDayOfMonth(firstDate), jc.GetMonth(firstDate), jc.GetYear(firstDate)); }
static void Main(string[] args) { jcal = new JulianCalendar(); string jDateString = "1104-08-16"; char[] delimiterChars = { '-' }; string[] dateParts = jDateString.Split(delimiterChars); int jyear, jmonth, jday; bool success = int.TryParse(dateParts[0], out jyear); success = int.TryParse(dateParts[1], out jmonth); success = int.TryParse(dateParts[2], out jday); DateTime myDate = new DateTime(jyear, jmonth, jday, 0, 0, 0, 0, jcal); Console.WriteLine("Date converted to Gregorian: {0}", myDate); Console.ReadLine(); }
// 'GENERATE INDEX' CLICKED: GENERATE INDEX AND BARCODE FROM FORM DATA. private void generateBarcode() { try { if (!Page.IsValid) { return; } // First, get list of all entries. indexSetPrintedMsg.Visible = false; List <EntryContent> allEntriesList = new List <EntryContent>(); allEntriesList = getEntries(); ViewState["allEntriesList"] = allEntriesList; // If Index form not filled if (allEntriesList.Count == 0) { string msg = "All fields are required!"; ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + msg + "');", true); return; } else { string year = DateTime.Now.ToString("yy"); JulianCalendar jc = new JulianCalendar(); string julianDay = jc.GetDayOfYear(DateTime.Now).ToString(); string time = DateTime.Now.ToString("HHmmssfff"); // Making the Index string ViewState["allEntriesConcat"] = selectJob.SelectedValue.ToUpper() + year + julianDay + time; } string indexString = (string)ViewState["allEntriesConcat"]; indexSavedMsg.Visible = false; generateIndexSection.Visible = true; // Convert index to barcode // imgBarcode.ImageUrl = string.Format("ShowCode39Barcode.ashx?code={0}&ShowText={1}&Thickness={2}",indexString,showTextValue, 1); } catch (Exception ex) { string msg = "Issue occured while attempting to generate Index. Contact system admin." + Environment.NewLine + ex.Message; System.Windows.Forms.MessageBox.Show(msg, "Error 04"); } }
public static void Main() { // Creates and initializes a JulianCalendar. JulianCalendar myCal = new JulianCalendar(); // Checks all the months in five years in the current era. int iMonthsInYear; for (int y = 2001; y <= 2005; y++) { Console.Write("{0}:\t", y); iMonthsInYear = myCal.GetMonthsInYear(y, JulianCalendar.CurrentEra); for (int m = 1; m <= iMonthsInYear; m++) { Console.Write("\t{0}", myCal.IsLeapMonth(y, m, JulianCalendar.CurrentEra)); } Console.WriteLine(); } }
private static double CurrentJulianDate() { JulianCalendar cal = new JulianCalendar(); int isJanFeb = (14 - cal.GetMonth(DateTime.UtcNow)) / 12; int years = cal.GetYear(DateTime.UtcNow) + 4800 - isJanFeb; int monthsMod = cal.GetMonth(DateTime.UtcNow) + (12 * isJanFeb) - 3; double dayNumber = cal.GetDayOfMonth(DateTime.UtcNow) + Math.Floor((double)(153 * monthsMod + 2) / 5) + 365 * years + Math.Floor((double)years / 4) - 32083; double julianDate = dayNumber + ((double)cal.GetHour(DateTime.UtcNow) - 12) / 24 + (double)cal.GetMinute(DateTime.UtcNow) / 1440 + (double)cal.GetSecond(DateTime.UtcNow) / 86400; return(julianDate); }
///// <summary> ///// ///// </summary> //public static string FromJulian // ( // long julianDate, // string format // ) //{ // long L = julianDate + 68569; // long N = (long)(4 * L / 146097); // L = L - (long)((146097 * N + 3) / 4); // long I = (long)(4000 * (L + 1) / 1461001); // L = L - (long)(1461 * I / 4) + 31; // long J = (long)(80 * L / 2447); // int Day = (int)(L - (long)(2447 * J / 80)); // L = (long)(J / 11); // int Month = (int)(J + 2 - 12 * L); // int Year = (int)(100 * (N - 49) + I + L); // // example format "dd/MM/yyyy" // return new DateTime(Year, Month, Day).ToString(format); //} /// <summary> /// /// </summary> public static string FromJulianDate ( DateTime gregorian ) { JulianCalendar calendar = new JulianCalendar(); var dateInJulian = calendar.ToDateTime ( gregorian.Year, gregorian.Month, gregorian.Day, gregorian.Hour, gregorian.Minute, gregorian.Second, gregorian.Millisecond ); return(dateInJulian.ToString("yyyyMMdd")); }
protected void SetUp() { gcal = new GregorianCalendar(); jucal = new JulianCalendar(); hical = new HijriCalendar(); hecal = new HebrewCalendar(); jacal = new JapaneseCalendar(); tacal = new TaiwanCalendar(); kcal = new KoreanCalendar(); tbcal = new ThaiBuddhistCalendar(); acal = new Calendar[] { gcal, jucal, hical, hecal, jacal, tacal, kcal, tbcal }; clcal = new ChineseLunisolarCalendar(); tlcal = new TaiwanLunisolarCalendar(); jlcal = new JapaneseLunisolarCalendar(); klcal = new KoreanLunisolarCalendar(); }
public static void Main() { // Sets a DateTime to April 3, 2002 of the Gregorian calendar. DateTime myDT = new DateTime(2002, 4, 3, new GregorianCalendar()); // Creates an instance of the JulianCalendar. JulianCalendar myCal = new JulianCalendar(); // Displays the values of the DateTime. Console.WriteLine("April 3, 2002 of the Gregorian calendar equals the following in the Julian calendar:"); DisplayValues(myCal, myDT); // Adds two years and ten months. myDT = myCal.AddYears(myDT, 2); myDT = myCal.AddMonths(myDT, 10); // Displays the values of the DateTime. Console.WriteLine("After adding two years and ten months:"); DisplayValues(myCal, myDT); }
public static void Main() { // Creates an instance of every Calendar type. Calendar[] myCals = new Calendar[8]; myCals[0] = new GregorianCalendar(); myCals[1] = new HebrewCalendar(); myCals[2] = new HijriCalendar(); myCals[3] = new JapaneseCalendar(); myCals[4] = new JulianCalendar(); myCals[5] = new KoreanCalendar(); myCals[6] = new TaiwanCalendar(); myCals[7] = new ThaiBuddhistCalendar(); // For each calendar, displays the current year, the number of months in that year, // and the number of days in each month of that year. int i, j, iYear, iMonth, iDay; DateTime myDT = DateTime.Today; for (i = 0; i < myCals.Length; i++) { iYear = myCals[i].GetYear(myDT); Console.WriteLine(); Console.WriteLine("{0}, Year: {1}", myCals[i].GetType(), myCals[i].GetYear(myDT)); Console.WriteLine(" MonthsInYear: {0}", myCals[i].GetMonthsInYear(iYear)); Console.WriteLine(" DaysInYear: {0}", myCals[i].GetDaysInYear(iYear)); Console.WriteLine(" Days in each month:"); Console.Write(" "); for (j = 1; j <= myCals[i].GetMonthsInYear(iYear); j++) { Console.Write(" {0,-5}", myCals[i].GetDaysInMonth(iYear, j)); } Console.WriteLine(); iMonth = myCals[i].GetMonth(myDT); iDay = myCals[i].GetDayOfMonth(myDT); Console.WriteLine(" IsLeapDay: {0}", myCals[i].IsLeapDay(iYear, iMonth, iDay)); Console.WriteLine(" IsLeapMonth: {0}", myCals[i].IsLeapMonth(iYear, iMonth)); Console.WriteLine(" IsLeapYear: {0}", myCals[i].IsLeapYear(iYear)); } }
public static void Main() { // Create an instance of the calendar. JulianCalendar myCal = new JulianCalendar(); Console.WriteLine(myCal.ToString()); // Create an instance of the GregorianCalendar. GregorianCalendar myGre = new GregorianCalendar(); // Display the MinSupportedDateTime and its equivalent in the GregorianCalendar. DateTime myMin = myCal.MinSupportedDateTime; Console.Write("MinSupportedDateTime: {0:D2}/{1:D2}/{2:D4}", myCal.GetMonth(myMin), myCal.GetDayOfMonth(myMin), myCal.GetYear(myMin)); Console.WriteLine(" (in Gregorian, {0:D2}/{1:D2}/{2:D4})", myGre.GetMonth(myMin), myGre.GetDayOfMonth(myMin), myGre.GetYear(myMin)); // Display the MaxSupportedDateTime and its equivalent in the GregorianCalendar. DateTime myMax = myCal.MaxSupportedDateTime; Console.Write("MaxSupportedDateTime: {0:D2}/{1:D2}/{2:D4}", myCal.GetMonth(myMax), myCal.GetDayOfMonth(myMax), myCal.GetYear(myMax)); Console.WriteLine(" (in Gregorian, {0:D2}/{1:D2}/{2:D4})", myGre.GetMonth(myMax), myGre.GetDayOfMonth(myMax), myGre.GetYear(myMax)); }
internal static Func <string, IValue> GetDateTimeParser(this IColumn column) { return(source => { if (source == null) { return new ValueWrapper <DateTime>(DateTime.MinValue, null, true, null); } DateTime value = default; var sourceStr = source.ToString(); var hasError = false; if (!string.IsNullOrWhiteSpace(column.Format)) { hasError = !DateTime.TryParseExact(sourceStr, column.Format.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries), CultureInfo.InvariantCulture, DateTimeStyles.None, out value); } if (string.IsNullOrWhiteSpace(column.Format) || hasError) { hasError = !DateTime.TryParse(sourceStr, out value); } if (!hasError && column.CalendarType == CalendarType.Julian) { value = new JulianCalendar().ToDateTime(value.Year, value.Month, value.Day, value.Hour, value.Minute, value.Second, value.Millisecond); } string error = null; if (hasError) { error = Localization.GetLocalizationString("Could not parse date \"{0}\" ", source); } return new ValueWrapper <DateTime>(value, error, false, source); }); }
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 void JulianTest() { JulianCalendar jc = new JulianCalendar(); Assert.False(jc.IsLeapYear(1999)); }
public void GetLeapMonth() { GregorianCalendar gc = new GregorianCalendar(); Assert.AreEqual(0, gc.GetLeapMonth(2007), "#1-1"); Assert.AreEqual(0, gc.GetLeapMonth(2008), "#1-2"); Assert.AreEqual(0, gc.GetLeapMonth(2100), "#1-3"); Assert.AreEqual(0, gc.GetLeapMonth(2000), "#1-4"); JulianCalendar jc = new JulianCalendar(); Assert.AreEqual(0, jc.GetLeapMonth(2007), "#2-1"); Assert.AreEqual(0, jc.GetLeapMonth(2008), "#2-2"); Assert.AreEqual(0, jc.GetLeapMonth(2100), "#2-3"); Assert.AreEqual(0, jc.GetLeapMonth(2000), "#2-4"); Assert.AreEqual(0, jc.GetLeapMonth(2009), "#2-5"); Assert.AreEqual(0, jc.GetLeapMonth(2010), "#2-6"); HebrewCalendar hc = new HebrewCalendar(); // 3rd, 6th, 8th, 11th 14th and 17th year in every 19 are leap. // 5339 % 19 = 0. Assert.AreEqual(0, hc.GetLeapMonth(5343), "#3-1"); Assert.AreEqual(0, hc.GetLeapMonth(5344), "#3-2"); Assert.AreEqual(7, hc.GetLeapMonth(5345), "#3-3"); Assert.AreEqual(0, hc.GetLeapMonth(5346), "#3-4"); Assert.AreEqual(7, hc.GetLeapMonth(5347), "#3-5"); Assert.AreEqual(0, hc.GetLeapMonth(5348), "#3-6"); Assert.AreEqual(0, hc.GetLeapMonth(5349), "#3-7"); ThaiBuddhistCalendar tc = new ThaiBuddhistCalendar(); Assert.AreEqual(0, tc.GetLeapMonth(2520), "#4-1"); Assert.AreEqual(0, tc.GetLeapMonth(2521), "#4-2"); Assert.AreEqual(0, tc.GetLeapMonth(2522), "#4-3"); Assert.AreEqual(0, tc.GetLeapMonth(2523), "#4-4"); ChineseLunisolarCalendar cc = new ChineseLunisolarCalendar(); Assert.AreEqual(0, cc.GetLeapMonth(2000), "#5-1"); Assert.AreEqual(5, cc.GetLeapMonth(2001), "#5-2"); Assert.AreEqual(0, cc.GetLeapMonth(2002), "#5-3"); Assert.AreEqual(0, cc.GetLeapMonth(2003), "#5-4"); Assert.AreEqual(3, cc.GetLeapMonth(2004), "#5-5"); Assert.AreEqual(0, cc.GetLeapMonth(2005), "#5-6"); Assert.AreEqual(8, cc.GetLeapMonth(2006), "#5-7"); Assert.AreEqual(0, cc.GetLeapMonth(2007), "#5-8"); Assert.AreEqual(0, cc.GetLeapMonth(2008), "#5-9"); Assert.AreEqual(6, cc.GetLeapMonth(2009), "#5-10"); Assert.AreEqual(0, cc.GetLeapMonth(2010), "#5-11"); Assert.AreEqual(0, cc.GetLeapMonth(2011), "#5-12"); Assert.AreEqual(5, cc.GetLeapMonth(2012), "#5-13"); Assert.AreEqual(0, cc.GetLeapMonth(2013), "#5-14"); Assert.AreEqual(10, cc.GetLeapMonth(2014), "#5-15"); Assert.AreEqual(0, cc.GetLeapMonth(2015), "#5-16"); Assert.AreEqual(0, cc.GetLeapMonth(2016), "#5-17"); Assert.AreEqual(7, cc.GetLeapMonth(2017), "#5-18"); Assert.AreEqual(0, cc.GetLeapMonth(2018), "#5-19"); Assert.AreEqual(0, cc.GetLeapMonth(2019), "#5-20"); KoreanLunisolarCalendar kc = new KoreanLunisolarCalendar(); Assert.AreEqual(0, kc.GetLeapMonth(2000), "#6-1"); Assert.AreEqual(5, kc.GetLeapMonth(2001), "#6-2"); Assert.AreEqual(0, kc.GetLeapMonth(2002), "#6-3"); Assert.AreEqual(0, kc.GetLeapMonth(2003), "#6-4"); Assert.AreEqual(3, kc.GetLeapMonth(2004), "#6-5"); Assert.AreEqual(0, kc.GetLeapMonth(2005), "#6-6"); Assert.AreEqual(8, kc.GetLeapMonth(2006), "#6-7"); Assert.AreEqual(0, kc.GetLeapMonth(2007), "#6-8"); Assert.AreEqual(0, kc.GetLeapMonth(2008), "#6-9"); Assert.AreEqual(6, kc.GetLeapMonth(2009), "#6-10"); Assert.AreEqual(0, kc.GetLeapMonth(2010), "#6-11"); Assert.AreEqual(0, kc.GetLeapMonth(2011), "#6-12"); Assert.AreEqual(4, kc.GetLeapMonth(2012)); // off from cn by 1, "#6-13"); Assert.AreEqual(0, kc.GetLeapMonth(2013), "#6-14"); Assert.AreEqual(10, kc.GetLeapMonth(2014), "#6-15"); Assert.AreEqual(0, kc.GetLeapMonth(2015), "#6-16"); Assert.AreEqual(0, kc.GetLeapMonth(2016), "#6-17"); Assert.AreEqual(6, kc.GetLeapMonth(2017)); // off from cn by 1, "#6-18"); Assert.AreEqual(0, kc.GetLeapMonth(2018), "#6-19"); Assert.AreEqual(0, kc.GetLeapMonth(2019), "#6-20"); }
/// <summary> /// Parse passed date into instance properties. /// </summary> /// <param name="inputDate">The date to parse as a text string.</param> public void ParseDateString(string inputDate) { // clear possible Period cached value; this.period = null; string dateType = string.Empty; var dataString = inputDate; // Preserve inputDate for feedback to the user if it is broken. if (dataString.StartsWith("@#")) { dataString = dataString.Substring(2); int i = dataString.IndexOf("@", 2); // TODO: Subtle bug? Should the 2 be there as already trimmed above? if (i != -1) { dateType = dataString.Substring(0, i).ToUpper(); dataString = dataString.Substring(i + 1); } } switch (dateType) { case "@#DGREGORIAN@": DateType = GedcomDateType.Gregorian; break; case "@#DJULIAN@": DateType = GedcomDateType.Julian; break; case "@#DHEBREW@": DateType = GedcomDateType.Hebrew; break; case "@#DROMAN@": DateType = GedcomDateType.Roman; break; case "@#DUNKNOWN@": DateType = GedcomDateType.Unknown; break; default: DateType = GedcomDateType.Gregorian; break; } period = dataString; var periodResult = ExtractDatePeriod(period); dataString = periodResult.DataAfterExtraction; DatePeriod = periodResult.DatePeriod; Calendar calendar = null; switch (DateType) { case GedcomDateType.French: // TODO: no FrenCalendar! Date1 = dataString; throw new NotImplementedException(); break; case GedcomDateType.Gregorian: calendar = new GregorianCalendar(); Date1 = dataString; break; case GedcomDateType.Hebrew: calendar = new HebrewCalendar(); Date1 = dataString; break; case GedcomDateType.Julian: calendar = new JulianCalendar(); Date1 = dataString; break; case GedcomDateType.Roman: // TODO: no RomanCalendar! Date1 = dataString; throw new NotImplementedException(); break; } string[] dateSplit = SplitDateString(dataString); dateTime1 = null; dateTime2 = null; partsParsed1 = 0; partsParsed2 = 0; if (dateSplit.Length == 1) { partsParsed1 = 1; partsParsed2 = 0; dateTime1 = GetDateInfo(dateSplit, 0, 1, calendar, inputDate); if (dateTime1 != null) { // We only got a year, so we need to interpret that as a range from the start to the end of the year. dateTime2 = dateTime1.Value.AddYears(1).AddSeconds(-1); partsParsed2 = 1; AddParserMessage(ParserMessageIds.InterpretedAsYearRange, inputDate, dateTime1, dateTime2); } } else if (dateSplit.Length == 2) { partsParsed1 = 2; partsParsed2 = 0; dateTime1 = GetDateInfo(dateSplit, 0, 2, calendar, inputDate); if (dateTime1 != null) { // We only got a month and year, so we need to interpret that as a range from the start to the end of the month. dateTime2 = dateTime1.Value.AddMonths(1).AddSeconds(-1); partsParsed2 = 2; AddParserMessage(ParserMessageIds.InterpretedAsMonthRange, inputDate, dateTime1, dateTime2); } } else if (dateSplit.Length == 3) { // day month year or year (AND/TO) year if (string.Compare(dateSplit[1], "AND", true) != 0 && string.Compare(dateSplit[1], "TO", true) != 0) { partsParsed1 = 1; partsParsed2 = 0; dateTime1 = GetDateInfo(dateSplit, 0, 3, calendar, inputDate); } else { partsParsed1 = 1; partsParsed2 = 1; dateTime1 = GetDateInfo(dateSplit, 0, 1, calendar, inputDate); dateTime2 = GetDateInfo(dateSplit, 2, 1, calendar, inputDate); } } else if (dateSplit.Length > 4) { // AND ? TO ? if (DatePeriod == GedcomDatePeriod.Between || DatePeriod == GedcomDatePeriod.Range) { // where is the AND / TO ? if (string.Compare(dateSplit[1], "AND", true) == 0 || string.Compare(dateSplit[1], "TO", true) == 0) { partsParsed1 = 1; partsParsed2 = 3; dateTime1 = GetDateInfo(dateSplit, 0, 1, calendar, inputDate); dateTime2 = GetDateInfo(dateSplit, 2, 3, calendar, inputDate); } else if (string.Compare(dateSplit[2], "AND", true) == 0 || string.Compare(dateSplit[2], "TO", true) == 0) { partsParsed1 = 2; partsParsed2 = 3; dateTime1 = GetDateInfo(dateSplit, 0, 2, calendar, inputDate); dateTime2 = GetDateInfo(dateSplit, 3, 3, calendar, inputDate); } else { // lets assume dateSplit[3] is AND / TO partsParsed1 = 3; partsParsed2 = 3; dateTime1 = GetDateInfo(dateSplit, 0, 3, calendar, inputDate); dateTime2 = GetDateInfo(dateSplit, 4, 3, calendar, inputDate); } } else { // assume date is generic text, can't do much with it // TODO: We should feed back to the user here. } } if ((DatePeriod == GedcomDatePeriod.Exact && dateTime1 == null) || !dateTime1.HasValue) { // unable to parse, let's try some more methods // as these dates are used for analysis it doesn't matter // too much if the format is wrong, e.g. we read 12-11-1994 // as 12 NOV 1994 when it is meant as 11 DEC 1994, we don't // throw away the original data at all or use these dates // when writing the data back out // TODO: format provider instead of null? DateTime date; if (DateTime.TryParseExact(dataString, new string[] { "d-M-yyyy", "M-d-yyyy", "yyyy-M-d", "d.M.yyyy", "M.d.yyyy", "yyyy.M.d" }, null, DateTimeStyles.None, out date)) { dateTime1 = date; partsParsed1 = 3; partsParsed2 = 0; } // other values seen, UNKNOWN, PRIVATE, DECEASED, DEAD // These have probably been entered so the system // it was entered on doesn't remove the event due // to lack of any date entered. // accept as unparsable } }
private void dateTimePicker1_ValueChanged(object sender, EventArgs e) { JulianCalendar myCal = new JulianCalendar(); textBox1.Text = (myCal.GetDayOfYear(dateTimePicker1.Value)).ToString(); }
public bool runTest() { Console.WriteLine(s_strTFPath + "\\" + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer); String strLoc = "Loc_000oo"; String strValue = String.Empty; int iCountErrors = 0; int iCountTestcases = 0; try { DateTime dTest; HebrewCalendar hCal = new HebrewCalendar(); JulianCalendar jCal = new JulianCalendar(); HijriCalendar hiCal = new HijriCalendar (); GregorianCalendar gCal = new GregorianCalendar (); JapaneseCalendar jaCal = new JapaneseCalendar (); KoreanCalendar kCal = new KoreanCalendar (); ThaiBuddhistCalendar tCal = new ThaiBuddhistCalendar (); strLoc = "Loc_100vy"; iCountTestcases++; dTest = new DateTime(5360,04,14,hCal); if (dTest.Year != 1600) { ++iCountErrors; printerr( "Error_100aa! DateTime object was not set correctly"); } if (dTest.Month != 1) { ++iCountErrors; printerr( "Error_100bb! DateTime object was not set correctly"); } if (dTest.Day != 1) { ++iCountErrors; printerr( "Error_100cc! DateTime object was not set correctly"); } if (dTest.Hour != 0) { ++iCountErrors; printerr( "Error_100dd! DateTime object was not set correctly"); } if (dTest.Minute != 0) { ++iCountErrors; printerr( "Error_100ee! DateTime object was not set correctly"); } if (dTest.Second != 0) { ++iCountErrors; printerr( "Error_100ff! DateTime object was not set correctly"); } if (dTest.Millisecond != 0) { ++iCountErrors; printerr( "Error_100gg! DateTime object was not set correctly"); } strLoc = "Loc_101vy"; iCountTestcases++; dTest = new DateTime(1599,12,22,jCal); if (dTest.Year != 1600) { ++iCountErrors; printerr( "Error_101aa! DateTime object was not set correctly"); } if (dTest.Month != 1) { ++iCountErrors; printerr( "Error_101bb! DateTime object was not set correctly"); } if (dTest.Day != 1) { ++iCountErrors; printerr( "Error_101cc! DateTime object was not set correctly"); } if (dTest.Hour != 0) { ++iCountErrors; printerr( "Error_101dd! DateTime object was not set correctly"); } if (dTest.Minute != 0) { ++iCountErrors; printerr( "Error_101ee! DateTime object was not set correctly"); } if (dTest.Second != 0) { ++iCountErrors; printerr( "Error_101ff! DateTime object was not set correctly"); } if (dTest.Millisecond != 0) { ++iCountErrors; printerr( "Error_101gg! DateTime object was not set correctly"); } strLoc = "Loc_102vy"; iCountTestcases++; dTest = new DateTime(1008,06,15,hiCal); if (dTest.Year != 1600) { ++iCountErrors; printerr( "Error_102aa! DateTime object was not set correctly"); } if (dTest.Month != 1) { ++iCountErrors; printerr( "Error_102bb! DateTime object was not set correctly"); } if (dTest.Day != 1) { ++iCountErrors; printerr( "Error_102cc! DateTime object was not set correctly"); } if (dTest.Hour != 0) { ++iCountErrors; printerr( "Error_102dd! DateTime object was not set correctly"); } if (dTest.Minute != 0) { ++iCountErrors; printerr( "Error_102ee! DateTime object was not set correctly"); } if (dTest.Second != 0) { ++iCountErrors; printerr( "Error_102ff! DateTime object was not set correctly"); } if (dTest.Millisecond != 0) { ++iCountErrors; printerr( "Error_102gg! DateTime object was not set correctly"); } strLoc = "Loc_103vy"; iCountTestcases++; dTest = new DateTime(1600,1,1,gCal); if (dTest.Year != 1600) { ++iCountErrors; printerr( "Error_103aa! DateTime object was not set correctly"); } if (dTest.Month != 1) { ++iCountErrors; printerr( "Error_103bb! DateTime object was not set correctly"); } if (dTest.Day != 1) { ++iCountErrors; printerr( "Error_103cc! DateTime object was not set correctly"); } if (dTest.Hour != 0) { ++iCountErrors; printerr( "Error_103dd! DateTime object was not set correctly"); } if (dTest.Minute != 0) { ++iCountErrors; printerr( "Error_103ee! DateTime object was not set correctly"); } if (dTest.Second != 0) { ++iCountErrors; printerr( "Error_103ff! DateTime object was not set correctly"); } if (dTest.Millisecond != 0) { ++iCountErrors; printerr( "Error_103gg! DateTime object was not set correctly"); } strLoc = "Loc_104vy"; iCountTestcases++; dTest = new DateTime(1,1,8,jaCal); if (dTest.Year != 1989) { ++iCountErrors; printerr( "Error_104aa! DateTime object was not set correctly"); } if (dTest.Month != 1) { ++iCountErrors; printerr( "Error_104bb! DateTime object was not set correctly"); } if (dTest.Day != 8) { ++iCountErrors; printerr( "Error_104cc! DateTime object was not set correctly"); } if (dTest.Hour != 0) { ++iCountErrors; printerr( "Error_104dd! DateTime object was not set correctly"); } if (dTest.Minute != 0) { ++iCountErrors; printerr( "Error_104ee! DateTime object was not set correctly"); } if (dTest.Second != 0) { ++iCountErrors; printerr( "Error_104ff! DateTime object was not set correctly"); } if (dTest.Millisecond != 0) { ++iCountErrors; printerr( "Error_104gg! DateTime object was not set correctly"); } strLoc = "Loc_105vy"; iCountTestcases++; dTest = new DateTime(3933,1,1,kCal); if (dTest.Year != 1600) { ++iCountErrors; printerr( "Error_105aa! DateTime object was not set correctly"); } if (dTest.Month != 1) { ++iCountErrors; printerr( "Error_105bb! DateTime object was not set correctly"); } if (dTest.Day != 1) { ++iCountErrors; printerr( "Error_105cc! DateTime object was not set correctly"); } if (dTest.Hour != 0) { ++iCountErrors; printerr( "Error_105dd! DateTime object was not set correctly"); } if (dTest.Minute != 0) { ++iCountErrors; printerr( "Error_105ee! DateTime object was not set correctly"); } if (dTest.Second != 0) { ++iCountErrors; printerr( "Error_105ff! DateTime object was not set correctly"); } if (dTest.Millisecond != 0) { ++iCountErrors; printerr( "Error_105gg! DateTime object was not set correctly"); } strLoc = "Loc_106vy"; iCountTestcases++; dTest = new DateTime(2143,1,1,tCal); if (dTest.Year != 1600) { ++iCountErrors; printerr( "Error_106aa! DateTime object was not set correctly"); } if (dTest.Month != 1) { ++iCountErrors; printerr( "Error_106bb! DateTime object was not set correctly"); } if (dTest.Day != 1) { ++iCountErrors; printerr( "Error_106cc! DateTime object was not set correctly"); } if (dTest.Hour != 0) { ++iCountErrors; printerr( "Error_106dd! DateTime object was not set correctly"); } if (dTest.Minute != 0) { ++iCountErrors; printerr( "Error_106ee! DateTime object was not set correctly"); } if (dTest.Second != 0) { ++iCountErrors; printerr( "Error_106ff! DateTime object was not set correctly"); } if (dTest.Millisecond != 0) { ++iCountErrors; printerr( "Error_106gg! DateTime object was not set correctly"); } strLoc = "Loc_524vy"; iCountTestcases++; try { dTest = new DateTime(0,03,25,hCal); iCountErrors++; printerr( "Error_200bb! No exception thrown"); } catch (ArgumentOutOfRangeException argexc) { printinfo( "Info_512ad! Caught ArguementOutOfRangeException"); } catch (Exception e) { ++iCountErrors; printerr( "Error_200aa! Wrong exception thrown: " + e.ToString()); } strLoc = "Loc_333vy"; iCountTestcases++; try { dTest = new DateTime(10000,03,25,hCal); iCountErrors++; printerr( "Error_300bb! No exception thrown"); } catch (ArgumentOutOfRangeException argexc) { printinfo( "Info_333ad! Caught ArguementOutOfRangeException"); } catch (Exception e) { ++iCountErrors; printerr( "Error_300aa! Wrong exception thrown: " + e.ToString()); } strLoc = "Loc_444vy"; iCountTestcases++; try { dTest = new DateTime(5000,0,25,hCal); iCountErrors++; printerr( "Error_400bb! No exception thrown"); } catch (ArgumentOutOfRangeException argexc) { printinfo( "Info_444ad! Caught ArguementOutOfRangeException"); } catch (Exception e) { ++iCountErrors; printerr( "Error_400aa! Wrong exception thrown: " + e.ToString()); } strLoc = "Loc_555vy"; iCountTestcases++; try { dTest = new DateTime(5000,13,25,jCal); iCountErrors++; printerr( "Error_500bb! No exception thrown"); } catch (ArgumentOutOfRangeException argexc) { printinfo( "Info_555ad! Caught ArguementOutOfRangeException"); } catch (Exception e) { ++iCountErrors; printerr( "Error_500aa! Wrong exception thrown: " + e.ToString()); } strLoc = "Loc_665vy"; iCountTestcases++; try { dTest = new DateTime(2000,03,0,jCal); iCountErrors++; printerr( "Error_600bb! No exception thrown"); } catch (ArgumentOutOfRangeException argexc) { printinfo( "Info_665ad! Caught ArguementOutOfRangeException"); } catch (Exception e) { ++iCountErrors; printerr( "Error_600aa! Wrong exception thrown: " + e.ToString()); } strLoc = "Loc_777vy"; iCountTestcases++; try { dTest = new DateTime(2000,03,32,jCal); iCountErrors++; printerr( "Error_700bb! No exception thrown"); } catch (ArgumentOutOfRangeException argexc) { printinfo( "Info_775ad! Caught ArguementOutOfRangeException"); } catch (Exception e) { ++iCountErrors; printerr( "Error_700aa! Wrong exception thrown: " + e.ToString()); } strLoc = "Loc_888vy"; iCountTestcases++; try { dTest = new DateTime(2000,03,14,null); iCountErrors++; printerr( "Error_800bb! No exception thrown"); } catch (ArgumentNullException argexc) { printinfo( "Info_885ad! Caught ArguementNullException"); } catch (Exception e) { ++iCountErrors; printerr( "Error_800aa! Wrong exception thrown: " + e.ToString()); } } catch (Exception exc_general ) { ++iCountErrors; Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy! strLoc=="+ strLoc +", exc_general=="+exc_general.ToString()); } if ( iCountErrors == 0 ) { Console.WriteLine( "paSs. "+s_strTFName+" ,iCountTestcases=="+iCountTestcases.ToString()); return true; } else { Console.WriteLine("FAiL! "+s_strTFName+" ,iCountErrors=="+iCountErrors.ToString()+" , BugNums?: "+s_strActiveBugNums ); return false; } }
// Set up for the tests. protected override void Setup() { calendar = new JulianCalendar(); twoDigitYearMax = 2029; }