Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,4 @@ Alnoman Kamil - noman [at] kamil [dot] gr - https://kamil.gr
Leonardo Taccari - iamleot [at] gmail [dot] com
Jorenar - dev [at] jorenar [dot] com - https://jorenar.com
John Wassilak - john [at] wassilak [dot] com
Rajvira10
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ may want to subscribe to `GitHub's tag feed
0.14.2
======
unreleased
* FIX date and time fields wrapping in ikhal when their formats contain wide
characters, such as Japanese year, month, and day markers
* FIX ``khal import --format``/``-f`` was accepted and then ignored, always
falling back to ``view.event_format``

Expand Down
8 changes: 5 additions & 3 deletions khal/ui/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def __init__(
monthdisplay: Literal["firstday", "firstfullweek"] = "firstday",
keybindings: dict[str, list[str]] | None = None,
) -> None:
datewidth = len(startdt.strftime(dateformat))
datewidth = urwid.Text(startdt.strftime(dateformat)).pack()[0]
self._dateformat = dateformat
if startdt is None:
startdt = dt.date.today()
Expand Down Expand Up @@ -207,8 +207,10 @@ def __init__(
self.on_start_date_change = on_start_date_change
self.on_end_date_change = on_end_date_change
self.on_type_change = on_type_change
self._datewidth = len(start.strftime(self.conf["locale"]["longdateformat"]))
self._timewidth = len(start.strftime(self.conf["locale"]["timeformat"]))
date_text = start.strftime(self.conf["locale"]["longdateformat"])
time_text = start.strftime(self.conf["locale"]["timeformat"])
self._datewidth = urwid.Text(date_text).pack()[0]
self._timewidth = urwid.Text(time_text).pack()[0]
# this will contain the widgets for [start|end] [date|time]
self.widgets = StartEnd(None, None, None, None)
self.checkallday = urwid.CheckBox("Allday", state=self.allday, on_state_change=self.toggle)
Expand Down
30 changes: 29 additions & 1 deletion tests/ui/test_editor.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import datetime as dt

import icalendar
import pytest

from khal.ui.editor import RecurrenceEditor, StartEndEditor
from khal.ui.editor import DateEdit, RecurrenceEditor, StartEndEditor
from tests.utils import BERLIN, LOCALE_BERLIN

from .canvas_render import CanvasTranslator
Expand All @@ -21,6 +22,33 @@
}


@pytest.mark.parametrize("dateformat", ["%Y-%m-%d", "%Y年%m月%d日"])
def test_date_edit_display_width(dateformat):
editor = DateEdit(START, dateformat=dateformat)
lines = list(editor.render((50,), False).decoded_text)
assert len(lines) == 1
assert lines[0].rstrip() == START.strftime(dateformat)


@pytest.mark.parametrize("dateformat", ["%Y-%m-%d", "%Y年%m月%d日"])
@pytest.mark.parametrize("timeformat", ["%H:%M", "%H時%M分"])
@pytest.mark.parametrize("allday", [False, True])
def test_start_end_editor_display_width(dateformat, timeformat, allday):
conf = {
**CONF,
"locale": {**CONF["locale"], "longdateformat": dateformat, "timeformat": timeformat},
}
start, end = (START.date(), END.date()) if allday else (START, END)
editor = StartEndEditor(start, end, conf=conf)
lines = list(editor.render((60,), False).decoded_text)
assert len(lines) == 3
assert start.strftime(dateformat) in lines[1]
assert end.strftime(dateformat) in lines[2]
if not allday:
assert start.strftime(timeformat) in lines[1]
assert end.strftime(timeformat) in lines[2]


def test_popup(monkeypatch):
"""making sure the popup calendar gets callend with the right inital value

Expand Down