/// <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);
        }
Exemple #2
0
        /// <summary>
        /// Returns a hash code for this instance.
        /// </summary>
        /// <returns>
        /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
        /// </returns>
        public override int GetHashCode()
        {
            int result = 17;

            result  = 37 * result + GetType().GetHashCode(); // needed or this and subclasses will return identical hash
            result += 37 * result + DateWithLocation.GetHashCode();
            result += 37 * result + DateWithLocation.Location.GetHashCode();
            result += 37 * result + AstronomicalCalculator.GetHashCode();
            return(result);
        }
Exemple #3
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);
        }
Exemple #4
0
        /// <summary>
        /// Determines whether the specified <see cref="System.Object"/> is equal to this instance.
        /// </summary>
        /// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param>
        /// <returns>
        ///     <c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.
        /// </returns>
        /// <exception cref="T:System.NullReferenceException">
        /// The <paramref name="obj"/> parameter is null.
        /// </exception>
        public override bool Equals(object obj)
        {
            if (this == obj)
            {
                return(true);
            }
            if (!(obj is AstronomicalCalendar))
            {
                return(false);
            }
            var aCal = (AstronomicalCalendar)obj;

            return(DateWithLocation.Equals(aCal.DateWithLocation) && DateWithLocation.Location.Equals(aCal.DateWithLocation.Location) &&
                   AstronomicalCalculator.Equals(aCal.AstronomicalCalculator));
        }
Exemple #5
0
        /// <summary>
        /// Determines whether the specified <see cref="System.Object"/> is equal to this instance.
        /// </summary>
        /// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param>
        /// <returns>
        ///     <c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.
        /// </returns>
        /// <exception cref="T:System.NullReferenceException">
        /// The <paramref name="obj"/> parameter is null.
        /// </exception>
        public override bool Equals(object obj)
        {
            if (this == obj)
            {
                return(true);
            }
            if (!(obj is ZmanimCalendar))
            {
                return(false);
            }
            var zCal = (ZmanimCalendar)obj;

            // return getCalendar().ToMillisecondsFromEpoch().equals(zCal.getCalendar().ToMillisecondsFromEpoch())
            return(DateWithLocation.Equals(zCal.DateWithLocation) && DateWithLocation.Location.Equals(zCal.DateWithLocation.Location) &&
                   AstronomicalCalculator.Equals(zCal.AstronomicalCalculator));
        }