Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

calendar should understand full- vs. half-width characters #61250

Open
nneonneo mannequin opened this issue Jan 27, 2013 · 4 comments
Open

calendar should understand full- vs. half-width characters #61250

nneonneo mannequin opened this issue Jan 27, 2013 · 4 comments
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@nneonneo
Copy link
Mannequin

nneonneo mannequin commented Jan 27, 2013

BPO 17048
Nosy @rhettinger, @terryjreedy, @ezio-melotti, @chason, @ishigoya
Dependencies
  • bpo-12568: Add functions to get the width in columns of a character
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2013-01-27.08:38:10.091>
    labels = ['type-feature', 'library']
    title = 'calendar should understand full- vs. half-width characters'
    updated_at = <Date 2018-01-29.05:13:25.560>
    user = 'https://bugs.python.org/nneonneo'

    bugs.python.org fields:

    activity = <Date 2018-01-29.05:13:25.560>
    actor = 'chason.chaffin'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2013-01-27.08:38:10.091>
    creator = 'nneonneo'
    dependencies = ['12568']
    files = []
    hgrepos = []
    issue_num = 17048
    keywords = []
    message_count = 4.0
    messages = ['180748', '180751', '181154', '311001']
    nosy_count = 6.0
    nosy_names = ['rhettinger', 'terry.reedy', 'nneonneo', 'ezio.melotti', 'chason.chaffin', 'ishigoya']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = 'needs patch'
    status = 'open'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue17048'
    versions = ['Python 3.4']

    @nneonneo
    Copy link
    Mannequin Author

    nneonneo mannequin commented Jan 27, 2013

    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.

    @nneonneo nneonneo mannequin added the stdlib Python modules in the Lib dir label Jan 27, 2013
    @nneonneo
    Copy link
    Mannequin Author

    nneonneo mannequin commented Jan 27, 2013

    This is also a problem in Python 2.7 after the patch in bpo-17049 is applied.

    @terryjreedy
    Copy link
    Member

    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.]

    bpo-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.

    @terryjreedy terryjreedy added the type-feature A feature request or enhancement label Feb 2, 2013
    @ishigoya
    Copy link
    Mannequin

    ishigoya mannequin commented Jan 28, 2018

    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 pimutils/khal#751

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant