Пример #1
0
        public string Lunar2Solar(string sDate)
        {
            DateTime dt;

            try {
                dt = new DateTime(Convert.ToInt32(sDate.Substring(0, 4)), Convert.ToInt32(sDate.Substring(4, 2)), Convert.ToInt32(sDate.Substring(6, 2)));
            } catch (Exception) {
                return(sDate);
            }
            bool bExistLeap = false;
            KoreanLunisolarCalendar kr_Lunnar = new KoreanLunisolarCalendar();
            int _lunnarYY = kr_Lunnar.GetYear(dt);
            int _lunnarMM = kr_Lunnar.GetMonth(dt);
            int _lunnarDD = kr_Lunnar.GetDayOfMonth(dt);

            if (kr_Lunnar.GetMonthsInYear(_lunnarYY) > 12)                                 //12보다 큰달은 윤달이 있다는.
            {
                bExistLeap = kr_Lunnar.IsLeapMonth(_lunnarYY, _lunnarMM);                  // 윤달에 대한 true or false
                int intLeap_mm = kr_Lunnar.GetLeapMonth(_lunnarYY);                        //윤달 추출
                if (_lunnarMM >= intLeap_mm)
                {
                    _lunnarMM--;
                }
            }
            return((new DateTime(_lunnarYY, _lunnarMM, _lunnarDD)).ToString("yyyyMMdd"));
        }
Пример #2
0
        ///<inheritdoc/>
        public IEnumerable <PublicHoliday> Get(int year)
        {
            var countryCode = CountryCode.KR;
            var items       = new List <PublicHoliday>();

            var koreanCalendar = new KoreanLunisolarCalendar();

            if (year >= koreanCalendar.MinSupportedDateTime.Year && year < koreanCalendar.MaxSupportedDateTime.Year)
            {
                var leapMonth = koreanCalendar.GetLeapMonth(year);

                var lunarNewYear1 = koreanCalendar.ToDateTime(year, this.MoveMonth(1, leapMonth), 1, 0, 0, 0, 0); //Has substitute holiday
                lunarNewYear1 = lunarNewYear1.Shift(saturday => saturday, sunday => sunday.AddDays(1));

                var lunarNewYear2 = lunarNewYear1.AddDays(+1).Shift(saturday => saturday, sunday => sunday.AddDays(1));
                var lunarNewYear3 = lunarNewYear1.AddDays(-1).Shift(saturday => saturday, sunday => sunday.AddDays(-1));

                var buddhaBday = koreanCalendar.ToDateTime(year, this.MoveMonth(4, leapMonth), 8, 0, 0, 0, 0);

                var chuseok1 = koreanCalendar.ToDateTime(year, this.MoveMonth(8, leapMonth), 14, 0, 0, 0, 0); //Has substitute holiday
                chuseok1 = chuseok1.Shift(saturday => saturday, sunday => sunday.AddDays(1));
                var chuseok2 = chuseok1.AddDays(+1).Shift(saturday => saturday, sunday => sunday.AddDays(1));
                var chuseok3 = chuseok2.AddDays(+1).Shift(saturday => saturday, sunday => sunday.AddDays(1));

                items.Add(new PublicHoliday(lunarNewYear1, "설날", "Lunar New Year", countryCode));
                items.Add(new PublicHoliday(lunarNewYear2, "설날", "Lunar New Year", countryCode));
                items.Add(new PublicHoliday(lunarNewYear3, "설날", "Lunar New Year", countryCode));
                items.Add(new PublicHoliday(buddhaBday, "부처님 오신 날", "Buddha's Birthday", countryCode));
                items.Add(new PublicHoliday(chuseok1, "추석", "Chuseok", countryCode));
                items.Add(new PublicHoliday(chuseok2, "추석", "Chuseok", countryCode));
                items.Add(new PublicHoliday(chuseok3, "추석", "Chuseok", countryCode));
            }

            items.Add(new PublicHoliday(year, 1, 1, "새해", "New Year's Day", countryCode));
            items.Add(new PublicHoliday(year, 3, 1, "3·1절", "Independence Movement Day", countryCode));

            var childrenDay = new DateTime(year, 5, 5).Shift(saturday => saturday.AddDays(2), sunday => sunday.AddDays(1)); //Substitute holiday

            items.Add(new PublicHoliday(childrenDay, "어린이날", "Children's Day", countryCode));                               //Has substitute holiday

            items.Add(new PublicHoliday(year, 6, 6, "현충일", "Memorial Day", countryCode));
            items.Add(new PublicHoliday(year, 8, 15, "광복절", "Liberation Day", countryCode));
            items.Add(new PublicHoliday(year, 10, 3, "개천절", "National Foundation Day", countryCode));
            items.Add(new PublicHoliday(year, 10, 9, "한글날", "Hangul Day", countryCode));
            items.Add(new PublicHoliday(year, 12, 25, "크리스마스", "Christmas Day", countryCode));

            return(items.OrderBy(o => o.Date));
        }
Пример #3
0
 protected void SetUp()
 {
     gcal  = new GregorianCalendar();
     jucal = new JulianCalendar();
     hical = new HijriCalendar();
     hecal = new HebrewCalendar();
     jacal = new JapaneseCalendar();
     tacal = new TaiwanCalendar();
     kcal  = new KoreanCalendar();
     tbcal = new ThaiBuddhistCalendar();
     acal  = new Calendar[] {
         gcal, jucal, hical, hecal, jacal,
         tacal, kcal, tbcal
     };
     clcal = new ChineseLunisolarCalendar();
     tlcal = new TaiwanLunisolarCalendar();
     jlcal = new JapaneseLunisolarCalendar();
     klcal = new KoreanLunisolarCalendar();
 }
Пример #4
0
        public static void Cultures()
        {
            // These classes won't be linked away because of the code.
            //
            // This is to resolve crash at CultureInfo.CurrentCulture
            // when language is set to Thai. See
            // https://github.com/xamarin/Xamarin.Forms/issues/4037

            _ = new ChineseLunisolarCalendar();
            _ = new HebrewCalendar();
            _ = new HijriCalendar();
            _ = new JapaneseCalendar();
            _ = new JapaneseLunisolarCalendar();
            _ = new KoreanCalendar();
            _ = new KoreanLunisolarCalendar();
            _ = new PersianCalendar();
            _ = new TaiwanCalendar();
            _ = new TaiwanLunisolarCalendar();
            _ = new ThaiBuddhistCalendar();
            _ = new UmAlQuraCalendar();
        }
Пример #5
0
        public string Solar2Lunar(string sDate)
        {
            string[] YunDal = new string [] { "190008", "190305", "190604", "190902", "191106", "191405", "191702", "191907", "192205",
                                              "192504", "192802", "193006", "193305", "193603", "193807", "194106", "194404", "194702", "194907",
                                              "195205", "195503", "195708", "196006", "196304", "196603", "196807", "197105", "197404", "197608",
                                              "197906", "198204", "198410", "198706", "199005", "199303", "199508", "199805", "200104", "200402",
                                              "200607", "200905", "201203", "201409", "201705", "202004", "202302", "202506", "202805", "203103",
                                              "203311", "203606", "203905", "204202", "204407", "205003" };
            KoreanLunisolarCalendar kr_Lunnar = new KoreanLunisolarCalendar();
            int    iYear  = Convert.ToInt32(sDate.Substring(0, 4));
            int    iMonth = Convert.ToInt32(sDate.Substring(4, 2));
            int    iDay   = Convert.ToInt32(sDate.Substring(6, 2));
            string str    = sDate.Substring(0, 6);

            if (kr_Lunnar.GetMonthsInYear(iYear) > 12)
            {
                int leapMonth = kr_Lunnar.GetLeapMonth(iYear);
                for (int i = 0; i < YunDal.Count(); i++)
                {
                    if (str == YunDal[i])
                    {
                        iMonth++;
                        break;
                    }
                }
                if (iMonth > leapMonth)
                {
                    iMonth++;
                }
            }
            try {
                return(kr_Lunnar.ToDateTime(iYear, iMonth, iDay, 0, 0, 0, 0).ToString("yyyyMMdd"));
            } catch (Exception) {
                return(sDate);
            }
        }
Пример #6
0
        public static void KoreanLunisolarTest()
        {
            KoreanLunisolarCalendar kls = new KoreanLunisolarCalendar();

            Assert.Equal(1, kls.Eras.Length);
        }
Пример #7
0
        public void GetLeapMonth()
        {
            GregorianCalendar gc = new GregorianCalendar();

            Assert.AreEqual(0, gc.GetLeapMonth(2007), "#1-1");
            Assert.AreEqual(0, gc.GetLeapMonth(2008), "#1-2");
            Assert.AreEqual(0, gc.GetLeapMonth(2100), "#1-3");
            Assert.AreEqual(0, gc.GetLeapMonth(2000), "#1-4");

            JulianCalendar jc = new JulianCalendar();

            Assert.AreEqual(0, jc.GetLeapMonth(2007), "#2-1");
            Assert.AreEqual(0, jc.GetLeapMonth(2008), "#2-2");
            Assert.AreEqual(0, jc.GetLeapMonth(2100), "#2-3");
            Assert.AreEqual(0, jc.GetLeapMonth(2000), "#2-4");
            Assert.AreEqual(0, jc.GetLeapMonth(2009), "#2-5");
            Assert.AreEqual(0, jc.GetLeapMonth(2010), "#2-6");

            HebrewCalendar hc = new HebrewCalendar();

            // 3rd, 6th, 8th, 11th 14th and 17th year in every 19 are leap.
            // 5339 % 19 = 0.
            Assert.AreEqual(0, hc.GetLeapMonth(5343), "#3-1");
            Assert.AreEqual(0, hc.GetLeapMonth(5344), "#3-2");
            Assert.AreEqual(7, hc.GetLeapMonth(5345), "#3-3");
            Assert.AreEqual(0, hc.GetLeapMonth(5346), "#3-4");
            Assert.AreEqual(7, hc.GetLeapMonth(5347), "#3-5");
            Assert.AreEqual(0, hc.GetLeapMonth(5348), "#3-6");
            Assert.AreEqual(0, hc.GetLeapMonth(5349), "#3-7");

            ThaiBuddhistCalendar tc = new ThaiBuddhistCalendar();

            Assert.AreEqual(0, tc.GetLeapMonth(2520), "#4-1");
            Assert.AreEqual(0, tc.GetLeapMonth(2521), "#4-2");
            Assert.AreEqual(0, tc.GetLeapMonth(2522), "#4-3");
            Assert.AreEqual(0, tc.GetLeapMonth(2523), "#4-4");

            ChineseLunisolarCalendar cc = new ChineseLunisolarCalendar();

            Assert.AreEqual(0, cc.GetLeapMonth(2000), "#5-1");
            Assert.AreEqual(5, cc.GetLeapMonth(2001), "#5-2");
            Assert.AreEqual(0, cc.GetLeapMonth(2002), "#5-3");
            Assert.AreEqual(0, cc.GetLeapMonth(2003), "#5-4");
            Assert.AreEqual(3, cc.GetLeapMonth(2004), "#5-5");
            Assert.AreEqual(0, cc.GetLeapMonth(2005), "#5-6");
            Assert.AreEqual(8, cc.GetLeapMonth(2006), "#5-7");
            Assert.AreEqual(0, cc.GetLeapMonth(2007), "#5-8");
            Assert.AreEqual(0, cc.GetLeapMonth(2008), "#5-9");
            Assert.AreEqual(6, cc.GetLeapMonth(2009), "#5-10");
            Assert.AreEqual(0, cc.GetLeapMonth(2010), "#5-11");
            Assert.AreEqual(0, cc.GetLeapMonth(2011), "#5-12");
            Assert.AreEqual(5, cc.GetLeapMonth(2012), "#5-13");
            Assert.AreEqual(0, cc.GetLeapMonth(2013), "#5-14");
            Assert.AreEqual(10, cc.GetLeapMonth(2014), "#5-15");
            Assert.AreEqual(0, cc.GetLeapMonth(2015), "#5-16");
            Assert.AreEqual(0, cc.GetLeapMonth(2016), "#5-17");
            Assert.AreEqual(7, cc.GetLeapMonth(2017), "#5-18");
            Assert.AreEqual(0, cc.GetLeapMonth(2018), "#5-19");
            Assert.AreEqual(0, cc.GetLeapMonth(2019), "#5-20");

            KoreanLunisolarCalendar kc = new KoreanLunisolarCalendar();

            Assert.AreEqual(0, kc.GetLeapMonth(2000), "#6-1");
            Assert.AreEqual(5, kc.GetLeapMonth(2001), "#6-2");
            Assert.AreEqual(0, kc.GetLeapMonth(2002), "#6-3");
            Assert.AreEqual(0, kc.GetLeapMonth(2003), "#6-4");
            Assert.AreEqual(3, kc.GetLeapMonth(2004), "#6-5");
            Assert.AreEqual(0, kc.GetLeapMonth(2005), "#6-6");
            Assert.AreEqual(8, kc.GetLeapMonth(2006), "#6-7");
            Assert.AreEqual(0, kc.GetLeapMonth(2007), "#6-8");
            Assert.AreEqual(0, kc.GetLeapMonth(2008), "#6-9");
            Assert.AreEqual(6, kc.GetLeapMonth(2009), "#6-10");
            Assert.AreEqual(0, kc.GetLeapMonth(2010), "#6-11");
            Assert.AreEqual(0, kc.GetLeapMonth(2011), "#6-12");
            Assert.AreEqual(4, kc.GetLeapMonth(2012));       // off from cn by 1, "#6-13");
            Assert.AreEqual(0, kc.GetLeapMonth(2013), "#6-14");
            Assert.AreEqual(10, kc.GetLeapMonth(2014), "#6-15");
            Assert.AreEqual(0, kc.GetLeapMonth(2015), "#6-16");
            Assert.AreEqual(0, kc.GetLeapMonth(2016), "#6-17");
            Assert.AreEqual(6, kc.GetLeapMonth(2017));       // off from cn by 1, "#6-18");
            Assert.AreEqual(0, kc.GetLeapMonth(2018), "#6-19");
            Assert.AreEqual(0, kc.GetLeapMonth(2019), "#6-20");
        }
Пример #8
0
        public DateTimeFormatter(string dateTimePattern, string calendarName, string amDesignator, string pmDesignator)
        {
            Calendar calendar = null;

            switch (calendarName)
            {
            case "ChineseLunisolarCalendar":
                calendar = new ChineseLunisolarCalendar();
                break;

            case "GregorianCalendar":
                calendar = new GregorianCalendar();
                break;

            case "HebrewCalendar":
                calendar = new HebrewCalendar();
                break;

            case "HijriCalendar":
                calendar = new HijriCalendar();
                break;

            case "JapaneseCalendar":
                calendar = new JapaneseCalendar();
                break;

            case "JapaneseLunisolarCalendar":
                calendar = new JapaneseLunisolarCalendar();
                break;

            case "JulianCalendar":
                calendar = new JulianCalendar();
                break;

            case "KoreanCalendar":
                calendar = new KoreanCalendar();
                break;

            case "KoreanLunisolarCalendar":
                calendar = new KoreanLunisolarCalendar();
                break;

            case "PersianCalendar":
                calendar = new PersianCalendar();
                break;

            case "TaiwanCalendar":
                calendar = new TaiwanCalendar();
                break;

            case "TaiwanLunisolarCalendar":
                calendar = new TaiwanLunisolarCalendar();
                break;

            case "ThaiBuddhistCalendar":
                calendar = new ThaiBuddhistCalendar();
                break;

            case "UmAlQuraCalendar":
                calendar = new UmAlQuraCalendar();
                break;
            }

            Initialize(dateTimePattern, calendar, amDesignator, pmDesignator);
        }
Пример #9
0
 public static void KoreanLunisolarTest()
 {
     KoreanLunisolarCalendar kls = new KoreanLunisolarCalendar();
     Assert.Equal(1, kls.Eras.Length);
 }
Пример #10
0
        public static Calendar GetCalendar(this CalendarEnum self, CultureInfo culture = null)
        {
            Calendar calendar = null;

            switch (self)
            {
            case CalendarEnum.Gregorian:
                calendar = new GregorianCalendar();
                break;

            case CalendarEnum.Hebrew:
                calendar = new HebrewCalendar();
                break;

            case CalendarEnum.UmAlQura:
                calendar = new UmAlQuraCalendar();
                break;

            case CalendarEnum.Hijri:
                calendar = new HijriCalendar();
                break;

            case CalendarEnum.Japanese:
                calendar = new JapaneseCalendar();
                break;

            case CalendarEnum.JapaneseLunisolar:
                calendar = new JapaneseLunisolarCalendar();
                break;

            case CalendarEnum.Julian:
                calendar = new JulianCalendar();
                break;

            case CalendarEnum.Korean:
                calendar = new KoreanCalendar();
                break;

            case CalendarEnum.KoreanLunisolar:
                calendar = new KoreanLunisolarCalendar();
                break;

            case CalendarEnum.Persian:
                calendar = new PersianCalendar();
                break;

            case CalendarEnum.Taiwan:
                calendar = new TaiwanCalendar();
                break;

            case CalendarEnum.TaiwanLunisolar:
                calendar = new TaiwanLunisolarCalendar();
                break;

            case CalendarEnum.ThaiBuddhist:
                calendar = new ThaiBuddhistCalendar();
                break;

            default:
                if (culture == null)
                {
                    culture = System.Threading.Thread.CurrentThread.CurrentCulture;
                }
                calendar = culture.Calendar;
                break;
            }

            return(calendar);
        }