Exemplo n.º 1
0
        /// <summary>
        /// Creates a new object that is a copy of the current instance.
        /// <b>Note:</b> If the <seealso cref="Zmanim.TimeZone.ITimeZone"/> in the cloned
        /// <see cref="GeoLocation"/> will be changed from the
        /// original, it is critical that
        /// <see cref="DateWithLocation"/>.
        /// <see cref="TimeZone">TimeZone</see>
        /// be set in order for the AstronomicalCalendar to output times in the
        /// expected offset after being cloned.
        /// </summary>
        /// <returns>
        /// A new object that is a copy of this instance.
        /// </returns>
        public virtual object Clone()
        {
            var clone = (AstronomicalCalendar)MemberwiseClone();

            clone.DateWithLocation       = (IDateWithLocation)DateWithLocation.Clone();
            clone.AstronomicalCalculator = (AstronomicalCalculator)AstronomicalCalculator.Clone();
            return(clone);
        }
Exemplo n.º 2
0
        /// <summary>
        /// A method that will roll the sunset time forward a day if sunset occurs
        /// before sunrise. This will typically happen when a timezone other than the
        /// local timezone is used (calculating Los Angeles sunset using a GMT
        /// timezone for example). In this case the sunset date will be incremented
        /// to the following date.
        /// </summary>
        /// <param name="sunset">the sunset date to adjust if needed</param>
        /// <param name="sunrise">the sunrise to compare to the sunset</param>
        /// <returns>
        /// the adjusted sunset date.
        /// If the calculation can't be computed such as in the Arctic
        /// Circle where there is at least one day a year where the sun does
        /// not rise, and one where it does not set, a null will be returned.
        /// See detailed explanation on top of the page.
        /// </returns>
        private DateTime?GetAdjustedSunsetDate(DateTime?sunset, DateTime?sunrise)
        {
            if (sunset == null || sunrise == null || sunrise.Value.CompareTo(sunset) < 0)
            {
                return(sunset);
            }

            var clonedDateWithLocation = (IDateWithLocation)DateWithLocation.Clone();

            clonedDateWithLocation.Date = sunset.Value;
            clonedDateWithLocation.Date.AddDays(1);

            return(clonedDateWithLocation.Date);
        }