This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
标题: calendar should understand full- vs. half-width characters
类型: enhancement Stage: needs patch
Components: Library (Lib) Versions: Python 3.4
process
状态: open Resolution:
Dependencies: 12568 后续:
分配给: 抄送列表: chason.chaffin, ezio.melotti, ishigoya, nneonneo, rhettinger, terry.reedy
优先级: normal 关键字:

nneonneo2013-01-27 08:38 创建。最近一次由 admin2022-04-11 14:57 修改。

Messages (4)
msg180748 - (view) Author: Robert Xiao (nneonneo) * 日期: 2013-01-27 08:38
Try this at your command-prompt (requires utf8 support in the terminal emulator):

$ python3 -m calendar -L zh_CN -e utf8

The result is a mess like this:

                                  2013

         一月                        二月                        三月
一  二  三  四  五  六  日       一  二  三  四  五  六  日       一  二  三  四  五  六  日
    1  2  3  4  5  6                   1  2  3                   1  2  3
 7  8  9 10 11 12 13       4  5  6  7  8  9 10       4  5  6  7  8  9 10
14 15 16 17 18 19 20      11 12 13 14 15 16 17      11 12 13 14 15 16 17
21 22 23 24 25 26 27      18 19 20 21 22 23 24      18 19 20 21 22 23 24
28 29 30 31               25 26 27 28               25 26 27 28 29 30 31

Note the irregular spacing. The calendar module assumes that the characters are half-width, when in reality they are full-width characters.

calendar should use unicodedata.east_asian_width to determine if a character is full- or half-width, and adjust the spacing accordingly.
msg180751 - (view) Author: Robert Xiao (nneonneo) * 日期: 2013-01-27 08:50
This is also a problem in Python 2.7 after the patch in issue17049 is applied.
msg181154 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) 日期: 2013-02-02 09:41
For this particular East Asian local, the problem is the double spacing between the double-width characters (the Chinese numbers 1 to 7). This is potentially easily fixed for this locale. But do all locales have abbreviated weekday names that fit in 2 columns?

In looking at whether this issue should be classified as a bug or feature issue, I only found this:
'''
 class calendar.LocaleTextCalendar(firstweekday=0, locale=None)

    This subclass of TextCalendar can be passed a locale name in the constructor and will return month and weekday names in the specified locale.'''

The current code does this, though not gracefully. I suspect that adding "-t html" to the command line, to use class calendar.LocaleHTMLCalendar, would work better.

[Doc note 1: I suspect the next sentence "If this locale includes an encoding all strings containing month and weekday names will be returned as unicode.", which is unchanged from 2.x, is obsolete and perhaps should just be removed.

Doc note 2: I could not find any doc for the command line interface in 
8.2. calendar — General calendar-related functions. Unless I am missing something, a new section should be added.]

#12568 will add a new feature that will only go in the 'next' release. So if this issue depends on that issue, it is effectively a new feature also.
msg311001 - (view) Author: Robert Booth (ishigoya) 日期: 2018-01-28 21:30
There is similar misaligned output in Japanese and Korean:

Korean:
         1월                        2월                        3월
월  화  수  목  금  토  일       월  화  수  목  금  토  일       월  화  수  목  금  토  일
 1  2  3  4  5  6  7                1  2  3  4                1  2  3  4
 8  9 10 11 12 13 14       5  6  7  8  9 10 11       5  6  7  8  9 10 11

Japanese:
         1月                        2月                        3月
月  火  水  木  金  土  日       月  火  水  木  金  土  日       月  火  水  木  金  土  日
 1  2  3  4  5  6  7                1  2  3  4                1  2  3  4
 8  9 10 11 12 13 14       5  6  7  8  9 10 11       5  6  7  8  9 10 11

I came across this issue while using khal, a command-line calendar. That program also uses the calendar.LocaleTextCalendar class. I've raised an issue at https://github.com/pimutils/khal/issues/751
历史
日期 用户 动作 参数
2022-04-11 14:57:41admin修改github: 61250
2018-01-29 05:13:25chason.chaffin修改抄送: + chason.chaffin
2018-01-28 21:30:28ishigoya修改抄送: + ishigoya
消息: + msg311001
2013-02-03 04:38:26ezio.melotti修改抄送: + ezio.melotti
2013-02-02 09:41:36terry.reedy修改versions: + Python 3.4, - Python 2.7, Python 3.2
抄送: + rhettinger, terry.reedy

消息: + msg181154

type: enhancement
stage: needs patch
2013-01-27 09:01:24serhiy.storchaka修改dependencies: + Add functions to get the width in columns of a character
2013-01-27 08:50:03nneonneo修改消息: + msg180751
versions: + Python 2.7
2013-01-27 08:38:10nneonneo创建