public void testDayNameFromConvertedDateToAD1() { EnglishDate english_date = new EnglishDate(); string nep_date = "11/10/2070"; Assert.AreEqual("saturday", dc.ToAD(nep_date).dayName.ToLower()); nep_date = "01/01/2013"; Assert.AreEqual("friday", dc.ToAD(nep_date).dayName.ToLower()); nep_date = "12/10/2000"; Assert.AreEqual("wednesday", dc.ToAD(nep_date).dayName.ToLower()); }
public void testDayNumberFromConvertedDateToAD() { EnglishDate english_date = new EnglishDate(); string nep_date = "11/10/2070"; Assert.AreEqual(7, dc.ToAD(nep_date).dayNumber); nep_date = "01/01/2013"; Assert.AreEqual(6, dc.ToAD(nep_date).dayNumber); nep_date = "12/10/2000"; Assert.AreEqual(4, dc.ToAD(nep_date).dayNumber); }
///<summary>Converts this Hebrew date to its string representation using a custom format string.</summary> ///<param name="format">A DateTime format string.</param> ///<returns>A Hebrew date string.</returns> public string ToString(string format) { return(EnglishDate.ToString(format, culture)); }
///<summary>Returns the hash code for this instance.</summary> ///<returns>A 32-bit signed integer hash code.</returns> public override int GetHashCode() { return(EnglishDate.GetHashCode()); }
///<summary>Checks whether this Hebrew date is equal to another Hebrew date.</summary> ///<param name="other">The Hebrew date to compare to.</param> ///<returns>True if the dates are equal.</returns> public bool Equals(HebrewDate other) { return(EnglishDate.Equals(other.EnglishDate)); }
///<summary>Compares this Hebrew date to another Hebrew date.</summary> ///<param name="other">The date to compare to.</param> ///<returns>A signed number indicating the relative values of this instance and the value parameter. </returns> public int CompareTo(HebrewDate other) { return(EnglishDate.CompareTo(other.EnglishDate)); }
public EnglishDate ToAD(string gDate) { int def_eyy = 0; int def_emm = 0; int def_edd = 0; int def_nyy = 0; int total_eDays = 0; int total_nDays = 0; int a = 0; int m = 0; int y = 0; int i = 0; int j = 0; int k = 0; //split nepali dates to get its year,month and day System.String[] userDateParts = gDate.Split(new[] { "/" }, StringSplitOptions.None); int mm = int.Parse(userDateParts[0]); int dd = int.Parse(userDateParts[1]); int yy = int.Parse(userDateParts[2]); //check if day and month in user input value is valid or not if (mm > 12) { throw new Exception("Month value cannot be greater than 12."); } if (nepaliDateData.getLastDayOfMonthNep(yy, mm) < dd) { throw new Exception(dateFunctions.GetNepaliMonth(mm) + " of the year " + yy + " doesnot have " + dd + " days."); } //get starting nepali and english date for conversion //Initialize english date Tuple <int, int[]> initializationDates = conversionStartDateData.getClosestEnglishDateAndNepaliDateToAD(yy); int nepali_init_date = initializationDates.Item1; int[] english_init_date = initializationDates.Item2; //Initialize english date //def_eyy = 1943; //def_emm = 4; //def_edd = 13; def_eyy = english_init_date[0]; def_emm = english_init_date[1]; def_edd = english_init_date[2]; //Equivalent nepali date // def_nyy = 2000; def_nyy = nepali_init_date; //Initializations total_eDays = 0; total_nDays = 0; a = 0; m = 0; i = 0; // k = 0; k = nepali_init_date; int[] month = new int[] { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; int[] lmonth = new int[] { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; while ((i < (yy - def_nyy))) { j = 1; while ((j <= 12)) { total_nDays += nepaliDateData.getLastDayOfMonthNep(k, j); j += 1; } i += 1; k += 1; } j = 1; while ((j < mm)) { total_nDays += nepaliDateData.getLastDayOfMonthNep(k, j); j += 1; } total_nDays += dd; total_eDays = def_edd; m = def_emm; y = def_eyy; while ((!(total_nDays == 0))) { if ((dateFunctions.IsLeapYear(y))) { a = lmonth[m]; } else { a = month[m]; } total_eDays += 1; if ((total_eDays > a)) { m += 1; total_eDays = 1; if ((m > 12)) { y += 1; m = 1; } } total_nDays -= 1; } EnglishDate eng_date = new EnglishDate(); eng_date.engDay = total_eDays; eng_date.engDaysInMonth = a; eng_date.engMonth = m; eng_date.engYear = y; eng_date.dayName = new DateTime(y, m, total_eDays).DayOfWeek.ToString(); //1 is added since we consider first day to be 1 while it is actually 0 eng_date.dayNumber = (int)new DateTime(y, m, total_eDays).DayOfWeek + 1; eng_date.setFormattedDate(y, m, total_eDays); return(eng_date); }
public void setup() { englishDate = new EnglishDate(); }