nagataaaas / japanera Goto Github PK
View Code? Open in Web Editor NEWEasy Tools for Japanese Era System
License: MIT License
Easy Tools for Japanese Era System
License: MIT License
TODO: issue の内容について具体的に書く
locale.setlocale(locale.LC_ALL, '')
の影響で、s3 オブジェクト取得などで使う botocore の utils.py parse_timestamp #L927 がエラーを吐いてしまう。具体的には以下のようなエラーが発生した。
> raise ParserError("Unknown string format: %s", timestr)
E dateutil.parser._parser.ParserError: Unknown string format: 月, 30 1月 2023 07:39:41 GMT
エラーを見るに、意図しないロケール設定の影響を受けて、文字列形式が変わってしまったことが原因で、実際に影響をもたらしたのが Japanera の ini.py だったので、この副作用を取り除きたい。
迷い中 🤔
初めまして。
EraDateの使用法について質問です。
print(EraDate(1926, 12, 23).strftime("%-E%-o年%m月%d日"))
print(EraDate(1926, 12, 24).strftime("%-E%-o年%m月%d日"))
print(EraDate(1926, 12, 25).strftime("%-E%-o年%m月%d日"))
上記のコードを実行すると出力結果が以下のようになります。
大正15年12月23日
西暦26年12月24日
昭和01年12月25日
これはバグでしょうか?それとも仕様でしょうか?
また、1926年12月24日を「大正」として扱うにはどのようにすればよいでしょうか。
アプリケーション側で対処するしかないのでしょうか。
よろしくお願いします。
すごいライブラリですね!もともと生でdatetime.datetime.strptime()
を使っていたのですが、困ったことがあったのでライブラリを探しているところでした。 datetime.strptime()
は西暦でちゃんと入れないと閏年の扱いに失敗するみたいです。なので、以下の挙動もバグだと思います。
Python 3.8.2 (default, Feb 27 2020, 19:58:50)
[Clang 11.0.0 (clang-1100.0.33.17)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import japanera
>>> janera = japanera.Japanera()
>>> janera.strptime("令和02年02月01日", "%-E%-O年%m月%d日")
[datetime.datetime(2020, 2, 1, 0, 0)]
>>> janera.strptime("令和02年02月29日", "%-E%-O年%m月%d日")
[]
datetime
はこうなります。
>>> from datetime import datetime
>>> datetime.strptime("R02.02.29", "R%y.%m.%d")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/_strptime.py", line 568, in _strptime_datetime
tt, fraction, gmtoff_fraction = _strptime(data_string, format)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/_strptime.py", line 534, in _strptime
julian = datetime_date(year, month, day).toordinal() - \
ValueError: day is out of range for month
>>>
いつもお世話になっております。
Japanera 2.1.1のrequirement.txtにはkanjize==1.5.0とあるのですが、pip install -U Japaneraではkanjize 1.4.0がインストールされ、あらためてpip install -U kanjizeすると、以下のエラーが表示されます。
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
japanera 2.1.1 requires kanjize==1.4.0, but you have kanjize 1.5.0 which is incompatible.
Thank you for making such a helpful library. It does everything I need, but it seems to have a small bug.
When I run the following code, it fails to parse the date.
from japanera import Japanera
janera = Japanera()
janera.strptime('昭和27年3月14日','%-E%-O年%m月%d日')
# => []
The issue appears to be with this line of code:
https://github.com/delta114514/Japanera/blob/042996abc07d46c8790ff98f74a38702cf4ae3b3/japanera/japanera.py#L970
I think the problem is that %m
and %d
are ambiguous during parsing - they will parse either single-digit values or zero-padded values, but when formatting, they will always output the zero-padded form. So your check probably fails because
"昭和27年3月14日" !=
"昭和27年03月14日"
After commenting out the line I mentioned, it parses the date properly.
File "date.py", line 13, in <module>
era_of_1950_1_1: Era = EraDate(1950, 1, 1).era
File "/home/miso/.local/lib/python3.8/site-packages/japanera/japanera.py", line 157, in __new__
result = find_era_and_date(absolute_year=year, month=month, day=day)
File "/home/miso/.local/lib/python3.8/site-packages/japanera/parser.py", line 484, in find_era_and_date
_found = find_eras_with_year(absolute_year)
File "/home/miso/.local/lib/python3.8/site-packages/japanera/parser.py", line 562, in find_eras_with_year
def _find_first_era_after_year_index(era_list: list["Era"]) -> int:
TypeError: 'type' object is not subscriptable```
Parser failed to load on Ubuntu 20.04 (Python3.8).
Python 3.8.10 (default, May 26 2023, 14:05:08)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import japanera
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/tnagano/.local/lib/python3.8/site-packages/japanera/__init__.py", line 17, in <module>
from .japanera import (Era, EraDate, EraDateTime, ERA_DATA_COMMON, ERA_DATA_DAIKAKUJI, ERA_DATA_JIMYOUIN,
File "/home/tnagano/.local/lib/python3.8/site-packages/japanera/japanera.py", line 10, in <module>
from .parser import _strptime, find_era_and_date, _set_era_data
File "/home/tnagano/.local/lib/python3.8/site-packages/japanera/parser.py", line 536, in <module>
def find_eras_with_year(year: int) -> set["Era"]:
TypeError: 'type' object is not subscriptable
すばらしいライブラリありがとうございます!重宝させていただいています。
一点、機能の要望ですが、和暦の 1 桁年にご対応いただけませんでしょうか。
現状、Japanera().strptime('令和2年9月1日', "%-E%-O年%m月%d日")
とすると ValueError
の例外が飛ぶかと思います。
おそらく strptime 本家の方で 'y': r"(?P<y>\d\d)"
となっているためと考えられます。
Line 41 in a038d22
format_regex = _TimeRE_cache.compile(format)
format_regex = re.compile(format_regex.pattern.replace('(?P<y>\\d\\d)', '(?P<y>\\d|\\d\\d)'), re.IGNORECASE)
等とすれば 1 桁年にも対応できるかと思います。(が、力技できれいでない気がします。あとここで対応するのが適切か不明です。)
一度ご検討いただけると幸いです。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.