diff --git a/scancodeio/formats/__init__.py b/scancodeio/formats/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/scancodeio/formats/en/__init__.py b/scancodeio/formats/en/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/scancodeio/formats/en/formats.py b/scancodeio/formats/en/formats.py new file mode 100644 index 0000000000..399a438d3b --- /dev/null +++ b/scancodeio/formats/en/formats.py @@ -0,0 +1,24 @@ +# SPDX-License-Identifier: Apache-2.0 +# +# http://nexb.com and https://github.com/aboutcode-org/scancode.io +# The ScanCode.io software is licensed under the Apache License version 2.0. +# Data generated with ScanCode.io is provided as-is without warranties. +# ScanCode is a trademark of nexB Inc. +# +# You may not use this software except in compliance with the License. +# You may obtain a copy of the License at: http://apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software distributed +# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +# CONDITIONS OF ANY KIND, either express or implied. See the License for the +# specific language governing permissions and limitations under the License. +# +# Data Generated with ScanCode.io is provided on an "AS IS" BASIS, WITHOUT WARRANTIES +# OR CONDITIONS OF ANY KIND, either express or implied. No content created from +# ScanCode.io should be considered or used as legal advice. Consult an Attorney +# for any legal advice. +# +# ScanCode.io is a free software code scanning tool from nexB Inc. and others. +# Visit https://github.com/aboutcode-org/scancode.io for support and download. + +DATE_FORMAT = "M d, Y" +DATETIME_FORMAT = "Y-m-d H:i" diff --git a/scancodeio/middleware.py b/scancodeio/middleware.py new file mode 100644 index 0000000000..6b2d81119b --- /dev/null +++ b/scancodeio/middleware.py @@ -0,0 +1,48 @@ +# SPDX-License-Identifier: Apache-2.0 +# +# http://nexb.com and https://github.com/aboutcode-org/scancode.io +# The ScanCode.io software is licensed under the Apache License version 2.0. +# Data generated with ScanCode.io is provided as-is without warranties. +# ScanCode is a trademark of nexB Inc. +# +# You may not use this software except in compliance with the License. +# You may obtain a copy of the License at: http://apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software distributed +# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +# CONDITIONS OF ANY KIND, either express or implied. See the License for the +# specific language governing permissions and limitations under the License. +# +# Data Generated with ScanCode.io is provided on an "AS IS" BASIS, WITHOUT WARRANTIES +# OR CONDITIONS OF ANY KIND, either express or implied. No content created from +# ScanCode.io should be considered or used as legal advice. Consult an Attorney +# for any legal advice. +# +# ScanCode.io is a free software code scanning tool from nexB Inc. and others. +# Visit https://github.com/aboutcode-org/scancode.io for support and download. + +import zoneinfo + +from django.utils import timezone + + +def validate_timezone(tz): + """Return a valid timezone or None if invalid.""" + try: + return zoneinfo.ZoneInfo(tz).key + except (zoneinfo.ZoneInfoNotFoundError, TypeError, ValueError): + return + + +class TimezoneMiddleware: + def __init__(self, get_response): + self.get_response = get_response + + def __call__(self, request): + tz = validate_timezone(request.COOKIES.get("client_timezone")) + + if tz: + timezone.activate(zoneinfo.ZoneInfo(tz)) + else: + timezone.deactivate() + + return self.get_response(request) diff --git a/scancodeio/settings.py b/scancodeio/settings.py index 133171dac3..2324b22a50 100644 --- a/scancodeio/settings.py +++ b/scancodeio/settings.py @@ -207,6 +207,7 @@ "django.contrib.auth.middleware.AuthenticationMiddleware", "django.contrib.messages.middleware.MessageMiddleware", "django.middleware.clickjacking.XFrameOptionsMiddleware", + "scancodeio.middleware.TimezoneMiddleware", ] ROOT_URLCONF = "scancodeio.urls" @@ -348,6 +349,8 @@ LANGUAGE_CODE = "en-us" +FORMAT_MODULE_PATH = ["scancodeio.formats"] + TIME_ZONE = env.str("TIME_ZONE", default="UTC") USE_I18N = True diff --git a/scancodeio/static/main.js b/scancodeio/static/main.js index 3ecb2e6a8e..3904a57e20 100644 --- a/scancodeio/static/main.js +++ b/scancodeio/static/main.js @@ -404,6 +404,14 @@ document.addEventListener('DOMContentLoaded', function () { }); } + // Timezone + // Detects the user's current timezone using the browser's API + // and stores it in a cookie to be used by the backend for localization. + const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone; + if (timezone) { + document.cookie = `client_timezone=${timezone}; path=/; SameSite=Lax`; + } + }); // Toasts (requires bulma-toast.js) diff --git a/scanpipe/templates/scanpipe/includes/project_list_table.html b/scanpipe/templates/scanpipe/includes/project_list_table.html index 09d46773b6..c02e0a4668 100644 --- a/scanpipe/templates/scanpipe/includes/project_list_table.html +++ b/scanpipe/templates/scanpipe/includes/project_list_table.html @@ -1,4 +1,5 @@ {% load humanize %} +{% now "Y-m-d" as today %}