Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/apireview.net/App.razor
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@
<script src="_framework/blazor.web.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="js/bootstrap.bundle.min.js"></script>
<script src="js/localizeTime.js"></script>
</body>
</html>
37 changes: 1 addition & 36 deletions src/apireview.net/Pages/Schedule.razor
Original file line number Diff line number Diff line change
Expand Up @@ -51,39 +51,4 @@
<p class="mt-3 text-muted">
Videos are streamed to the <a href="https://www.youtube.com/@@NETFoundation/streams">.NET Foundation YouTube channel</a>.
This calendar is available <a href="@CalendarService.Url">as an .ics file</a> you can add to your favorite calendar app.
</p>

@ladeak ladeak Mar 31, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved this as is to a js file, and added observeUrlChange to trigger it.


<script>
(function () {
// Update <time> elements to user's local time,
// but if the date would differ keep Pacific time and show PST/PDT
document.querySelectorAll('time[datetime]').forEach(function (el) {
var isoStr = el.getAttribute('datetime');
var dt = new Date(isoStr);
var cell = el.closest('[data-date]');
var cellDate = cell ? cell.getAttribute('data-date') : null;
var localDate = dt.getFullYear() + '-' +
String(dt.getMonth() + 1).padStart(2, '0') + '-' +
String(dt.getDate()).padStart(2, '0');
if (cellDate && localDate !== cellDate) {
// Date would change — keep Pacific time; label it PST or PDT from the offset
var offsetMatch = isoStr.match(/([+-]\d{2}):\d{2}$/);
var tzLabel = (offsetMatch && offsetMatch[1] === '-07') ? 'PDT' : 'PST';
el.textContent = el.textContent + '\u00a0' + tzLabel;
} else {
el.textContent = dt.toLocaleTimeString([], { hour: 'numeric', minute: '2-digit' });
}
});

// Re-highlight today/past cells using the user's local date
var now = new Date();
var todayStr = now.getFullYear() + '-' +
String(now.getMonth() + 1).padStart(2, '0') + '-' +
String(now.getDate()).padStart(2, '0');
document.querySelectorAll('[data-date]').forEach(function (el) {
var d = el.getAttribute('data-date');
el.classList.toggle('today', d === todayStr);
el.classList.toggle('past', d < todayStr);
});
})();
</script>
</p>
50 changes: 50 additions & 0 deletions src/apireview.net/wwwroot/js/localizeTime.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
function localizeTime() {
// Update <time> elements to user's local time,
// but if the date would differ keep Pacific time and show PST/PDT
document.querySelectorAll('time[datetime]').forEach(function (el) {
var isoStr = el.getAttribute('datetime');
var dt = new Date(isoStr);
var cell = el.closest('[data-date]');
var cellDate = cell ? cell.getAttribute('data-date') : null;
var localDate = dt.getFullYear() + '-' +
String(dt.getMonth() + 1).padStart(2, '0') + '-' +
String(dt.getDate()).padStart(2, '0');
if (cellDate && localDate !== cellDate) {
// Date would change — keep Pacific time; label it PST or PDT from the offset
var offsetMatch = isoStr.match(/([+-]\d{2}):\d{2}$/);
var tzLabel = (offsetMatch && offsetMatch[1] === '-07') ? 'PDT' : 'PST';
el.textContent = el.textContent + '\u00a0' + tzLabel;
} else {
el.textContent = dt.toLocaleTimeString([], { hour: 'numeric', minute: '2-digit' });
}
});

// Re-highlight today/past cells using the user's local date
var now = new Date();
var todayStr = now.getFullYear() + '-' +
String(now.getMonth() + 1).padStart(2, '0') + '-' +
String(now.getDate()).padStart(2, '0');
document.querySelectorAll('[data-date]').forEach(function (el) {
var d = el.getAttribute('data-date');
el.classList.toggle('today', d === todayStr);
el.classList.toggle('past', d < todayStr);
});
}

const observeUrlChange = () => {
if (document.location.href.includes("/schedule")) {
localizeTime();
}
let oldHref = document.location.href;
const body = document.querySelector("body");
const observer = new MutationObserver(mutations => {
if (oldHref !== document.location.href) {
oldHref = document.location.href;
if (document.location.href.includes("/schedule")) {
localizeTime();
}
}
});
observer.observe(body, { childList: true, subtree: true });
};
window.onload = observeUrlChange;
Loading