We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
CSV Report generation API tests fail when the current date in the active timezone is different to the UTC date
## Observed behavior
When running the tests in `kolibri/plugins/facility/test/test_api.py` 2 tests can sometimes fail - the ones to do with generating a CSV Summary Log or Session Log report.

This occurs when the date as reported on the local machine in the currently set timezone is different to the current date according to UTC. In my specific case, the tests would fail when I ran them after 4pm PST (UTC - 8). I have not tested, but would assume that a similar issue would occur running the tests at say 7am in (UTC + 8) timezone.

## Errors and logs
```
kolibri/plugins/facility/test/test_api.py F..F.....                                                                                                                                                         [100%]

==================================================================================================== FAILURES =====================================================================================================
_____________________________________________________________________ ContentSummaryLogCSVExportTestCase.test_csv_download_admin_permissions ______________________________________________________________________

self = <kolibri.plugins.facility.test.test_api.ContentSummaryLogCSVExportTestCase testMethod=test_csv_download_admin_permissions>, mock_enqueue = <MagicMock name='enqueue' id='140268344491728'>

    @mock.patch.object(log_exports_cleanup, "enqueue", return_value=None)
    def test_csv_download_admin_permissions(self, mock_enqueue):
        call_command(
            "exportlogs",
            log_type="summary",
            output_file=output_filename(
                "summary",
                self.facility,
                start_date=self.start_date,
                end_date=self.end_date,
            ),
            overwrite=True,
            start_date=self.start_date,
            end_date=self.end_date,
        )
        self.client.login(
            username=self.admin.username,
            password=DUMMY_PASSWORD,
            facility=self.facility,
        )
        response = self.client.get(
            reverse(
                "kolibri:kolibri.plugins.facility:download_csv_file",
                kwargs={"csv_type": "summary", "facility_id": self.facility.id},
            )
        )
>       self.assertEqual(response.status_code, 200)
E       AssertionError: 404 != 200

kolibri/plugins/facility/test/test_api.py:149: AssertionError
---------------------------------------------------------------------------------------------- Captured stdout setup ----------------------------------------------------------------------------------------------
Installed 2 object(s) from 1 fixture(s)
---------------------------------------------------------------------------------------------- Captured stdout call -----------------------------------------------------------------------------------------------
INFO     2024-03-01 16:58:51,322 Creating csv file /home/richard/github/kolibri/.pytest_kolibri_home/log_export/Rock N' Roll High School #0_0f6e_content_summary_logs_from_2020-10-21_to_2024-03-01.csv
INFO     2024-03-01 16:58:51,327 Created csv file /home/richard/github/kolibri/.pytest_kolibri_home/log_export/Rock N' Roll High School #0_0f6e_content_summary_logs_from_2020-10-21_to_2024-03-01.csv with 3 lines
INFO     2024-03-01 16:58:51,504 127.0.0.1 - - "GET /facility/api/downloadcsvfile/summary/0f6ee14289d0447dbb105688560eee29/" 404 0 "" "unknown"
WARNING  2024-03-01 16:58:51,504 Not Found: /facility/api/downloadcsvfile/summary/0f6ee14289d0447dbb105688560eee29/
------------------------------------------------------------------------------------------------ Captured log call ------------------------------------------------------------------------------------------------
csv_export.py              186 INFO     Creating csv file /home/richard/github/kolibri/.pytest_kolibri_home/log_export/Rock N' Roll High School #0_0f6e_content_summary_logs_from_2020-10-21_to_2024-03-01.csv
exportlogs.py              159 INFO     Created csv file /home/richard/github/kolibri/.pytest_kolibri_home/log_export/Rock N' Roll High School #0_0f6e_content_summary_logs_from_2020-10-21_to_2024-03-01.csv with 3 lines
log.py                     224 WARNING  Not Found: /facility/api/downloadcsvfile/summary/0f6ee14289d0447dbb105688560eee29/
_____________________________________________________________________ ContentSessionLogCSVExportTestCase.test_csv_download_admin_permissions ______________________________________________________________________

self = <kolibri.plugins.facility.test.test_api.ContentSessionLogCSVExportTestCase testMethod=test_csv_download_admin_permissions>, mock_enqueue = <MagicMock name='enqueue' id='140268351318224'>

    @mock.patch.object(log_exports_cleanup, "enqueue", return_value=None)
    def test_csv_download_admin_permissions(self, mock_enqueue):
        call_command(
            "exportlogs",
            log_type="session",
            output_file=output_filename(
                "session",
                self.facility,
                start_date=self.start_date,
                end_date=self.end_date,
            ),
            overwrite=True,
            start_date=self.start_date,
            end_date=self.end_date,
        )
        self.client.login(
            username=self.admin.username,
            password=DUMMY_PASSWORD,
            facility=self.facility,
        )
        response = self.client.get(
            reverse(
                "kolibri:kolibri.plugins.facility:download_csv_file",
                kwargs={"csv_type": "session", "facility_id": self.facility.id},
            )
        )
>       self.assertEqual(response.status_code, 200)
E       AssertionError: 404 != 200

kolibri/plugins/facility/test/test_api.py:252: AssertionError
---------------------------------------------------------------------------------------------- Captured stdout setup ----------------------------------------------------------------------------------------------
Installed 2 object(s) from 1 fixture(s)
---------------------------------------------------------------------------------------------- Captured stdout call -----------------------------------------------------------------------------------------------
INFO     2024-03-01 16:58:52,079 Creating csv file /home/richard/github/kolibri/.pytest_kolibri_home/log_export/Rock N' Roll High School #1_207d_content_session_logs_from_2020-10-21_to_2024-03-01.csv
INFO     2024-03-01 16:58:52,084 Created csv file /home/richard/github/kolibri/.pytest_kolibri_home/log_export/Rock N' Roll High School #1_207d_content_session_logs_from_2020-10-21_to_2024-03-01.csv with 3 lines
INFO     2024-03-01 16:58:52,177 127.0.0.1 - - "GET /facility/api/downloadcsvfile/session/207d21f8516da5fad0659fc6488359d3/" 404 0 "" "unknown"
WARNING  2024-03-01 16:58:52,177 Not Found: /facility/api/downloadcsvfile/session/207d21f8516da5fad0659fc6488359d3/
------------------------------------------------------------------------------------------------ Captured log call ------------------------------------------------------------------------------------------------
csv_export.py              186 INFO     Creating csv file /home/richard/github/kolibri/.pytest_kolibri_home/log_export/Rock N' Roll High School #1_207d_content_session_logs_from_2020-10-21_to_2024-03-01.csv
exportlogs.py              159 INFO     Created csv file /home/richard/github/kolibri/.pytest_kolibri_home/log_export/Rock N' Roll High School #1_207d_content_session_logs_from_2020-10-21_to_2024-03-01.csv with 3 lines
log.py                     224 WARNING  Not Found: /facility/api/downloadcsvfile/session/207d21f8516da5fad0659fc6488359d3/
======================================================================================= 2 failed, 7 passed in 13.86 seconds =======================================================================================
```

Note - I did a test of the actual functionality that relies on this in the Facility plugin, and observed no issues, so this seems at the moment to be purely a testing artifact.

## Expected behavior
Tests should pass regardless of time of day or timezone!

## User-facing consequences
I think none - but would be good to work out why this is happening to be sure.

## Steps to reproduce
Set your system timezone to PST.
Set your system time to after 4pm.
Run the test suite above with pytest.

## Context

Noticed in the develop branch, but also extant on release-v0.16.x


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `kolibri/utils/time_utils.py`
Content:
```
1 from django.utils import timezone
2 
3 
4 def local_now():
5     return timezone.localtime(timezone.now())
6 
7 
8 def naive_utc_datetime(dt):
9     return timezone.make_naive(dt, timezone=timezone.utc)
10
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/kolibri/utils/time_utils.py b/kolibri/utils/time_utils.py
--- a/kolibri/utils/time_utils.py
+++ b/kolibri/utils/time_utils.py
@@ -2,8 +2,18 @@
 
 
 def local_now():
+    """
+    Returns the current time in the local timezone.
+    """
     return timezone.localtime(timezone.now())
 
 
+def utc_now():
+    """
+    Returns the current time in the UTC timezone.
+    """
+    return timezone.now()
+
+
 def naive_utc_datetime(dt):
     return timezone.make_naive(dt, timezone=timezone.utc)

{"golden_diff": "diff --git a/kolibri/utils/time_utils.py b/kolibri/utils/time_utils.py\n--- a/kolibri/utils/time_utils.py\n+++ b/kolibri/utils/time_utils.py\n@@ -2,8 +2,18 @@\n \n \n def local_now():\n+    \"\"\"\n+    Returns the current time in the local timezone.\n+    \"\"\"\n     return timezone.localtime(timezone.now())\n \n \n+def utc_now():\n+    \"\"\"\n+    Returns the current time in the UTC timezone.\n+    \"\"\"\n+    return timezone.now()\n+\n+\n def naive_utc_datetime(dt):\n     return timezone.make_naive(dt, timezone=timezone.utc)\n", "issue": "CSV Report generation API tests fail when the current date in the active timezone is different to the UTC date\n## Observed behavior\r\nWhen running the tests in `kolibri/plugins/facility/test/test_api.py` 2 tests can sometimes fail - the ones to do with generating a CSV Summary Log or Session Log report.\r\n\r\nThis occurs when the date as reported on the local machine in the currently set timezone is different to the current date according to UTC. In my specific case, the tests would fail when I ran them after 4pm PST (UTC - 8). I have not tested, but would assume that a similar issue would occur running the tests at say 7am in (UTC + 8) timezone.\r\n\r\n## Errors and logs\r\n```\r\nkolibri/plugins/facility/test/test_api.py F..F.....                                                                                                                                                         [100%]\r\n\r\n==================================================================================================== FAILURES =====================================================================================================\r\n_____________________________________________________________________ ContentSummaryLogCSVExportTestCase.test_csv_download_admin_permissions ______________________________________________________________________\r\n\r\nself = <kolibri.plugins.facility.test.test_api.ContentSummaryLogCSVExportTestCase testMethod=test_csv_download_admin_permissions>, mock_enqueue = <MagicMock name='enqueue' id='140268344491728'>\r\n\r\n    @mock.patch.object(log_exports_cleanup, \"enqueue\", return_value=None)\r\n    def test_csv_download_admin_permissions(self, mock_enqueue):\r\n        call_command(\r\n            \"exportlogs\",\r\n            log_type=\"summary\",\r\n            output_file=output_filename(\r\n                \"summary\",\r\n                self.facility,\r\n                start_date=self.start_date,\r\n                end_date=self.end_date,\r\n            ),\r\n            overwrite=True,\r\n            start_date=self.start_date,\r\n            end_date=self.end_date,\r\n        )\r\n        self.client.login(\r\n            username=self.admin.username,\r\n            password=DUMMY_PASSWORD,\r\n            facility=self.facility,\r\n        )\r\n        response = self.client.get(\r\n            reverse(\r\n                \"kolibri:kolibri.plugins.facility:download_csv_file\",\r\n                kwargs={\"csv_type\": \"summary\", \"facility_id\": self.facility.id},\r\n            )\r\n        )\r\n>       self.assertEqual(response.status_code, 200)\r\nE       AssertionError: 404 != 200\r\n\r\nkolibri/plugins/facility/test/test_api.py:149: AssertionError\r\n---------------------------------------------------------------------------------------------- Captured stdout setup ----------------------------------------------------------------------------------------------\r\nInstalled 2 object(s) from 1 fixture(s)\r\n---------------------------------------------------------------------------------------------- Captured stdout call -----------------------------------------------------------------------------------------------\r\nINFO     2024-03-01 16:58:51,322 Creating csv file /home/richard/github/kolibri/.pytest_kolibri_home/log_export/Rock N' Roll High School #0_0f6e_content_summary_logs_from_2020-10-21_to_2024-03-01.csv\r\nINFO     2024-03-01 16:58:51,327 Created csv file /home/richard/github/kolibri/.pytest_kolibri_home/log_export/Rock N' Roll High School #0_0f6e_content_summary_logs_from_2020-10-21_to_2024-03-01.csv with 3 lines\r\nINFO     2024-03-01 16:58:51,504 127.0.0.1 - - \"GET /facility/api/downloadcsvfile/summary/0f6ee14289d0447dbb105688560eee29/\" 404 0 \"\" \"unknown\"\r\nWARNING  2024-03-01 16:58:51,504 Not Found: /facility/api/downloadcsvfile/summary/0f6ee14289d0447dbb105688560eee29/\r\n------------------------------------------------------------------------------------------------ Captured log call ------------------------------------------------------------------------------------------------\r\ncsv_export.py              186 INFO     Creating csv file /home/richard/github/kolibri/.pytest_kolibri_home/log_export/Rock N' Roll High School #0_0f6e_content_summary_logs_from_2020-10-21_to_2024-03-01.csv\r\nexportlogs.py              159 INFO     Created csv file /home/richard/github/kolibri/.pytest_kolibri_home/log_export/Rock N' Roll High School #0_0f6e_content_summary_logs_from_2020-10-21_to_2024-03-01.csv with 3 lines\r\nlog.py                     224 WARNING  Not Found: /facility/api/downloadcsvfile/summary/0f6ee14289d0447dbb105688560eee29/\r\n_____________________________________________________________________ ContentSessionLogCSVExportTestCase.test_csv_download_admin_permissions ______________________________________________________________________\r\n\r\nself = <kolibri.plugins.facility.test.test_api.ContentSessionLogCSVExportTestCase testMethod=test_csv_download_admin_permissions>, mock_enqueue = <MagicMock name='enqueue' id='140268351318224'>\r\n\r\n    @mock.patch.object(log_exports_cleanup, \"enqueue\", return_value=None)\r\n    def test_csv_download_admin_permissions(self, mock_enqueue):\r\n        call_command(\r\n            \"exportlogs\",\r\n            log_type=\"session\",\r\n            output_file=output_filename(\r\n                \"session\",\r\n                self.facility,\r\n                start_date=self.start_date,\r\n                end_date=self.end_date,\r\n            ),\r\n            overwrite=True,\r\n            start_date=self.start_date,\r\n            end_date=self.end_date,\r\n        )\r\n        self.client.login(\r\n            username=self.admin.username,\r\n            password=DUMMY_PASSWORD,\r\n            facility=self.facility,\r\n        )\r\n        response = self.client.get(\r\n            reverse(\r\n                \"kolibri:kolibri.plugins.facility:download_csv_file\",\r\n                kwargs={\"csv_type\": \"session\", \"facility_id\": self.facility.id},\r\n            )\r\n        )\r\n>       self.assertEqual(response.status_code, 200)\r\nE       AssertionError: 404 != 200\r\n\r\nkolibri/plugins/facility/test/test_api.py:252: AssertionError\r\n---------------------------------------------------------------------------------------------- Captured stdout setup ----------------------------------------------------------------------------------------------\r\nInstalled 2 object(s) from 1 fixture(s)\r\n---------------------------------------------------------------------------------------------- Captured stdout call -----------------------------------------------------------------------------------------------\r\nINFO     2024-03-01 16:58:52,079 Creating csv file /home/richard/github/kolibri/.pytest_kolibri_home/log_export/Rock N' Roll High School #1_207d_content_session_logs_from_2020-10-21_to_2024-03-01.csv\r\nINFO     2024-03-01 16:58:52,084 Created csv file /home/richard/github/kolibri/.pytest_kolibri_home/log_export/Rock N' Roll High School #1_207d_content_session_logs_from_2020-10-21_to_2024-03-01.csv with 3 lines\r\nINFO     2024-03-01 16:58:52,177 127.0.0.1 - - \"GET /facility/api/downloadcsvfile/session/207d21f8516da5fad0659fc6488359d3/\" 404 0 \"\" \"unknown\"\r\nWARNING  2024-03-01 16:58:52,177 Not Found: /facility/api/downloadcsvfile/session/207d21f8516da5fad0659fc6488359d3/\r\n------------------------------------------------------------------------------------------------ Captured log call ------------------------------------------------------------------------------------------------\r\ncsv_export.py              186 INFO     Creating csv file /home/richard/github/kolibri/.pytest_kolibri_home/log_export/Rock N' Roll High School #1_207d_content_session_logs_from_2020-10-21_to_2024-03-01.csv\r\nexportlogs.py              159 INFO     Created csv file /home/richard/github/kolibri/.pytest_kolibri_home/log_export/Rock N' Roll High School #1_207d_content_session_logs_from_2020-10-21_to_2024-03-01.csv with 3 lines\r\nlog.py                     224 WARNING  Not Found: /facility/api/downloadcsvfile/session/207d21f8516da5fad0659fc6488359d3/\r\n======================================================================================= 2 failed, 7 passed in 13.86 seconds =======================================================================================\r\n```\r\n\r\nNote - I did a test of the actual functionality that relies on this in the Facility plugin, and observed no issues, so this seems at the moment to be purely a testing artifact.\r\n\r\n## Expected behavior\r\nTests should pass regardless of time of day or timezone!\r\n\r\n## User-facing consequences\r\nI think none - but would be good to work out why this is happening to be sure.\r\n\r\n## Steps to reproduce\r\nSet your system timezone to PST.\r\nSet your system time to after 4pm.\r\nRun the test suite above with pytest.\r\n\r\n## Context\r\n\r\nNoticed in the develop branch, but also extant on release-v0.16.x\r\n\n", "before_files": [{"content": "from django.utils import timezone\n\n\ndef local_now():\n    return timezone.localtime(timezone.now())\n\n\ndef naive_utc_datetime(dt):\n    return timezone.make_naive(dt, timezone=timezone.utc)\n", "path": "kolibri/utils/time_utils.py"}], "after_files": [{"content": "from django.utils import timezone\n\n\ndef local_now():\n    \"\"\"\n    Returns the current time in the local timezone.\n    \"\"\"\n    return timezone.localtime(timezone.now())\n\n\ndef utc_now():\n    \"\"\"\n    Returns the current time in the UTC timezone.\n    \"\"\"\n    return timezone.now()\n\n\ndef naive_utc_datetime(dt):\n    return timezone.make_naive(dt, timezone=timezone.utc)\n", "path": "kolibri/utils/time_utils.py"}]}