1/* =========================================================================== 2 bsw-live-dates.js 3 BroadbandSwitch.uk: every "today" stamp on the site, driven by one engine 4 5 THE BUG THIS FIXES. The hero byline read "Reviewed today, 22nd August 6 2026" on 23 August. A stamp that says "today" and then freezes is worse 7 than no stamp: one stale day teaches the visitor that every freshness 8 label on the site is decorative. 9 10 WHAT IT DOES. On every page load, computes the current date IN THE 11 EUROPE/LONDON TIMEZONE (a UTC clock would show yesterday's date to a UK 12 visitor after midnight in summer) and writes it into: 13 14 #bswReviewed "23rd August 2026" the hero byline 15 #bswSaveMonth (pinned) the savings footnote month. NOT rolled by the 16 clock: it is read from window.BSW_LIVE.month, 17 set when the figure is recalculated 18 [data-bsw-today] any element opting in: 19 data-bsw-today -> "23rd August 2026" 20 data-bsw-today="month" -> "August 2026" 21 data-bsw-today="short" -> "23 Aug 2026" 22 and any of those that are <time> elements get datetime="2026-08-23". 23 24 HOW TO INSTALL. Serve as /assets/js/bsw-live-dates.js and load it on 25 every page, last in the body: 26 27 <script src="/assets/js/bsw-live-dates.js" defer></script> 28 29 It is a single guarded IIFE with no dependencies. It cannot be killed by 30 another script's error, and if IT fails, the server-rendered date remains, 31 so keep stamping the build date into the HTML as the no-JS fallback. 32 33 TESTING. Set window.BSW_NOW = '2026-09-01T09:00:00Z' BEFORE this script 34 runs and every stamp renders as 1st September 2026. Remove it for 35 production, where the real clock is used. 36 =========================================================================== */ 37 38(function () { 39 'use strict'; 40 try { 41 var now = new Date(window.BSW_NOW || Date.now()); 42 if (isNaN(now)) now = new Date(); 43 44 function parts(opts) { 45 var o = { timeZone: 'Europe/London' }; 46 for (var k in opts) o[k] = opts[k]; 47 var out = {}; 48 new Intl.DateTimeFormat('en-GB', o).formatToParts(now).forEach(function (p) { 49 out[p.type] = p.value; 50 }); 51 return out; 52 } 53 54 var full = parts({ day: 'numeric', month: 'long', year: 'numeric' }); 55 var num = parts({ day: '2-digit', month: '2-digit', year: 'numeric' }); 56 var abbr = parts({ day: 'numeric', month: 'short', year: 'numeric' }); 57 58 var day = parseInt(full.day, 10); 59 var ord = (day > 3 && day < 21) ? 'th' : (['th', 'st', 'nd', 'rd'][day % 10] || 'th'); 60 61 var LONG = day + ord + ' ' + full.month + ' ' + full.year; /* 23rd August 2026 */ 62 var MONTH = full.month + ' ' + full.year; /* August 2026 */ 63 var SHORT = abbr.day + ' ' + abbr.month + ' ' + abbr.year; /* 23 Aug 2026 */ 64 var ISO = num.year + '-' + num.month + '-' + num.day; /* 2026-08-23 */ 65 66 function write(el, text) { 67 if (!el || el.textContent === text) return; 68 el.textContent = text; 69 if (el.tagName === 'TIME') el.setAttribute('datetime', ISO); 70 } 71 72 write(document.getElementById('bswReviewed'), LONG); 73 /* The savings footnote month is NOT a "today" stamp. It names the month the 74 figure was last calculated, so it comes from window.BSW_LIVE.month, which 75 the monthly deals refresh pins. It never rolls over with the clock. */ 76 var pinnedMonth = window.BSW_LIVE && window.BSW_LIVE.month; 77 if (pinnedMonth) write(document.getElementById('bswSaveMonth'), pinnedMonth); 78 79 var opted = document.querySelectorAll('[data-bsw-today]'); 80 for (var i = 0; i < opted.length; i++) { 81 var mode = opted[i].getAttribute('data-bsw-today'); 82 write(opted[i], mode === 'month' ? MONTH : mode === 'short' ? SHORT : LONG); 83 } 84 85 /* shared, for anything else that wants the same clock */ 86 window.BSW_LIVE = window.BSW_LIVE || {}; 87 window.BSW_LIVE.today = { long: LONG, month: MONTH, short: SHORT, iso: ISO }; 88 } catch (e) { /* the server-rendered date stays; never break the page */ } 89})();
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.