nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: pimutils/khal
Pull request #645 (2017-05-04 22:44:22)

Fix birthdays


Patch:
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index ac070ff..18eee90 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -12,6 +12,7 @@ may want to subscribe to `GitHub's tag feed
 unreleased
 
 * FIX set PRODID to khal/icalendar
+* FIX don't crash on updated vcards
 
 * ADD new entry points recommended for packagers to use.
 
diff --git a/khal/khalendar/backend.py b/khal/khalendar/backend.py
index ed845f4..289dc51 100644
--- a/khal/khalendar/backend.py
+++ b/khal/khalendar/backend.py
@@ -273,6 +273,7 @@ class SQLiteDb(object):
         """
         assert calendar is not None
         assert href is not None
+        self.delete(href, calendar=calendar)
         ical = icalendar.Event.from_ical(vevent)
         vcard = ical.walk()[0]
         if 'BDAY' in vcard.keys():


Test patch:
diff --git a/tests/backend_test.py b/tests/backend_test.py
index 85243bb..ab68726 100644
--- a/tests/backend_test.py
+++ b/tests/backend_test.py
@@ -687,6 +687,13 @@ def test_birthdays():
     assert events[0].summary == 'Unix\'s 45th birthday'
 
 
+def test_birthdays_update():
+    """test if we can update a birthday"""
+    db = backend.SQLiteDb([calname], ':memory:', locale=LOCALE_BERLIN)
+    db.update_birthday(card, 'unix.vcf', calendar=calname)
+    db.update_birthday(card, 'unix.vcf', calendar=calname)
+
+
 def test_birthdays_no_year():
     db = backend.SQLiteDb([calname], ':memory:', locale=LOCALE_BERLIN)
     assert list(db.get_floating(start, end)) == list()
Repository: pimutils/khal
Pull request #819 (2018-10-30 10:45:05)

In printformats, use time 21:45 to distinguish hours/minutes and AM/PM formats.
To clearly show how the time is formatted, printformats should use a sample time like 21:45 instead of 10:09. This distinguishes hours from minutes, and 12/24 hour clocks.


Patch:
diff --git a/doc/source/usage.rst b/doc/source/usage.rst
index a74f9a9..c38f7f7 100644
--- a/doc/source/usage.rst
+++ b/doc/source/usage.rst
@@ -447,7 +447,7 @@ prints a list of all configured calendars.
 
 printformats
 ************
-prints a fixed date (*2013-12-21 10:09*) in all configured date(time) formats.
+prints a fixed date (*2013-12-21 21:45*) in all configured date(time) formats.
 This is supposed to help check if those formats are configured as intended.
 
 search
diff --git a/khal/cli.py b/khal/cli.py
index faf1e3c..ee520f6 100644
--- a/khal/cli.py
+++ b/khal/cli.py
@@ -503,10 +503,10 @@ def _get_cli():
     def printformats(ctx):
         '''Print a date in all formats.
 
-        Print the date 2013-12-21 10:09 in all configured date(time)
+        Print the date 2013-12-21 21:45 in all configured date(time)
         formats to check if these locale settings are configured to ones
         liking.'''
-        time = dt.datetime(2013, 12, 21, 10, 9)
+        time = dt.datetime(2013, 12, 21, 21, 45)
         try:
             for strftime_format in [
                     'longdatetimeformat', 'datetimeformat', 'longdateformat',


Test patch:
diff --git a/tests/cli_test.py b/tests/cli_test.py
index 7bb0045..1f20c86 100644
--- a/tests/cli_test.py
+++ b/tests/cli_test.py
@@ -348,11 +348,11 @@ def test_printformats(runner):
     runner = runner(days=2)
 
     result = runner.invoke(main_khal, ['printformats'])
-    assert '\n'.join(['longdatetimeformat: 21.12.2013 10:09',
-                      'datetimeformat: 21.12. 10:09',
+    assert '\n'.join(['longdatetimeformat: 21.12.2013 21:45',
+                      'datetimeformat: 21.12. 21:45',
                       'longdateformat: 21.12.2013',
                       'dateformat: 21.12.',
-                      'timeformat: 10:09',
+                      'timeformat: 21:45',
                       '']) == result.output
     assert not result.exception
Repository: pimutils/khal
Pull request #1022 (2021-03-11 23:42:24)

Add warning when an event with an RRULE will never occur (e.g. #1020) and stop processing.


Patch:
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index 9e622b5..a465025 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -16,6 +16,7 @@ not released
 * FIX `khal interactive` now accepts -a/-d options (as documented)
 * FIX Strip whitespace when loading `displayname` and `color` files
 * FIX Warn when loading events with a recurrence that finishes before it starts
+* FIX Warn when loading events with a recurrence that never occurs
 * FIX Alarms without descriptions no longer crash `ikhal`
 * FIX Display all-day events at the top of the day in `ikhal`
 * FIX Keybindings in empty search results no longer crash `ikhal`
diff --git a/khal/icalendar.py b/khal/icalendar.py
index e0f46e6..735f4ce 100644
--- a/khal/icalendar.py
+++ b/khal/icalendar.py
@@ -277,6 +277,12 @@ def expand(vevent, href=''):
                     'This event will not be available in khal.'.format(href))
                 return False
 
+        if rrule.count() == 0:
+            logger.warning(
+                '{0}: Recurrence defined but will never occur.\n'
+                'This event will not be available in khal.'.format(href))
+            return False
+
         rrule = map(sanitize_datetime, rrule)
 
         logger.debug('calculating recurrence dates for {}, this might take some time.'.format(href))


Test patch:
diff --git a/tests/ics/event_rrule_no_occurence.ics b/tests/ics/event_rrule_no_occurence.ics
new file mode 100644
index 0000000..9d5f481
--- /dev/null
+++ b/tests/ics/event_rrule_no_occurence.ics
@@ -0,0 +1,8 @@
+BEGIN:VEVENT
+DTSTART;VALUE=DATE-TIME:20210101T093000Z
+DTEND;VALUE=DATE-TIME:20210101T094500Z
+RRULE:FREQ=WEEKLY;UNTIL=20210104T090000Z;BYDAY=TU
+DTSTAMP;VALUE=DATE-TIME:20210101T000000Z
+SUMMARY:This event will never happen
+UID:OW1M4APLKA2WTEOJLIGRHVSEHJHDZLLVXI2N
+END:VEVENT
diff --git a/tests/khalendar_utils_test.py b/tests/khalendar_utils_test.py
index 94b0c92..60b6628 100644
--- a/tests/khalendar_utils_test.py
+++ b/tests/khalendar_utils_test.py
@@ -690,6 +690,13 @@ class TestSpecial(object):
         # TODO test for logging message
         assert dtstart is False
 
+    def test_event_dt_rrule_until_before_start(self):
+        """test handling if an event with RRULE will never occur"""
+        vevent = _get_vevent(_get_text('event_rrule_no_occurence'))
+        dtstart = icalendar_helpers.expand(vevent, berlin)
+        # TODO test for logging message
+        assert dtstart is False
+
 
 simple_rdate = """BEGIN:VEVENT
 SUMMARY:Simple Rdate
Repository: pimutils/khal
Pull request #1082 (2021-08-20 10:45:26)

Add support for processing and importing ics without UID
Files like this seem to be produced by all kinds of proprietary reservation
systems and such. They are clearly out of spec, but since they exist I'd
prefer to be able to import them without needing to manually add an UID
every time.

Another alternative would be to report an error if there is no UID and
random_uid=False, and then doing this only when random_uid=True. I'm not
sure it would be an improvement over this simpler solution, so I'll offer
this first.

WhyNotHugo: The general idea here makes sense to me, I mostly have one suggestion.

I would rather make the UID the hash (sha256?) of the input event itself, so that if we handle the exact same event twice, it gets the same UID, and we avoid creating a duplicate entry.

What do you think?
d7415: I'd also suggest adding a warning, so that a user importing it knows it's a bad file.
viiru-: Both suggestions sound good to me. I'll rework and get back to you (sadly not today, I'm out of time for the moment). Thanks for the review @WhyNotHugo and @d7415.
viiru-: I have pushed a new version that implements the suggested improvements, can you review again?

Patch:
diff --git a/khal/icalendar.py b/khal/icalendar.py
index 3cfbb17..03ea8a4 100644
--- a/khal/icalendar.py
+++ b/khal/icalendar.py
@@ -27,6 +27,7 @@ import icalendar
 import logging
 import pytz
 from collections import defaultdict
+from hashlib import sha256
 
 from .exceptions import UnsupportedRecurrence
 from .parse_datetime import guesstimedeltafstr, rrulefstr
@@ -62,6 +63,12 @@ def split_ics(ics, random_uid=False, default_timezone=None):
             tzs[key] = item
 
         if item.name == 'VEVENT':
+            if 'UID' not in item:
+                logger.warning(
+                    f"Event with summary '{item['SUMMARY']}' doesn't have a unique ID."
+                    "A generated ID will be used instead."
+                )
+                item['UID'] = sha256(item.to_ical()).hexdigest()
             events_grouped[item['UID']].append(item)
         else:
             continue


Test patch:
diff --git a/tests/icalendar_test.py b/tests/icalendar_test.py
index 5a4aaba..251e9ee 100644
--- a/tests/icalendar_test.py
+++ b/tests/icalendar_test.py
@@ -78,3 +78,11 @@ def test_windows_timezone(caplog):
     cal = _get_text("tz_windows_format")
     split_ics(cal)
     assert "Cannot find timezone `Pacific/Auckland`" not in caplog.text
+
+
+def test_split_ics_without_uid():
+    cal = _get_text('without_uid')
+    vevents = split_ics(cal)
+    assert vevents
+    vevents2 = split_ics(cal)
+    assert vevents[0] == vevents2[0]
diff --git a/tests/ics/without_uid.ics b/tests/ics/without_uid.ics
new file mode 100644
index 0000000..a7dd248
--- /dev/null
+++ b/tests/ics/without_uid.ics
@@ -0,0 +1,10 @@
+BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//PIMUTILS.ORG//NONSGML khal / icalendar //EN
+BEGIN:VEVENT
+SUMMARY:An Event
+DTSTART;VALUE=DATE:20140409
+DTEND;VALUE=DATE:20140410
+DTSTAMP;VALUE=DATE-TIME:20140401T234817Z
+END:VEVENT
+END:VCALENDAR