Skip to content

Commit

Permalink
Merge pull request #27 from kinegratii/develop
Browse files Browse the repository at this point in the history
Release v3.4.3
  • Loading branch information
kinegratii authored Feb 1, 2021
2 parents 8e64e43 + ba4379b commit c8fb6e2
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ print(names) # ['Alice', 'Bob', 'Charlie']
```
The MIT License (MIT)
Copyright (c) 2015-2020 kinegratii
Copyright (c) 2015-2021 kinegratii
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand Down
2 changes: 1 addition & 1 deletion borax/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# coding=utf8

__version__ = '3.4.2'
__version__ = '3.4.3'
__author__ = 'kinegratii'
18 changes: 7 additions & 11 deletions borax/calendars/lunardate.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
EncoderMixin, f_year, f_month, f_day, f_leap
)

from typing import Optional, Iterator, Tuple, Union
from typing import Optional, Iterator, Tuple

__all__ = ['LunarDate', 'LCalendars', 'InvalidLunarDateError']

Expand All @@ -19,11 +19,7 @@ class InvalidLunarDateError(ValueError):
pass


# Typing

Leap = Union[int, bool]

# Constants
# Constants

MIN_LUNAR_YEAR = 1900
MAX_LUNAR_YEAR = 2100
Expand Down Expand Up @@ -128,7 +124,7 @@ def iter_year_month(year: int) -> Iterator[Tuple[int, int, int]]:
return _iter_year_month(YEAR_INFOS[year - MIN_LUNAR_YEAR])

@staticmethod
def ndays(year: int, month: Optional[int] = None, leap: Leap = False) -> int:
def ndays(year: int, month: Optional[int] = None, leap: int = 0) -> int:
_check_year_range(year)
if month is None:
return YEAR_DAYS[year - MIN_LUNAR_YEAR]
Expand Down Expand Up @@ -181,7 +177,7 @@ def delta(date1, date2):

# offset <----> year, day_offset <----> year, month, day, leap

def offset2ymdl(offset: int) -> Tuple[int, int, int, Leap]:
def offset2ymdl(offset: int) -> Tuple[int, int, int, int]:
def _o2mdl(_year_info, _offset):
for _month, _days, _leap in _iter_year_month(_year_info):
if _offset < _days:
Expand Down Expand Up @@ -368,7 +364,7 @@ def get_gz_cn(offset: int) -> str:
class LunarDate(EncoderMixin):
fields = [f_year, f_month, f_day, f_leap]

def __init__(self, year: int, month: int, day: int, leap: Leap = False):
def __init__(self, year: int, month: int, day: int, leap: int = 0):
offset = ymdl2offset(year, month, day, leap)
self._year = year
self._month = month
Expand All @@ -390,7 +386,7 @@ def day(self) -> int:
return self._day

@property
def leap(self) -> bool:
def leap(self) -> int:
return self._leap

@property
Expand Down Expand Up @@ -488,7 +484,7 @@ def after(self, day_delta: int = 1) -> 'LunarDate':
return LunarDate(y, m, d, leap)

def replace(self, *, year: Optional[int] = None, month: Optional[int] = None, day: Optional[int] = None,
leap: Optional[Leap] = None):
leap: Optional[int] = None):
if year is None:
year = self._year
if month is None:
Expand Down
4 changes: 4 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# 更新日志

## v3.4.3 (20210201)

- `borax.calendars.lunarDate`
- `LunarDate.leap` 使用 `int` 类型 ([#26](https://github.com/kinegratii/borax/issues/26)

## v3.4.2 (20201227)

Expand Down
8 changes: 4 additions & 4 deletions docs/guides/lunardate.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ LunarDate(2100, 12, 29, 0)
| year | `int` | 农历年 | 2018 | %y | |
| month | `int` | 农历月 | 6 | %m | |
| day | `int` | 农历日 | 26 | %d | |
| leap | `bool` | 是否闰月 | False | %l | (1) |
| leap | `int` | 是否闰月 | 0 | %l | (1) |
| offset | `int` | 距下限的偏移量 | 43287 | - | |
| term | `str``None` | 节气名称 | 立秋 | %t | (2) |
| cn_year | `str` | 中文年 | 二〇一八 | %Y | (3) |
Expand All @@ -141,7 +141,7 @@ LunarDate(2100, 12, 29, 0)

备注信息:

- (1) '%l' 将闰月标志格式化为数字,如“0”、“1”
- (1) 自v3.4.3开始,leap 的类型由 `bool` 改为 `int`'%l' 将闰月标志格式化为数字,如“0”、“1”
- (2) 当 term为None时,将格式化为 '-'。
- (3) '%Y'、'%M'、'%D' 三个中文名称不包含“年”、“月”、“日”后缀汉字
- (4) 和'%M' 相比,将“冬”、“腊” 显示为“十一”、“十二”,其余不变
Expand Down Expand Up @@ -183,7 +183,7 @@ LunarDate(2100, 12, 29, 0)
将当前日期转化为公历日期

```
>>> ld = LunarDate(2018, 6, 26, False)
>>> ld = LunarDate(2018, 6, 26, 0)
>>>ld.to_solar_date()
datetime.date(2018, 8, 7)
```
Expand Down Expand Up @@ -358,7 +358,7 @@ print(my_birthday.leap) # 0

### 日期相关

- **LCalendars.ndays(year: int, month: Optional[int] = None, leap: Leap = False) -> int**
- **LCalendars.ndays(year: int, month: Optional[int] = None, leap: int= 0) -> int**

返回X年或者X年X月的天数;如输入的年月不存在,将抛出 `ValueError` 异常。
例子:
Expand Down
2 changes: 1 addition & 1 deletion long_description.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ License

The MIT License (MIT)

Copyright (c) 2015-2020 kinegratii
Copyright (c) 2015-2021 kinegratii

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand Down
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "borax"
version = "3.4.0"
version = "3.4.3"
description = "A util collections for Python3."
readme = "long_description.rst"
authors = ["kinegratii <kinegratii@gmail.com>"]
Expand All @@ -26,7 +26,7 @@ classifiers=[

[tool.poetry.dev-dependencies]
nose = "^0.9"
coverage = "^4.5"
flake8 = "^3.5"
coverage = "^5.2"
flake8 = "^3.8"
mccabe = "^0.6"
wheel = "^0.31"
wheel = "^0.35"
2 changes: 1 addition & 1 deletion tests/test_lunardate.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_create_date(self):
self.assertEqual(1976, ld.year)
self.assertEqual(8, ld.month)
self.assertEqual(8, ld.day)
self.assertEqual(True, ld.leap)
self.assertEqual(1, ld.leap)

def test_create_specific_dates(self):
today = LunarDate.today()
Expand Down

0 comments on commit c8fb6e2

Please sign in to comment.