/// <summary> /// Sub offset /// </summary> public static UniversalTime operator -(UniversalTime date, TimeSpan offset) { var jd = SweDate.DateToJulianDay(date, DateCalendar.Gregorian); jd -= offset.TotalDays; return(SweDate.JulianDayToDate(jd, DateCalendar.Gregorian)); }
/// <summary> /// New date from components /// </summary> public UniversalTime(int year, int month, int day, double hour) : this() { var jd = SweDate.DateToJulianDay(year, month, day, hour, DateCalendar.Julian); SweDate.JulianDayToDate(jd, DateCalendar.Julian, out _Year, out _Month, out _Day, out _Hours, out _Minutes, out _Seconds); }
/// <summary> /// Returns the DateUT of this Julian Day /// </summary> public UniversalTime ToDateUT() { return(SweDate.JulianDayToDate(Value, Calendar)); }
/// <summary> /// Create a new Julian Day from a DateUT /// </summary> /// <param name="date">Date source</param> /// <param name="calendar">Calendar source</param> public JulianDay(UniversalTime date, DateCalendar?calendar = null) : this() { this.Calendar = calendar ?? SweDate.GetCalendar(date.Year, date.Month, date.Day); this.Value = SweDate.DateToJulianDay(date, this.Calendar); }
/// <summary> /// Create a new Julian Day from his value /// </summary> /// <param name="val">The Julian Day value</param> public JulianDay(double val, DateCalendar?calendar = null) : this() { this.Calendar = calendar ?? SweDate.GetCalendar(val); this.Value = val; }
/// <summary> /// To string with format /// </summary> public string ToString(string format, IFormatProvider formatProvider) { if (String.IsNullOrWhiteSpace(format)) { format = DefaultFormat; } System.Globalization.DateTimeFormatInfo dfi = (formatProvider ?? System.Globalization.CultureInfo.CurrentCulture) .GetFormat(typeof(System.Globalization.DateTimeFormatInfo)) as System.Globalization.DateTimeFormatInfo; dfi = dfi ?? System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat; StringBuilder result = new StringBuilder(); int cnt = 0, fl = format.Length; for (int i = 0; i < fl; i++) { char c = format[i]; switch (c) { case '\\': i++; if (i < format.Length) { result.Append(format[i]); } else { result.Append('\\'); } break; case 'd': cnt = 0; while (i < fl && format[i] == 'd') { cnt++; i++; } i--; var jd = SweDate.DateToJulianDay(this); int nd = ((int)SweDate.DayOfWeek(jd)) + 1; if (nd >= 7) { nd -= 7; } if (cnt == 1) { result.Append(this.Day); } else if (cnt == 2) { result.Append(this.Day.ToString("D2")); } else if (cnt == 3) { result.Append(dfi.AbbreviatedDayNames[nd]); } else { result.Append(dfi.DayNames[nd]); } break; case 'M': cnt = 0; while (i < fl && format[i] == 'M') { cnt++; i++; } i--; if (cnt == 1) { result.Append(this.Month); } else if (cnt == 2) { result.Append(this.Month.ToString("D2")); } else if (cnt == 3) { result.Append(dfi.AbbreviatedMonthNames[this.Month - 1]); } else { result.Append(dfi.MonthNames[this.Month - 1]); } break; case 'y': cnt = 0; while (i < fl && format[i] == 'y') { cnt++; i++; } i--; if (cnt == 1) { result.Append(this.Year % 100); } else if (cnt == 2) { result.Append((this.Year % 100).ToString("D2")); } else { result.Append(this.Year); } break; case 'h': cnt = 0; while (i < fl && format[i] == 'h') { cnt++; i++; } i--; if (cnt == 1) { result.Append(this.Hours % 12); } else { result.Append((this.Hours % 12).ToString("D2")); } break; case 'H': cnt = 0; while (i < fl && format[i] == 'H') { cnt++; i++; } i--; if (cnt == 1) { result.Append(this.Hours); } else { result.Append(this.Hours.ToString("D2")); } break; case 'm': cnt = 0; while (i < fl && format[i] == 'm') { cnt++; i++; } i--; if (cnt == 1) { result.Append(this.Minutes); } else { result.Append(this.Minutes.ToString("D2")); } break; case 's': cnt = 0; while (i < fl && format[i] == 's') { cnt++; i++; } i--; if (cnt == 1) { result.Append(this.Seconds); } else { result.Append(this.Seconds.ToString("D2")); } break; case 't': cnt = 0; while (i < fl && format[i] == 't') { cnt++; i++; } i--; String des = this.Hours < 12 ? dfi.AMDesignator : dfi.PMDesignator; if (cnt == 1) { result.Append(des[0]); } else { result.Append(des); } break; //case '/': // result.Append(DateTime.MinValue.ToString("/")); // break; default: result.Append(c); break; } } return(result.ToString()); }
/// <summary> /// Get Date UT from Ephemeris Time /// </summary> public UniversalTime DateUT(EphemerisTime et) { return(SweDate.JulianDayToDate(et.JulianDay.Value, et.JulianDay.Calendar)); }
/// <summary> /// Get Date UT from Julian Day /// </summary> public UniversalTime DateUT(JulianDay jd) { return(SweDate.JulianDayToDate(jd.Value, jd.Calendar)); }