public SolarEvents Calculate(int year, int month, int day, double latitude, double longitude, string timezoneName) { double lw = toRad(-longitude); double phi = toRad(latitude); System.DateTimeOffset gregorianDate = new System.DateTimeOffset(year, month, day, 0, 0, 0, System.TimeSpan.Zero); double julianDate = this.ConvertGregorianToJulian(gregorianDate); double d = this.CalculateJulianDays(julianDate); double n = this.CalculateJulianCycle(d, lw); double ds = this.CalculateApproximateTransit(0, lw, n); double M = this.CalculateSolarMeanAnomaly(ds); double C = this.CalculateEquationOfCenter(M); double L = this.CalculateEclipticLongitude(M, C); double dec = this.CalculateDeclination(L); double et = this.CalculateEquationOfTime(M, L); double jNoon = this.CalculateSolarNoon(ds, et); double w = this.CalculateHourAngle(phi, dec); double a = this.CalculateApproximateTransit(w, lw, n); double jSet = this.CalculateSolarNoon(a, et); double jRise = jNoon - (jSet - jNoon); long gSet = this.ConvertJulianToGregorian(jSet); long gRise = this.ConvertJulianToGregorian(jRise); System.TimeZoneInfo timezone = System.TimeZoneInfo.FindSystemTimeZoneById(timezoneName); System.DateTimeOffset sunset = this.ConvertGregorianToDate(gSet, timezone); System.DateTimeOffset sunrise = this.ConvertGregorianToDate(gRise, timezone); return(new SolarEvents { Sunrise = sunrise, Sunset = sunset }); }
public static System.DateTimeOffset ToDate(System.TimeZoneInfo timeZone, System.DateTime gDate, double time) { int hours = (int)System.Math.Floor(time * 24); int minutes = (int)System.Math.Floor((time * 24 * 60) % 60); int seconds = (int)System.Math.Floor((time * 24 * 60 * 60) % 60); return(new System.DateTimeOffset(gDate.Year, gDate.Month, gDate.Day, hours, minutes, seconds, timeZone.GetUtcOffset(gDate))); }
/// <summary> /// the sunrise/sunset for the given calendar date in the given timezone at the given location. /// Accounts for DST. /// </summary> /// <param name="year">Calendar year in timezone</param> /// <param name="month">Calendar month in timezone</param> /// <param name="day">Calendar day in timezone</param> /// <param name="latitude">Latitude of location in degrees</param> /// <param name="longitude">Longitude of location in degrees</param> /// <param name="timezoneId">Id of the timezone as specified by the .net framework</param> /// <returns></returns> public SolarEvents Calculate(int year, int month, int day, double latitude, double longitude, string timeZoneId) { double lat = latitude; double lng = longitude; System.DateTime gDate = new System.DateTime(year, month, day, 12, 0, 0, System.DateTimeKind.Utc); System.TimeZoneInfo timeZone = System.TimeZoneInfo.FindSystemTimeZoneById(timeZoneId); System.TimeSpan timeZoneOffset = timeZone.GetUtcOffset(gDate); double tzOffHr = timeZoneOffset.TotalHours; double jDate = GregorianToJulian(gDate, tzOffHr); // D double t = JulianCentury(jDate); // G double ml = GeomMeanLongitudeSun(t); // I - deg double ma = GeomMeanAnomalySun(t); // J - deg double eo = EccentricityEarthOrbit(t); // K double eoc = EquationOfCenterSun(ma, t); // L double tl = TrueLongitudeSun(ml, eoc); // M - deg double al = ApparentLongitudeSun(tl, t); // P - deg double oe = MeanObliquityOfEcliptic(t); // Q - deg double oc = ObliquityCorrection(oe, t); // R - deg double d = DeclinationSun(oc, al); // T - deg double eot = EquationOfTime(oc, ml, eo, ma); // V - minutes double ha = HourAngleSunrise(lat, d); // W - Deg double sn = SolarNoon(lng, eot, tzOffHr); // X - LST double sunrise = Sunrise(sn, ha); // Y - LST double sunset = Sunset(sn, ha); // Z - LST System.DateTimeOffset sunriseOffset = ToDate(timeZone, gDate, sunrise); System.DateTimeOffset sunsetOffset = ToDate(timeZone, gDate, sunset); System.Console.WriteLine("timeZoneOffset: " + timeZoneOffset.TotalHours); System.Console.WriteLine("julianDate: " + jDate); System.Console.WriteLine("julianCentury: " + t); System.Console.WriteLine("geomMeanLongitudeSun: " + ml); System.Console.WriteLine("geomMeanAnomalySun: " + ma); System.Console.WriteLine("eccentricityEarthOrbit: " + eo); System.Console.WriteLine("equationOfCenterSun: " + eoc); System.Console.WriteLine("trueLongitudeSun: " + tl); System.Console.WriteLine("solarApparentLongitude: " + al); System.Console.WriteLine("meanObliquityOfEcliptic: " + oe); System.Console.WriteLine("obliquityCorrection: " + oc); System.Console.WriteLine("equationOfTime: " + eot); System.Console.WriteLine("solarDecline: " + d); System.Console.WriteLine("hourAngleSunrise: " + ha); System.Console.WriteLine("solarNoon: " + sn); System.Console.WriteLine("sunrise: " + sunrise); System.Console.WriteLine("sunset: " + sunset); return(new SolarEvents { Sunrise = sunriseOffset, Sunset = sunsetOffset }); }
/// <summary> /// </summary> /// <param name="settings"></param> public SessionSchedule(QuickFix.Dictionary settings) { this.WeeklySession = false; if (!settings.Has(SessionSettings.START_DAY) && settings.Has(SessionSettings.END_DAY)) { throw new QuickFix.ConfigError("EndDay used without StartDay"); } if (settings.Has(SessionSettings.START_DAY) && !settings.Has(SessionSettings.END_DAY)) { throw new QuickFix.ConfigError("StartDay used without EndDay"); } if (settings.Has(SessionSettings.START_DAY) && settings.Has(SessionSettings.END_DAY)) { StartDay = settings.GetDay(SessionSettings.START_DAY); EndDay = settings.GetDay(SessionSettings.END_DAY); WeeklySession = true; } if (settings.Has(SessionSettings.USE_LOCAL_TIME)) { UseLocalTime = settings.GetBool(SessionSettings.USE_LOCAL_TIME); } if (settings.Has(SessionSettings.TIME_ZONE)) { if (UseLocalTime) { throw new ConfigError( SessionSettings.TIME_ZONE + " conflicts with " + SessionSettings.USE_LOCAL_TIME); } string id = settings.GetString(SessionSettings.TIME_ZONE); TimeZone = System.TimeZoneInfo.FindSystemTimeZoneById(id); } try { this.StartTime = System.TimeSpan.Parse( settings.GetString(SessionSettings.START_TIME)); this.EndTime = System.TimeSpan.Parse( settings.GetString(SessionSettings.END_TIME)); } catch (System.FormatException e) { throw new ConfigError(e.Message); } }
// http://stackoverflow.com/questions/3407575/retrieving-oldest-commit-with-jgit public virtual void GetOldestCommit(string path) { NGit.Revwalk.RevCommit c = null; NGit.Api.Git repository = NGit.Api.Git.Open(path); try { NGit.Revwalk.RevWalk rw = new NGit.Revwalk.RevWalk(repository.GetRepository()); NGit.AnyObjectId headid = repository.GetRepository().Resolve(NGit.Constants.HEAD); NGit.Revwalk.RevCommit root = rw.ParseCommit(headid); string msg1 = root.GetFullMessage(); rw.Sort(NGit.Revwalk.RevSort.REVERSE); rw.MarkStart(root); c = rw.Next(); // repository.GetRepository(). } catch (System.Exception ex) { System.Console.WriteLine(ex.Message); } string msg2 = c.GetFullMessage(); // Get author NGit.PersonIdent authorIdent = c.GetAuthorIdent(); System.DateTime authorDate = authorIdent.GetWhen(); System.TimeZoneInfo authorTimeZone = authorIdent.GetTimeZone(); NGit.PersonIdent committerIdent = c.GetCommitterIdent(); // http://stackoverflow.com/questions/12608610/how-do-you-get-the-author-date-and-commit-date-from-a-jgit-revcommit System.Console.WriteLine(authorIdent); System.Console.WriteLine(authorDate); System.Console.WriteLine(authorTimeZone); System.Console.WriteLine(committerIdent); CloseRepository(repository); }
/// <summary> /// Converts a time to the time in a particular time zone. /// </summary> /// <param name="this">The date and time to convert.</param> /// <param name="destinationTimeZone">The time zone to convert to.</param> /// <returns>The date and time in the destination time zone.</returns> public static System.DateTime ConvertTime(this System.DateTime @this, System.TimeZoneInfo destinationTimeZone) { return(System.TimeZoneInfo.ConvertTime(@this, destinationTimeZone)); }
private System.DateTimeOffset ConvertGregorianToDate(long timestamp, System.TimeZoneInfo timezone) { return(System.TimeZoneInfo.ConvertTime(System.DateTimeOffset.FromUnixTimeSeconds(timestamp), timezone)); }
/// <summary> /// Converts the time in a specified time zone to Coordinated Universal Time (UTC). /// </summary> /// <param name="this">The date and time to convert.</param> /// <param name="sourceTimeZone">The time zone of .</param> /// <returns> /// The Coordinated Universal Time (UTC) that corresponds to the parameter. The object's property is /// always set to . /// </returns> public static System.DateTime ConvertTimeToUtc(this System.DateTime @this, System.TimeZoneInfo sourceTimeZone) { return(System.TimeZoneInfo.ConvertTimeToUtc(@this, sourceTimeZone)); }
/// <summary> /// Converts a time to the time in a particular time zone. /// </summary> /// <param name="dateTimeOffset">The date and time to convert.</param> /// <param name="destinationTimeZone">The time zone to convert to.</param> /// <returns>The date and time in the destination time zone.</returns> public static System.DateTimeOffset ConvertTime(this System.DateTimeOffset dateTimeOffset, System.TimeZoneInfo destinationTimeZone) { return(System.TimeZoneInfo.ConvertTime(dateTimeOffset, destinationTimeZone)); }