Ejemplo n.º 1
0
        /// <summary>
        /// Convert to <see cref="DailyAnswer"/>
        /// </summary>
        /// <param name="year"></param>
        /// <returns></returns>
        public override DailyAnswer ToDailyAnswer(int year)
        {
            var date = DateTimeFactory.OffsetByWeek(year, 7, 1, DayOfWeek.Monday).AddDays(1);

            var builder = DailyAnswerBuilder.Create(Name, HolidayType).From(date);

            if (Since.HasValue)
            {
                builder.Since(Since.Value);
            }

            if (End.HasValue)
            {
                builder.End(End.Value);
            }

            if (TimeStepValue.HasValue)
            {
                builder.Times(TimeStepValue.Value);
            }

            builder.Country(Country.ToCode(), GetRegionCodeList());

            return(builder.I18N(I18NIdentityCode).Build(year));
        }
Ejemplo n.º 2
0
        /// <inheritdoc />
        public override DailyAnswer ToDailyAnswer(int year)
        {
            var calculationDay = DateTimeFactory.Create(year, 9, 24);

            if (calculationDay.DayOfWeek == DayOfWeek.Sunday)
            {
                calculationDay = DateTimeFactory.FindNextDay(calculationDay, DayOfWeek.Monday);
            }

            var builder = DailyAnswerBuilder
                          .Create(Name, HolidayType)
                          .From(calculationDay);

            if (Since.HasValue)
            {
                builder.Since(Since.Value);
            }

            if (End.HasValue)
            {
                builder.End(End.Value);
            }

            if (TimeStepValue.HasValue)
            {
                builder.Times(TimeStepValue.Value);
            }

            builder.Country(Country.ToCode(), GetRegionCodeList());

            return(builder.I18N(I18NIdentityCode).Build(year));
        }
        /// <inheritdoc />
        public override DailyAnswer ToDailyAnswer(int year)
        {
            //算法一:根据元旦的农历时间算出其所在年份的十二月的最后一天(推荐)
            //算法二:根据指定年的农历大年初一向前倒退一天

            //推荐算法一的原因:
            //元旦通常在农历新年前,因此不存在修正 ChineseYear 的情况

            var date         = ChineseDateInfo.Of(year, 1, 1);
            var chineseMonth = date.ChineseMonth;

            if (chineseMonth < 12)
            {
                //修正到农历十二月
                var offset = 12 - chineseMonth;
                date = date.AddMonths(offset);
            }

            var lastDay   = date.GetDaysInMonth();
            var finalDate = ChineseDateInfo.OfLunar(date.ChineseYear, 12, lastDay);

            //农历十二月的最后一天,得到的是公历时间
            return(DailyAnswerBuilder
                   .Create(Name, HolidayType)
                   .From(finalDate.ToDateTime())
                   .Country(Country.ToCode(), GetRegionCodeList())
                   .I18N(I18NIdentityCode)
                   .Build(finalDate.ChineseYear));
        }
        /// <inheritdoc />
        public override DailyAnswer ToDailyAnswer(int year)
        {
            DateTime calculationDay;

            if (year >= 2007 && year <= 2009)
            {
                calculationDay = DateTimeFactory.FindNextDay(year, 11, 1, DayOfWeek.Tuesday);
            }
            else
            {
                //2010+ first Monday of the September/October school holidays
                //if coincides with Labour day, moves to 2nd Monday
                var facDay = DateTimeFactory.FindNextDay(year, 9, 25, DayOfWeek.Monday);
                if (facDay == DateTimeFactory.FindNextDay(year, 10, 1, DayOfWeek.Monday))
                {
                    facDay = facDay.AddDays(7);
                }
                calculationDay = facDay;
            }

            return(DailyAnswerBuilder
                   .Create(Name, HolidayType)
                   .From(calculationDay)
                   .Country(Country.ToCode(), GetRegionCodeList())
                   .I18N(I18NIdentityCode)
                   .Build(year));
        }
Ejemplo n.º 5
0
        /// <inheritdoc />
        public override DailyAnswer ToDailyAnswer(int year)
        {
            var date = DateTimeFactory.Create(year, 9, 27);

            if (date.IsLeapYear())
            {
                return(null);
            }

            var builder = DailyAnswerBuilder.Create(Name, HolidayType).From(date);

            if (Since.HasValue)
            {
                builder.Since(Since.Value);
            }

            if (End.HasValue)
            {
                builder.End(End.Value);
            }

            if (TimeStepValue.HasValue)
            {
                builder.Times(TimeStepValue.Value);
            }

            builder.I18N(I18NIdentityCode);
            builder.Country(Country.ToCode(), GetRegionCodeList());

            return(builder.Build(year));
        }
Ejemplo n.º 6
0
 /// <inheritdoc />
 public override DailyAnswer ToDailyAnswer(int year)
 {
     return(DailyAnswerBuilder.Create(Name, HolidayType)
            .From(DateTimeFactory.FindLastDay(year, 5, DayOfWeek.Monday))
            .I18N(I18NIdentityCode)
            .Country(Country.ToCode(), GetRegionCodeList())
            .Build(year));
 }
Ejemplo n.º 7
0
        /// <inheritdoc />
        public override DailyAnswer ToDailyAnswer(int year)
        {
            var calculationDay = DateTimeFactory.FindNextDay(year, 4, 19, DayOfWeek.Thursday);

            var builder = DailyAnswerBuilder
                          .Create(Name, HolidayType)
                          .From(calculationDay)
                          .Country(Country.ToCode(), GetRegionCodeList())
                          .I18N(I18NIdentityCode);

            return(builder.Build(year));
        }
Ejemplo n.º 8
0
        /// <inheritdoc />
        public override DailyAnswer ToDailyAnswer(int year)
        {
            var calculationDay = DateTimeFactory.Create(year, 2, 1);

            calculationDay = OccurrenceHelper.FindOccurrenceOfDayOfWeek(calculationDay, DayOfWeek.Monday, 3);

            return(DailyAnswerBuilder
                   .Create(Name, HolidayType)
                   .From(calculationDay)
                   .Country(Country.ToCode(), GetRegionCodeList())
                   .I18N(I18NIdentityCode)
                   .Build(year));
        }
Ejemplo n.º 9
0
        /// <inheritdoc />
        public override DailyAnswer ToDailyAnswer(int year)
        {
            var calculationDay = DateTimeFactory.Create(year, 5, 24);

            while (calculationDay.DayOfWeek != DayOfWeek.Monday)
            {
                calculationDay = calculationDay.AddDays(-1);
            }

            return(DailyAnswerBuilder
                   .Create(Name, HolidayType)
                   .From(calculationDay)
                   .Country(Country.ToCode(), GetRegionCodeList())
                   .I18N(I18NIdentityCode)
                   .Build(year));
        }
        /// <inheritdoc />
        public override DailyAnswer ToDailyAnswer(int year)
        {
            var builder = DailyAnswerBuilder.Create(Name, HolidayType);

            switch (year)
            {
            case 2016:
                builder.From(2016, 8, 25);
                break;

            case 2017:
                builder.From(2017, 8, 14);
                break;

            case 2018:
                builder.From(2018, 9, 2);
                break;

            case 2020:
                builder.From(2020, 8, 11);
                break;

            default:
                builder.From(year, 8, 24);
                break;
            }

            if (Since.HasValue)
            {
                builder.Since(Since.Value);
            }

            if (End.HasValue)
            {
                builder.End(End.Value);
            }

            if (TimeStepValue.HasValue)
            {
                builder.Times(TimeStepValue.Value);
            }

            builder.I18N(I18NIdentityCode);
            builder.Country(Country.ToCode(), GetRegionCodeList());

            return(builder.Build(year));
        }
Ejemplo n.º 11
0
        /// <inheritdoc />
        public override DailyAnswer ToDailyAnswer(int year)
        {
            var calculationDay = DateTimeFactory.Create(year, 1, 1);

            //当元旦为周末时,使用 Region 定义器来定义
            if (WeekendManager.GetWeekendDictionary(CountryCode.GB).IsWeekend(calculationDay))
            {
                return(DailyAnswerBuilder
                       .Create(Name, HolidayType)
                       .From(calculationDay)
                       .Country(Country.ToCode(), GetRegionCodeList())
                       .I18N(I18NIdentityCode)
                       .Build(year));
            }

            return(null);
        }
Ejemplo n.º 12
0
        /// <inheritdoc />
        public override DailyAnswer ToDailyAnswer(int year)
        {
            if ((year - 2) % 6 == 0)
            {
                var date = DateTimeFactory.Create(year, 12, 1)
                           .Shift(saturday => saturday.AddDays(-1), sunday => sunday.AddDays(1));

                return(DailyAnswerBuilder
                       .Create(Name, HolidayType)
                       .From(date)
                       .Country(Country.ToCode(), GetRegionCodeList())
                       .I18N(I18NIdentityCode)
                       .Build(year));
            }

            return(null);
        }
Ejemplo n.º 13
0
        /// <inheritdoc />
        public override DailyAnswer ToDailyAnswer(int year)
        {
            var date   = ChineseDateInfo.Of(year, 4, 1);
            var date15 = date.AddDays(-15);

            while (true)
            {
                if (date15.GetSolarTerm() == "春分")
                {
                    break;
                }
                date   = date.Tomorrow();
                date15 = date15.Tomorrow();
            }

            return(DailyAnswerBuilder.Create(Name, HolidayType).From(date.ToDateTime()).I18N(I18NIdentityCode).Build(year));
        }
Ejemplo n.º 14
0
        /// <inheritdoc />
        public override DailyAnswer ToDailyAnswer(int year)
        {
            DateTime calculationTime;

            if (year == 2012 || year >= 2016)
            {
                calculationTime = DateTimeFactory.FindNextDay(year, 10, 1, DayOfWeek.Monday);
            }
            else
            {
                calculationTime = DateTimeFactory.OffsetByWeek(year, 6, 2, DayOfWeek.Monday);
            }

            return(DailyAnswerBuilder
                   .Create(Name, HolidayType)
                   .From(calculationTime)
                   .Country(Country.ToCode(), GetRegionCodeList())
                   .I18N(I18NIdentityCode)
                   .Build(year));
        }
Ejemplo n.º 15
0
        /// <inheritdoc />
        public override DailyAnswer ToDailyAnswer(int year)
        {
            DateTime calculationDay;

            if (year == 2020)
            {
                //https://www.bbc.co.uk/news/uk-48565417
                calculationDay = DateTimeFactory.FindDay(year, 5, DayOfWeek.Friday, 2);
            }
            else
            {
                calculationDay = DateTimeFactory.OffsetByWeek(year, 5, 2, DayOfWeek.Monday);
            }

            return(DailyAnswerBuilder
                   .Create(Name, HolidayType)
                   .From(calculationDay)
                   .Country(Country.ToCode(), GetRegionCodeList())
                   .I18N(I18NIdentityCode)
                   .Build(year));
        }
Ejemplo n.º 16
0
        /// <inheritdoc />
        public override DailyAnswer ToDailyAnswer(int year)
        {
            var  caculationDate   = DateTimeFactory.Create(year, 12, 26);
            bool isSundayOrMonday =
                caculationDate.DayOfWeek == DayOfWeek.Sunday ||
                caculationDate.DayOfWeek == DayOfWeek.Monday;

            caculationDate = caculationDate.Shift(saturday => saturday.AddDays(2), sunday => sunday.AddDays(1));

            if (isSundayOrMonday)
            {
                caculationDate = caculationDate.AddDays(1);
            }

            return(DailyAnswerBuilder
                   .Create(Name, HolidayType)
                   .From(caculationDate)
                   .Country(Country.ToCode(), GetRegionCodeList())
                   .I18N(I18NIdentityCode)
                   .Build(year));
        }
Ejemplo n.º 17
0
        /// <inheritdoc />
        public override DailyAnswer ToDailyAnswer(int year)
        {
            if ((year - 1) % 4 == 0)
            {
                DailyAnswerBuilder builder;
                if (year >= 1937)
                {
                    builder = DailyAnswerBuilder.Create(Name, HolidayType).From(year, 1, 20);
                }
                else
                {
                    builder = DailyAnswerBuilder.Create(Name, HolidayType).From(year, 3, 4);
                }

                return(builder
                       .Country(Country.ToCode(), GetRegionCodeList())
                       .I18N(I18NIdentityCode)
                       .Build(year));
            }

            return(null);
        }