예제 #1
0
 def _given_minute(**kwargs) -> Optional[int]:
     minute = ja_num_to_int(kwargs.get("minute", None))
     if minute is None:
         return None
     if minute < 0 or 59 < minute:
         raise InvalidValueError(
             f"minute must be in 0..59, but {minute} was given.")
     return minute
예제 #2
0
 def _given_hour(**kwargs) -> Optional[int]:
     hour = ja_num_to_int(kwargs.get("hour", None))
     if hour is None:
         return None
     if "ampm" in kwargs.keys():
         hour = ja_hour_to_24_hour(kwargs["ampm"], hour)
     if hour < 0 or 29 < hour:
         raise InvalidValueError(
             f"hour must be in 0..29, but {hour} was given.")
     return hour
예제 #3
0
    def _given_month(self, **kwargs) -> Optional[int]:
        year_month = self._relative_month(**kwargs)
        if year_month is not None:
            self.year = year_month[0]
            return year_month[1]

        month = ja_num_to_int(kwargs.get("month", None))
        if month is None:
            return None
        if month < 1 or 12 < month:
            raise InvalidValueError(
                f"month must be in 1..12, but {month} was given.")

        return month
예제 #4
0
    def _given_day(self, **kwargs) -> Optional[int]:
        year_month_day = self._relative_day(**kwargs)
        if year_month_day is not None:
            self.year = year_month_day[0]
            self.month = year_month_day[1]
            return year_month_day[2]

        day = ja_num_to_int(kwargs.get("day", None))
        if day is None:
            return None
        if day < 1 or 31 < day:
            raise InvalidValueError(
                f"day must be in 1..31, but {day} was given.")
        return day
예제 #5
0
    def _given_year(self, **kwargs) -> Optional[int]:
        year = self._relative_year(**kwargs)
        if year is not None:
            return year

        year_ad = ja_num_to_int(kwargs.get("ad_year", None))

        if "jp_year" not in kwargs.keys():
            return year_ad

        year_jp = jp_year_to_ad_year(kwargs["jp_year"])
        if year_jp is None:
            return year_ad
        elif year_ad is None:
            return year_jp

        if year_jp == year_ad:
            return year_jp
        else:
            raise InvalidValueError(
                f"{kwargs['jp_year']} is not {year_ad}, but {year_jp}.")
예제 #6
0
def test_ja_num_to_int(ja_num, expect):
    assert ja_num_to_int(ja_num) == expect