public UDNRecord(UDN udn, UDNCalendarType calendar, string description) { Calendar = calendar; Description = description; Value = udn; StrVal = Value.ToString(); }
public UDNRecord(UDNCalendarType calendar, int year, int month, int day, string description) { Calendar = calendar; Description = description; Value = new UDN(calendar, year, month, day); StrVal = Value.ToString(); }
public date(UDNCalendarType calendar, int year, int month, int day) { Calendar = calendar; Year = year; Month = month; Day = day; }
protected override void DateChanged() { int year = fYear; if (year == UNKNOWN_YEAR) { year = UDN.UnknownYear; } else { if (fYearBC) { year = -year; } } UDNCalendarType udnCalendar = UDNCalendars[(int)fCalendar]; fUDN = new UDN(udnCalendar, year, fMonth, fDay); }
/// <summary> /// Public constructor. /// </summary> /// <param name="calendar"></param> /// <param name="year"></param> /// <param name="month"></param> /// <param name="day"></param> public UDN(UDNCalendarType calendar, int year, int month, int day) { fValue = CreateVal(calendar, year, month, day); }
/// <summary> /// Creates a new UDN instance that represents a date near the specified date in the specified /// <paramref name="calendar"/>.</summary> /// <param name="calendar">Source calendar. The <paramref name="year"/>, <paramref name="month"/> and /// <paramref name="day"/> are in this calendar.</param> /// <param name="year">Year number. Pass `UnknownYear` constant when year is unknown. /// This method DOES NOT check that `year` is inside a valid range. It's duty of a caller.</param> /// <param name="month">Month number. Pass `UnknownMonth` constant when month is unknown. /// This method DOES NOT check that `month` is inside a valid range. It's duty of a caller.</param> /// <param name="day">Day number. Pass `UnknownDay` constant when day is unknown. /// This method DOES NOT check that `day` is inside a valid range. It's duty of a caller.</param> /// <returns>UDN object representing a date near the specified one.</returns> public static UDN CreateApproximate(UDNCalendarType calendar, int year, int month, int day) { return(new UDN(CreateVal(calendar, year, month, day) | ApproximateDate)); }
/// <summary> /// Creates a new UDN instance that represents a date after the specified date in the specified /// <paramref name="calendar"/>.</summary> /// <param name="calendar">Source calendar. The <paramref name="year"/>, <paramref name="month"/> and /// <paramref name="day"/> are in this calendar.</param> /// <param name="year">Year number. Pass `UnknownYear` constant when year is unknown. /// This method DOES NOT check that `year` is inside a valid range. It's duty of a caller.</param> /// <param name="month">Month number. Pass `UnknownMonth` constant when month is unknown. /// This method DOES NOT check that `month` is inside a valid range. It's duty of a caller.</param> /// <param name="day">Day number. Pass `UnknownDay` constant when day is unknown. /// This method DOES NOT check that `day` is inside a valid range. It's duty of a caller.</param> /// <returns>UDN object representing a date after the specified one.</returns> public static UDN CreateAfter(UDNCalendarType calendar, int year, int month, int day) { return(new UDN(CreateVal(calendar, year, month, day) | DateAfter)); }
/// <summary> /// Calculates Julian day nubmer (JDN, https://en.wikipedia.org/wiki/Julian_day) using the specified date in /// the specified <paramref name="calendar"/>. /// Return value of this method ain't a usual JDN. See Returns section for more information. /// </summary> /// <param name="calendar">Source calendar. The <paramref name="year"/>, <paramref name="month"/> and /// <paramref name="day"/> are in this calendar.</param> /// <param name="year">Year number. Pass `UnknownYear` constant when year is unknown. /// This method DOES NOT check that `year` is inside a valid range. It's duty of a caller.</param> /// <param name="month">Month number. Pass `UnknownMonth` constant when month is unknown. /// This method DOES NOT check that `month` is inside a valid range. It's duty of a caller.</param> /// <param name="day">Day number. Pass `UnknownDay` constant when day is unknown. /// This method DOES NOT check that `day` is inside a valid range. It's duty of a caller.</param> /// <returns>Masked Julian day nubmer. See description of the <see cref="fValue"/> member for detailed /// information about masked JDN value. /// /// This method doesn't change the 27th and 28th bit ("date before" and "date after"). /// </returns> private static int CreateVal(UDNCalendarType calendar, int year, int month, int day) { int result = 0; /* * @ruslangaripov: * * The next conversation assume that `UnknownYear` member is 0. * * If all the `CalendarConverter::{calendar type}_to_jd` functions guarantee valid JDN for 0th year, we can * safely use the following code: * * int uYear = year; * * But if at least one of `CalendarConverter::{calendar type}_to_jd` functions fails on 0th year (read: * gives incorrect JDN) we HAVE TO use code like this: * * int uYear = (UnknownYear != year) ? year : 1; * * Here `1` is the first valid year for an algorithm that calculates JDN. I believe any such calculation * succeeds doing such calculation with 1st year. * * Wikipedia says that "For the year (Y) astronomical year numbering is used", and therefore I currently * stick with "0th year always valid for calculation JDN". And therefore, a * `CalendarConverter::{calendar type}_to_jd` succeeds with `UnknownYear`: * * int result = (int) (CalendarConverter::{calendar type}_to_jd(UnknownYear, uMonth, uDay)); * * `result` after the code from above is a valid JDN. */ int uYear = year; int uMonth = Math.Max(UnknownMonth + 1, month); int uDay = Math.Max(UnknownDay + 1, day); switch (calendar) { case UDNCalendarType.ctGregorian: result = CalendarConverter.gregorian_to_jd2(uYear, uMonth, uDay); // fixed break; case UDNCalendarType.ctJulian: result = CalendarConverter.julian_to_jd2(uYear, uMonth, uDay); // fixed break; case UDNCalendarType.ctHebrew: result = CalendarConverter.hebrew_to_jd3(uYear, uMonth, uDay); // fixed to the 3rd variant break; case UDNCalendarType.ctIslamic: result = CalendarConverter.islamic_to_jd3(uYear, uMonth, uDay); // fixed to the 3rd variant break; } if (UnknownYear == year) { result |= IgnoreYear; } if (UnknownMonth + 1 > month) { result |= IgnoreMonth; } if (UnknownDay + 1 > day) { result |= IgnoreDay; } return(result); }