diff --git a/borax/calendars/festivals2.py b/borax/calendars/festivals2.py index 8289627..4333d20 100644 --- a/borax/calendars/festivals2.py +++ b/borax/calendars/festivals2.py @@ -4,9 +4,9 @@ import collections import csv import enum +import warnings from datetime import date, timedelta, datetime from pathlib import Path -import warnings from typing import List, Tuple, Optional, Union, Iterator, Set, Generator, Sequence from borax.calendars.lunardate import LunarDate, LCalendars, TermUtils, TextUtils, TERMS_CN @@ -22,11 +22,25 @@ MixedDate = Union[date, LunarDate] +# Public Constants + class FreqConst: YEARLY = 0 MONTHLY = 1 +class FestivalCatalog: + basic = 'basic' + event = 'event' + life = 'life' + public = 'public' + tradition = 'tradition' + term = 'term' + other = 'other' + + CATALOGS = ['basic', 'term', 'public', 'tradition', 'event', 'life', 'other'] + + # Private Global Variables _IGNORE_LEAP_MONTH = 3 @@ -47,18 +61,6 @@ class FestivalSchema(enum.IntEnum): TERM = 4 -class FestivalCatalog: - basic = 'basic' - event = 'event' - life = 'life' - public = 'public' - tradition = 'tradition' - term = 'term' - other = 'other' - - CATALOGS = ['basic', 'term', 'public', 'tradition', 'event', 'life', 'other'] - - class WrappedDate: """A date object with solar and lunar calendars.""" __slots__ = ['solar', 'lunar', 'name', '_fl'] diff --git a/borax/capp/borax_calendar_app.py b/borax/capp/borax_calendar_app.py index 2b661ec..8f5ccbe 100644 --- a/borax/capp/borax_calendar_app.py +++ b/borax/capp/borax_calendar_app.py @@ -13,7 +13,7 @@ from borax.calendars.festivals2 import FestivalLibrary, WrappedDate from borax.calendars.lunardate import TextUtils, TERMS_CN from borax.calendars.ui import CalendarFrame, FestivalTableFrame -from borax.capp.festival_creator import FestivalCreatePanel, start_festival_creator +from borax.capp.festival_creator import FestivalCreatePanel library = FestivalLibrary.load_builtin().sort_by_countdown() diff --git a/docs/guides/festivals2-serialize.md b/docs/guides/festivals2-serialize.md index 9327a39..f1739f0 100644 --- a/docs/guides/festivals2-serialize.md +++ b/docs/guides/festivals2-serialize.md @@ -2,6 +2,8 @@ > 模块: `borax.calendars.festivals2` +> Updated in 3.6.0:LunarDate类不再支持直接序列,必须先转化对应的 WrappedDate 对象。 +> > Updated in 3.5.6: 星期型节日(WeekFestival)类支持倒数序号。如:“国际麻风节(1月最后一个星期天)” > > Add in 3.5.0 diff --git a/docs/guides/festivals2.md b/docs/guides/festivals2.md index 61806f2..f6a0ff4 100644 --- a/docs/guides/festivals2.md +++ b/docs/guides/festivals2.md @@ -15,7 +15,7 @@ ### 常量定义 -`festival2` 定义了一些常量,这些常量通常归属于一个名称以“Const”结尾的类,并使用大写字母的变量命名形式。 +`festival2` 定义了一些常量,这些常量通常归属于一个类,并使用大写字母的变量命名形式。本文档仅列出那些属于 public 权限的常量类。 #### FreqConst @@ -26,16 +26,32 @@ FreqConst 表示节日的频率,用于设置 `Festival` 的 `freq` 参数。 | FreqConst.YEARLY = 0 | 表示每年 | | FreqConst.MONTHLY = 1 | 表示每月 | -#### LeapConst +#### FestivalCatalog -LeapConst表示农历闰月的标志,用于 `Period` 、`Festival` 对象初始化操作。 +FestivalCatalog 定义了一些节日的分类标签,可以通过 `Festival.catalog` 属性进行读写。 -| 定义 | 表示 | -| -------------------- | ---- | -| LeapConst.NORMAL = 0 | 平月 | -| LeapConst.LEAP = 1 | 闰月 | -| LeapConst.MIXED = 2 | 混合 | +默认支持以下标签。 +```python +class FestivalCatalog: + basic = 'basic' + event = 'event' + life = 'life' + public = 'public' + tradition = 'tradition' + term = 'term' + other = 'other' + + CATALOGS = ['basic', 'term', 'public', 'tradition', 'event', 'life', 'other'] +``` + +节日标签用于同一日期有多个节日时,这些节日之间的先后排序问题。 + +```python +amy_birthday = SolarFestival(month=10,day=1, catalog='event') +``` + +如上例子,`amy_birthday` 总是在国庆节(其标签为 basic)之后。 ## 基础数据结构 - WrappedDate