Beispiel #1
0
        private static Func <ExactDateInfo, ExactDateInfo> NextTickDateForYears(
            Duration tickDuration)
        {
            var oneYear  = Duration.Zero.AddYears(1);
            var eraStart = ExactDateInfo.AnnoDomini(1, 1, 1, 0);

            return(prevTickDate =>
            {
                if (tickDuration > oneYear &&
                    prevTickDate == eraStart)
                {
                    return prevTickDate + tickDuration - oneYear;
                }

                return prevTickDate + tickDuration;
            });
        }
Beispiel #2
0
        /// <summary>
        /// Gets date corresponding to this duration
        /// after Christ birth.
        /// </summary>
        public ExactDateInfo GetDateAfterChristBirth()
        {
            var duration = _hours;

            var era = duration >= 0
                ? Era.AnnoDomini
                : Era.BeforeChrist;

            if (era == Era.AnnoDomini)
            {
                var years = duration / HoursInYear;

                duration -= HoursInYear * years;

                years += 1;

                var months = Convert.ToInt32(duration / HoursInMonth);

                duration -= HoursInMonth * months;

                months += 1;

                var days = Convert.ToInt32(duration / HoursInDay);

                duration -= HoursInDay * days;

                days += 1;

                FixDate(ref years, ref months, ref days);

                var hours = Convert.ToInt32(duration);

                return(ExactDateInfo.AnnoDomini(years, months, days, hours));
            }
            else
            {
                var years = duration / HoursInYear;

                if (duration != years * HoursInYear)
                {
                    years -= 1;
                }

                duration -= HoursInYear * years;

                years = -years;

                var months = Convert.ToInt32(duration / HoursInMonth);

                duration -= HoursInMonth * months;

                months += 1;

                var days = Convert.ToInt32(duration / HoursInDay);

                duration -= HoursInDay * days;

                days += 1;

                var hours = Convert.ToInt32(duration);

                return(ExactDateInfo.BeforeChrist(years, months, days, hours));
            }
        }