Repository: django-helpdesk/django-helpdesk

Issue:
Due date change detected when no change made
**Describe the bug**
In the current stable release, if a ticket has a due date set then saving the form on the view ticket page results in a (false) due date change being detected. 
The view then adds a TicketChange and FollowUp to record the (false) due date change, despite no change actually being made.


**To Reproduce**
Steps to reproduce the behavior:
1. Create a ticket with a due date
2. Save
3. Edit any detail about the ticket (e.g. add a comment) via the view ticket page
4. A note is automatically added reporting that due_date was changed, but the due date itself remains the same

**Expected behaviour**
Only the edit or comment made appears in the thread.

**Diagnosis**
These POST requests are handled by the update_ticket view.  This view currently assumes the POST data for due_date always has the format mm/dd/yy.  A comment in the code, consistent with some custom re logic, reveals this assumption:

NOTE: jQuery's default for dates is mm/dd/yy --  very US-centric but for now that's the only format supported until we clean up code to internationalize a little more. But the ticket.html template uses datepicker with format yy-mm-dd:
`$( "#id_due_date" ).datepicker({dateFormat: 'yy-mm-dd'});`
 With standard default input date formats, Django correctly transforms the POST data into the correct datetime object.

**Proposed Fix**
Short-term we can improve this by simply removing the custom re logic and using Django's built-in date parsing. Long-term, we should be using a form in this view to do validation and transformation and implement consistent date handling to support I18N and L10N package-wide. Pull request following with short-term fix.

**Desktop (please complete the following information):**
 - OS: MacOS Ventura 13.0.1
 - Browser: Safari
 - Version 16.1




Discussion:

Resolving patch:
diff --git a/helpdesk/views/staff.py b/helpdesk/views/staff.py
--- a/helpdesk/views/staff.py
+++ b/helpdesk/views/staff.py
@@ -23,7 +23,9 @@
 from django.shortcuts import get_object_or_404, redirect, render
 from django.urls import reverse, reverse_lazy
 from django.utils import timezone
+from django.utils.dateparse import parse_datetime
 from django.utils.html import escape
+from django.utils.timezone import make_aware
 from django.utils.translation import gettext as _
 from django.views.decorators.csrf import requires_csrf_token
 from django.views.generic.edit import FormView, UpdateView
@@ -536,12 +538,7 @@ def get_due_date_from_request_or_ticket(
     due_date = request.POST.get('due_date', None) or None
 
     if due_date is not None:
-        # based on Django code to parse dates:
-        # https://docs.djangoproject.com/en/2.0/_modules/django/utils/dateparse/
-        match = DATE_RE.match(due_date)
-        if match:
-            kw = {k: int(v) for k, v in match.groupdict().items()}
-            due_date = date(**kw)
+        due_date = make_aware(parse_datetime(due_date))
     else:
         due_date_year = int(request.POST.get('due_date_year', 0))
         due_date_month = int(request.POST.get('due_date_month', 0))


Test patch: