Esempio n. 1
0
def makeCalendar(yearInput, monthInput):
    global dateFrame
    global c
    for child in dateFrame.winfo_children():
        child.destroy()

    print(yearInput, monthInput)

    title["text"] = "{}년 {}월".format(yearInput, monthInput)
    c = calendar.month(yearInput, monthInput)
    lunar_c = KoreanLunarCalendar()
    # lunar.setSolarDate(2017, 6, 24)
    #print(lunar.LunarIsoFormat())
    dateIndex = c.find('Su')
    c = c[dateIndex + 2:]
    index = 0
    for i in range(6):
        for j in range(7):
            day = c[index:index + 3]
            day = day.replace('\n', '')
            if day.strip() != '':  #day가 비어있지 않으면 음력 추가
                lunar_day = day.strip()
                lunar_day = int(lunar_day)
                lunar_c.setSolarDate(yearInput, monthInput, lunar_day)
                lunar_day = lunar_c.LunarIsoFormat()
                lunar_index = lunar_day.find('-')
                lunar_day = lunar_day[lunar_index + 1:]
                lunar_day = lunar_day.replace('-', '.')
                day = day + '\n' + lunar_day
            name = Button(dateFrame, text=day)
            name.grid(row=i, column=j)
            if index + 3 <= len(c): index += 3
        if index >= len(c): break
    return c
Esempio n. 2
0
    def make_calendar(self):  #달력 만드는 함수
        try:
            for dates in self.m_cal:
                for date in dates:
                    if date == 0:
                        continue
                    self.delete_buttons(date)
            self.delete_buttons
        except AttributeError:
            pass

        year = int(self.year_str_var.get())  #년도 저장
        month = self.month_names.index(self.month_str_var.get())  #월 저장
        self.m_cal = calendar.monthcalendar(year, month)

        for dates in self.m_cal:
            row = self.m_cal.index(dates) + 1
            for date in dates:
                col = dates.index(date)
                if date == 0:
                    continue
                k_calendar = KoreanLunarCalendar()  #음력으로 바꿔주는 코드
                k_calendar.setSolarDate(year, month, date)
                k_day = k_calendar.LunarIsoFormat()

                num = 0
                for a in self.dat2_list:
                    m = int(a[1])
                    d = int(a[2])
                    if m == month and d == int(date):
                        num = num + 1
                self.make_button(str(date), str(row), str(col),
                                 str(k_day.split('-')[1]),
                                 str(k_day.split('-')[2]),
                                 num)  #날짜, 행, 열을 인자로 함수를 넣어줌.
Esempio n. 3
0
class DateConverter(object):
    def __init__(self, year, month, day, lunar):
        self._year = year
        self._month = month
        self._day = day
        self._lunar = lunar
        self._intercalation = None
        self._calendar = KoreanLunarCalendar()

    @property
    def year(self):
        return self._year

    @property
    def month(self):
        return self._month

    @property
    def day(self):
        return self._day

    @property
    def intercalation(self):
        return self._get_intercalation()

    @property
    def solar_day(self):
        return self._get_solar_day()

    @property
    def lunar_day(self):
        return self._get_lunar_day()

    def _get_intercalation(self):
        if self._lunar == True:
            if self._date.year % 4 == 0 or self._date.year % 400 == 0:
                self._intercalation = True
            else:
                self._intercalation = False
        else:
            self._intercalation = None
        return self._intercalation

    def _get_solar_day(self):
        self._calendar.setLunarDate(self._year, self._month, self._day,
                                    self._intercalation)
        solar_date = self._calendar.SolarIsoFormat()
        return solar_date

    def _get_lunar_day(self):
        self._calendar.setSolarDate(self._year, self._month, self._day)
        lunar_date = self._calendar.LunarIsoFormat()
        return lunar_date

    def __del__(self):
        del self._calendar
Esempio n. 4
0
 def _update_internal_state(self, time_date):
     date = dt_util.as_local(time_date).date()
     calendar = KoreanLunarCalendar()
     calendar.setSolarDate(date.year, date.month, date.day)
     lunar_date = calendar.LunarIsoFormat()
     self._state = lunar_date
     self._attribute = {
         'korean_gapja': calendar.getGapJaString(),
         'chinese_gapja': calendar.getChineseGapJaString()
     }
Esempio n. 5
0
def korean_solar_to_lunar(year, month, day):
    calendar = KoreanLunarCalendar()
    is_valid = calendar.setSolarDate(year, month, day)
    if not is_valid:
        raise ValueError(
            "Invalid date for solar date: (year=%r, month=%r, day=%r)" %
            (year, month, day))
    return (calendar.lunarYear, calendar.lunarMonth, calendar.lunarDay)
Esempio n. 6
0
def check_holiday(date):
    is_holiday = False
    year = date[0:4]
    month = date[5:7]
    day = date[8:]
    month_day = month + day

    date = datetime.datetime(int(year), int(month), int(day), 1, 0,
                             0)  # str -> datetime으로 변환

    lunar_calendar = KoreanLunarCalendar()
    lunar_calendar.setSolarDate(int(year), int(month), int(day))
    lunar_month_day = lunar_calendar.LunarIsoFormat()
    lunar_month_day = lunar_month_day[5:7] + lunar_month_day[8:]

    if month_day in WORKING['holidays'] or lunar_month_day in WORKING[
            'lunarHolidays']:
        is_holiday = True
    elif date.weekday() == 5 or date.weekday() == 6:
        is_holiday = True
    elif date.weekday() == 0:
        # 대체공휴일 적용
        yesterday = date - timedelta(days=1)
        yesterday = datetimeToDate(yesterday)
        two_days_ago = date - timedelta(days=2)
        two_days_ago = datetimeToDate(two_days_ago)
        if yesterday in WORKING[
                'alternativeVacation'] or two_days_ago in WORKING[
                    'alternativeVacation']:
            is_holiday = True

    if USE_LUNAR_NEW_YEAR:
        if not is_holiday and int(month) < 4:
            # 음력 1월 1일 전날의 날짜를 특정하기 어려워서 아래의 logic을 사용
            # 12월 29일수도 있고 12월 30일일 수도 있음 윤달이 있으면 단순히 처리하기 쉽지 않음
            tomorrow = date + timedelta(days=1)
            tomorrow = datetimeToDate(tomorrow)
            lunar_calendar.setSolarDate(int(year), int(tomorrow[0:2]),
                                        int(tomorrow[2:4]))
            lunar_month_day = lunar_calendar.LunarIsoFormat()
            lunar_month_day = lunar_month_day[5:7] + lunar_month_day[8:]
            if lunar_month_day == '0101':
                is_holiday = True
    return is_holiday
Esempio n. 7
0
def printInformation(year, is_intercalation=False):
    today = datetime.today()
    year = today.year
    month = today.month
    day = today.day
    calendar = KoreanLunarCalendar()
    calendar.setSolarDate(year, month, day)

    print('Year: {}'.format(year))

    # 할머니: (음) 5/23
    calendar.setLunarDate(year, 5, 23, is_intercalation)
    print('할머니 제사 (음) 5/23')
    print('* Solar: {}'.format(calendar.SolarIsoFormat()))
    print('* Lunar: {}'.format(calendar.LunarIsoFormat()))
    print('* Hangul: {}'.format(calendar.getGapJaString()))
    print('* Hanja: {}'.format(calendar.getChineseGapJaString()))

    calendar.setLunarDate(year, 5, 1, is_intercalation)
    print('초하루 (음) 5/1')
    print('* Solar: {}'.format(calendar.SolarIsoFormat()))
    print('* Lunar: {}'.format(calendar.LunarIsoFormat()))
    print('* Hangul: {}'.format(calendar.getGapJaString()))
    print('* Hanja: {}'.format(calendar.getChineseGapJaString()))

    print('------------------------------')

    # 할아버지: (음) 8/6
    calendar.setLunarDate(year, 8, 6, is_intercalation)
    print('할아버지 제사 (음) 8/6')
    print('* Solar: {}'.format(calendar.SolarIsoFormat()))
    print('* Lunar: {}'.format(calendar.LunarIsoFormat()))
    print('* Hangul: {}'.format(calendar.getGapJaString()))
    print('* Hanja: {}'.format(calendar.getChineseGapJaString()))

    print('초하루 (음) 8/1')
    calendar.setLunarDate(year, 8, 1, is_intercalation)
    print('* Solar: {}'.format(calendar.SolarIsoFormat()))
    print('* Lunar: {}'.format(calendar.LunarIsoFormat()))
    print('* Hangul: {}'.format(calendar.getGapJaString()))
    print('* Hanja: {}'.format(calendar.getChineseGapJaString()))
Esempio n. 8
0
 def from_solar_datetime(cls, dt):
     dt = cls.astimezone_kst(dt)
     calendar = KoreanLunarCalendar()
     valid = calendar.setSolarDate(dt.year, dt.month, dt.day)
     if not valid:
         raise ValueError('Invalid solar date')
     dt = cls(
         calendar.lunarYear,
         calendar.lunarMonth,
         calendar.lunarDay,
         dt.hour,
         dt.minute,
         dt.second,
         dt.microsecond,
         tzinfo=cls.kst,
         is_intercalation=calendar.isIntercalation,
     )
     return dt
Esempio n. 9
0
 def solar_to_lunar(self, solarDate):
     calendar = KoreanLunarCalendar()
     calendar.setSolarDate(solarDate.year, solarDate.month, solarDate.day)
     lunar = calendar.LunarIsoFormat()
     lunar = lunar.replace(' Intercalation', INTERCALATION)
     return lunar
class CalendarCalculator:
    def __init__(self):
        self.lunarCalculator = KoreanLunarCalendar()

    def isLunarMonth(self, year: int) -> bool:
        '''
        Judge lunar month
        :param year: the year
        :return: boolean type data
        '''
        if year % 4 == 0 and year % 100 != 0 or year % 400 == 0:
            return True

        #if ((i % 4 == 0 & & i % 100 != 0) | | i % 400 == 0)

        #elif year % 400 == 0:
        #return True

        else:
            return False

    def toSolarDate(self, year: int, month: int, day: int):
        '''
        Convert from lunar date to solar date
        :param year: lunar date of year
        :param month: lunar date of month
        :param day: lunar date of day
        :return: lunar date with tuple which have 3 arguments
        '''
        self.lunarCalculator.setLunarDate(year, month, day,
                                          self.isLunarMonth(year))
        formatedDate = self.formatDate(self.lunarCalculator.SolarIsoFormat())
        return formatedDate

    def toLunarDate(self, year: int, month: int, day: int) -> tuple:
        '''
        Convert from solar date to lunar date
        :param year: solar date of year
        :param month: solar date of month
        :param day: solar date of day
        :return: solar date with tuple which have 3 arguments
        '''
        self.lunarCalculator.setSolarDate(year, month, day)
        formatedDate = self.formatDate(self.lunarCalculator.LunarIsoFormat())
        return formatedDate

    def formatDate(self, date: str) -> tuple:
        '''
        Format string type to tuple
        :param date: string type value date ex) '2018-12-9'
        :return: tuple which have 3 arguments ex) (2018, 12, 9)
        '''
        return tuple(map(int, date.split('-')))

    def getSolarHoliday(self, year: int, month: int, day: int,
                        holiday: str) -> tuple:
        rawDate = self.toSolarDate(year, month, day)
        rawDate = (rawDate[1], rawDate[2], holiday)
        return rawDate

    def getToLunarDate(self, year, month, day):
        self.lunarCalculator.setSolarDate(year, month, day)
        return self.lunarCalculator.LunarIsoFormat()