Example #1
0
        public static YearAndHalfyear PreviousHalfyear(HalfyearKind startHalfyearKind) {
            int year;
            HalfyearKind halfyear;

            PreviousHalfyear(startHalfyearKind, out year, out halfyear);

            return new YearAndHalfyear(year, halfyear);
        }
Example #2
0
 public static DateTime EndTimeOfHalfyear(this int year, HalfyearKind halfyearKind,
                                          int yearStartMonth = TimeSpec.CalendarYearStartMonth)
 {
     return
         (StartTimeOfHalfyear(new DateTime(year, TimeSpec.MonthsPerHalfyear * (int)halfyearKind + 1, 1), yearStartMonth)
          .AddMonths(TimeSpec.MonthsPerYear)
          .Add(TimeSpec.MinNegativeDuration));
 }
Example #3
0
        public static void AddHalfyear(int startYear, HalfyearKind startHalfyearKind, int count, out int year, out HalfyearKind halfyear) {
            int offsetYear = (Math.Abs(count) / TimeSpec.HalfyearsPerYear) + 1;
            int startHalfyearCount = ((startYear + offsetYear) * TimeSpec.HalfyearsPerYear) + ((int)startHalfyearKind - 1);
            int targetHalfyearCount = startHalfyearCount + count;

            year = (targetHalfyearCount / TimeSpec.HalfyearsPerYear) - offsetYear;
            halfyear = (HalfyearKind)((targetHalfyearCount % TimeSpec.HalfyearsPerYear) + 1);
        }
Example #4
0
        public static YearAndHalfyear PreviousHalfyear(HalfyearKind startHalfyearKind)
        {
            int          year;
            HalfyearKind halfyear;

            PreviousHalfyear(startHalfyearKind, out year, out halfyear);

            return(new YearAndHalfyear(year, halfyear));
        }
Example #5
0
        public static YearAndHalfyear AddHalfyear(this HalfyearKind startHalfyearKind, int startYear, int count)
        {
            int          year;
            HalfyearKind halfyear;

            AddHalfyear(startYear, startHalfyearKind, count, out year, out halfyear);

            return(new YearAndHalfyear(year, halfyear));
        }
Example #6
0
        public static void AddHalfyear(int startYear, HalfyearKind startHalfyearKind, int count, out int year, out HalfyearKind halfyear)
        {
            int offsetYear          = (Math.Abs(count) / TimeSpec.HalfyearsPerYear) + 1;
            int startHalfyearCount  = ((startYear + offsetYear) * TimeSpec.HalfyearsPerYear) + ((int)startHalfyearKind - 1);
            int targetHalfyearCount = startHalfyearCount + count;

            year     = (targetHalfyearCount / TimeSpec.HalfyearsPerYear) - offsetYear;
            halfyear = (HalfyearKind)((targetHalfyearCount % TimeSpec.HalfyearsPerYear) + 1);
        }
Example #7
0
        private static TimeRange GetPeriodOf(int baseMonth, int year, HalfyearKind halfyear, int halfyearCount)
        {
            halfyearCount.ShouldBePositive("halfyearCount");

            var yearStart = new DateTime(year, baseMonth, 1);
            var start     = yearStart.AddMonths(((int)halfyear - 1) * TimeSpec.MonthsPerHalfyear);
            var end       = start.AddMonths(halfyearCount * TimeSpec.MonthsPerHalfyear);

            return(new TimeRange(start, end));
        }
Example #8
0
        protected HalfyearTimeRange(int startYear, HalfyearKind startHalfyearKind, int halfyearCount, ITimeCalendar calendar)
            : base(GetPeriodOf(calendar.YearBaseMonth, startYear, startHalfyearKind, halfyearCount), calendar) {
            StartYear = startYear;
            StartHalfyear = startHalfyearKind;

            HalfyearCount = halfyearCount;

            var endYearAndHalfyear = TimeTool.AddHalfyear(startHalfyearKind, startYear, halfyearCount - 1);
            EndYear = endYearAndHalfyear.Year ?? StartYear;
            EndHalfyear = endYearAndHalfyear.Halfyear ?? StartHalfyear;
        }
Example #9
0
        public static int[] GetMonthsOfHalfyear(this HalfyearKind halfyear)
        {
            switch (halfyear)
            {
            case HalfyearKind.First:
                return(TimeSpec.FirstHalfyearMonths);

            case HalfyearKind.Second:
                return(TimeSpec.SecondHalfyearMonths);
            }
            throw new InvalidOperationException("Invalid year halfyear " + halfyear);
        }
Example #10
0
        /// <summary>
        /// 지정한 달력 기준으로 지정된 년도의 반기(전반기/후반기)의 기간
        /// </summary>
        public static TimeSpan Halfyear(int year, HalfyearKind halfyear = HalfyearKind.First, Calendar calendar = null)
        {
            calendar = calendar ?? CurrentCalendar;
            var halfyearMonths = TimeTool.GetMonthsOfHalfyear(halfyear);
            var duration       = TimeSpec.NoDuration;

            foreach (var halfyearMonth in halfyearMonths)
            {
                duration = duration.Add(Month(year, halfyearMonth, calendar));
            }

            return(duration);
        }
Example #11
0
        protected HalfyearTimeRange(int startYear, HalfyearKind startHalfyearKind, int halfyearCount, ITimeCalendar calendar)
            : base(GetPeriodOf(calendar.YearBaseMonth, startYear, startHalfyearKind, halfyearCount), calendar)
        {
            StartYear     = startYear;
            StartHalfyear = startHalfyearKind;

            HalfyearCount = halfyearCount;

            var endYearAndHalfyear = TimeTool.AddHalfyear(startHalfyearKind, startYear, halfyearCount - 1);

            EndYear     = endYearAndHalfyear.Year ?? StartYear;
            EndHalfyear = endYearAndHalfyear.Halfyear ?? StartHalfyear;
        }
Example #12
0
        /// <summary>
        /// 지정한 년도의 반기를 표현하는 문자열을 반환합니다.
        /// </summary>
        /// <param name="year"></param>
        /// <param name="halfyear"></param>
        /// <returns></returns>
        public string GetHalfYearOfYearName(int year, HalfyearKind halfyear)
        {
            switch (YearKind)
            {
            case YearKind.CalendarYear:
                return(TimeStrings.CalendarHalfyearOfYearName(halfyear, year));

            case YearKind.FiscalYear:
                return(TimeStrings.FiscalHalfyearOfYearName(halfyear, year));

            case YearKind.SchoolYear:
                return(TimeStrings.SchoolHalfyearOfYearName(halfyear, year));

            default:
                return(TimeStrings.SystemHalfyearOfYearName(halfyear, year));
            }
        }
Example #13
0
        public void SingleHalfyearsTest()
        {
            const int          startYear     = 2004;
            const HalfyearKind startHalfyear = HalfyearKind.Second;
            var halfyears = new HalfyearRangeCollection(startYear, startHalfyear, 1);

            halfyears.YearBaseMonth.Should().Be(1);
            halfyears.HalfyearCount.Should().Be(1);
            halfyears.StartHalfyear.Should().Be(startHalfyear);
            halfyears.StartYear.Should().Be(startYear);
            halfyears.EndYear.Should().Be(startYear);
            halfyears.EndHalfyear.Should().Be(HalfyearKind.Second);

            var halfyearList = halfyears.GetHalfyears().ToList();

            halfyearList.Count.Should().Be(1);
            halfyearList[0].IsSamePeriod(new HalfyearRange(2004, HalfyearKind.Second)).Should().Be.True();
        }
Example #14
0
        public void SecondCalendarHalfyearsTest()
        {
            const int          startYear     = 2004;
            const HalfyearKind startHalfyear = HalfyearKind.Second;
            const int          halfyearCount = 3;
            var halfyears = new HalfyearRangeCollection(startYear, startHalfyear, halfyearCount);

            halfyears.YearBaseMonth.Should().Be(1);
            halfyears.HalfyearCount.Should().Be(halfyearCount);
            halfyears.StartHalfyear.Should().Be(startHalfyear);
            halfyears.StartYear.Should().Be(startYear);
            halfyears.EndYear.Should().Be(2005);
            halfyears.EndHalfyear.Should().Be(HalfyearKind.Second);

            var halfyearList = halfyears.GetHalfyears().ToList();

            halfyearList.Count.Should().Be(halfyearCount);
            Assert.IsTrue(halfyearList[0].IsSamePeriod(new HalfyearRange(2004, HalfyearKind.Second)));
            Assert.IsTrue(halfyearList[1].IsSamePeriod(new HalfyearRange(2005, HalfyearKind.First)));
            Assert.IsTrue(halfyearList[2].IsSamePeriod(new HalfyearRange(2005, HalfyearKind.Second)));
        }
Example #15
0
 public static void AddHalfyear(HalfyearKind startHalfyearKind, int count, out int year, out HalfyearKind halfyear) {
     AddHalfyear(0, startHalfyearKind, count, out year, out halfyear);
 }
Example #16
0
 public static void NextHalfyear(HalfyearKind startHalfyearKind, out int year, out HalfyearKind halfyear)
 {
     AddHalfyear(startHalfyearKind, 1, out year, out halfyear);
 }
Example #17
0
 public HalfyearRange(int year, HalfyearKind halfyear) : this(year, halfyear, new TimeCalendar()) {}
Example #18
0
 public static void PreviousHalfyear(HalfyearKind startHalfyearKind, out int year, out HalfyearKind halfyear) {
     AddHalfyear(startHalfyearKind, -1, out year, out halfyear);
 }
Example #19
0
 public static string SystemHalfyearName(HalfyearKind halfyear)
 {
     return(Format(SystemHalfYearNameFormat, (int)halfyear));
 }
Example #20
0
 public static YearAndHalfyear AddHalfyear(this HalfyearKind startHalfyearKind, int count)
 {
     return(AddHalfyear(startHalfyearKind, 0, count));
 }
 public HalfyearRangeCollection(int year, HalfyearKind halfyear, int halfyearCount, ITimeCalendar calendar)
     : base(year, halfyear, halfyearCount, calendar) {}
Example #22
0
 public HalfyearRange(int year, HalfyearKind halfyear) : this(year, halfyear, new TimeCalendar())
 {
 }
Example #23
0
 public static string SystemHalfyearName(HalfyearKind halfyear) {
     return Format(SystemHalfYearNameFormat, (int)halfyear);
 }
Example #24
0
 public static string CalendarHalfyearOfYearName(HalfyearKind halfyear, int year) {
     return Format(CalendarHalfyearOfYearNameFormat, (int)halfyear, year);
 }
Example #25
0
 public HalfyearRange(int year, HalfyearKind halfyear, ITimeCalendar calendar) : base(year, halfyear, 1, calendar) {}
Example #26
0
 public static void AddHalfyear(HalfyearKind startHalfyearKind, int count, out int year, out HalfyearKind halfyear)
 {
     AddHalfyear(0, startHalfyearKind, count, out year, out halfyear);
 }
Example #27
0
        private static TimeRange GetPeriodOf(int baseMonth, int year, HalfyearKind halfyear, int halfyearCount) {
            halfyearCount.ShouldBePositive("halfyearCount");

            var yearStart = new DateTime(year, baseMonth, 1);
            var start = yearStart.AddMonths(((int)halfyear - 1) * TimeSpec.MonthsPerHalfyear);
            var end = start.AddMonths(halfyearCount * TimeSpec.MonthsPerHalfyear);

            return new TimeRange(start, end);
        }
Example #28
0
 public HalfyearRangeCollection(int year, HalfyearKind halfyear, int halfyearCount)
     : this(year, halfyear, halfyearCount, new TimeCalendar())
 {
 }
Example #29
0
 public static string CalendarHalfyearOfYearName(HalfyearKind halfyear, int year)
 {
     return(Format(CalendarHalfyearOfYearNameFormat, (int)halfyear, year));
 }
Example #30
0
 public HalfyearRangeCollection(int year, HalfyearKind halfyear, int halfyearCount, ITimeCalendar calendar)
     : base(year, halfyear, halfyearCount, calendar)
 {
 }
Example #31
0
 public static DateTime StartTimeOfHalfyear(this int year, HalfyearKind halfyearKind,
                                            int yearStartMonth = TimeSpec.CalendarYearStartMonth)
 {
     return(StartTimeOfHalfyear(new DateTime(year, TimeSpec.MonthsPerHalfyear * (int)halfyearKind + 1, 1), yearStartMonth));
 }
Example #32
0
 public HalfyearRange(int year, HalfyearKind halfyear, ITimeCalendar calendar) : base(year, halfyear, 1, calendar)
 {
 }
Example #33
0
 public static int StartMonthOfHalfyear(this HalfyearKind half)
 {
     return(((int)half - 1) * TimeSpec.MonthsPerHalfyear + 1);
 }
Example #34
0
 public static string FiscalHalfyearName(HalfyearKind halfyear)
 {
     return(Format(FiscalHalfYearNameFormat, (int)halfyear));
 }
Example #35
0
 public static void PreviousHalfyear(HalfyearKind startHalfyearKind, out int year, out HalfyearKind halfyear)
 {
     AddHalfyear(startHalfyearKind, -1, out year, out halfyear);
 }
Example #36
0
 public static string SchoolHalfyearOfYearName(HalfyearKind halfyear, int year)
 {
     return(Format(SchoolHalfyearOfYearNameFormat, (int)halfyear, year));
 }
Example #37
0
 public static void NextHalfyear(HalfyearKind startHalfyearKind, out int year, out HalfyearKind halfyear) {
     AddHalfyear(startHalfyearKind, 1, out year, out halfyear);
 }
Example #38
0
 public static DateTime StartTimeOfHalfyear(this int year, HalfyearKind halfyearKind,
                                            int yearStartMonth = TimeSpec.CalendarYearStartMonth) {
     return StartTimeOfHalfyear(new DateTime(year, TimeSpec.MonthsPerHalfyear * (int)halfyearKind + 1, 1), yearStartMonth);
 }
Example #39
0
 public static int EndMonthOfHalfyear(this HalfyearKind half)
 {
     return(half.StartMonthOfHalfyear() + TimeSpec.MonthsPerHalfyear - 1);
 }
Example #40
0
 public static string FiscalHalfyearName(HalfyearKind halfyear) {
     return Format(FiscalHalfYearNameFormat, (int)halfyear);
 }
Example #41
0
 public static DateTime EndTimeOfHalfyear(this int year, HalfyearKind halfyearKind,
                                          int yearStartMonth = TimeSpec.CalendarYearStartMonth) {
     return
         StartTimeOfHalfyear(new DateTime(year, TimeSpec.MonthsPerHalfyear * (int)halfyearKind + 1, 1), yearStartMonth)
             .AddMonths(TimeSpec.MonthsPerYear)
             .Add(TimeSpec.MinNegativeDuration);
 }
Example #42
0
 public static string SchoolHalfyearOfYearName(HalfyearKind halfyear, int year) {
     return Format(SchoolHalfyearOfYearNameFormat, (int)halfyear, year);
 }
 public HalfyearRangeCollection(int year, HalfyearKind halfyear, int halfyearCount)
     : this(year, halfyear, halfyearCount, new TimeCalendar()) {}