PageSourceSearch

https://pmi-france.org/js/event_datetime.js?1783005576

js pmi-france.org collected 2026-09-24 09:55:56 UTC 2,393 bytes, 73 lines download raw bytes

1/**
2 * Convertit la date d'un évènement (timestamp UTC) vers l'heure locale
3 * du navigateur si son fuseau horaire diffère de celui de l'évènement.
4 *
5 * Cible tous les éléments .event-datetime ayant data-utc-datetime
6 * et data-event-timezone.
7 */
8(function () {
9    function getLocalTimezone() {
10        try {
11            return Intl.DateTimeFormat().resolvedOptions().timeZone || '';
12        } catch (e) {
13            return '';
14        }
15    }
16
17    function formatLocalDateTime(dateObj, timezone) {
18        var options = {
19            day: '2-digit',
20            month: 'long',
21            year: 'numeric',
22            hour: '2-digit',
23            minute: '2-digit',
24            timeZone: timezone
25        };
26        try {
27            return dateObj.toLocaleString('fr-FR', options);
28        } catch (e) {
29            return dateObj.toLocaleString('fr-FR');
30        }
31    }
32
33    function init() {
34        var tzLocal = getLocalTimezone();
35        if (!tzLocal) return;
36
37        var elements = document.querySelectorAll('.event-datetime');
38        elements.forEach(function (el) {
39            var utcStr = el.getAttribute('data-utc-datetime');
40            var tzEvent = el.getAttribute('data-event-timezone');
41            if (!utcStr || !tzEvent) return;
42
43            // Si l'utilisateur est dans le même fuseau, on masque la mention du fuseau
44            // pour éviter le bruit visuel — pas besoin de doubler l'info.
45            if (tzLocal === tzEvent) {
46                var timezoneTag = el.querySelector('.timezone-event');
47                if (timezoneTag) {
48                    timezoneTag.classList.add('d-none');
49                }
50                return;
51            }
52
53            var d = new Date(utcStr);
54            if (isNaN(d.getTime())) return;
55
56            var local = el.querySelector('.event-datetime-local');
57            var datetimeLocal = el.querySelector('.datetime-local');
58            if (!local || !datetimeLocal) return;
59
60            datetimeLocal.textContent = formatLocalDateTime(d, tzLocal) + ' (' + tzLocal + ')';
61            local.classList.remove('d-none');
62        });
63    }
64
65    if (document.readyState === 'loading') {
66        document.addEventListener('DOMContentLoaded', init);
67    } else {
68        init();
69    }
70
71    // Expose pour usage manuel (ex : après render dynamique d'un popup Leaflet)
72    window.refreshEventDatetime = init;
73})();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.