From a2908138048a035dba60d5a65ed10874e0550c40 Mon Sep 17 00:00:00 2001 From: Andrew Kreps Date: Mon, 4 May 2026 08:11:32 -0700 Subject: [PATCH] =?UTF-8?q?datepicker.js=20=E2=80=94=203=20fixes:=20=20=20?= =?UTF-8?q?-=20Added=20getPacificToday()=20using=20Intl.DateTimeFormat=20w?= =?UTF-8?q?ith=20timeZone:=20'America/Los=5FAngeles',=20which=20returns=20?= =?UTF-8?q?the=20correct=20Pacific=20date=20regardless=20of=20the=20browse?= =?UTF-8?q?r's=20timezone=20=20=20-=20isToday()=20now=20compares=20against?= =?UTF-8?q?=20the=20Pacific=20date=20instead=20of=20the=20local=20date=20?= =?UTF-8?q?=20=20-=20toUtcString()=20no=20longer=20calls=20.utc()=20?= =?UTF-8?q?=E2=80=94=20converting=20local-midnight=20dayjs=20objects=20to?= =?UTF-8?q?=20UTC=20was=20shifting=20dates=20backward=20for=20users=20east?= =?UTF-8?q?=20of=20UTC=20(e.g.,=20a=20user=20clicking=20"Jan=205"=20in=20t?= =?UTF-8?q?he=20calendar=20=20=20would=20accidentally=20store=20Jan=C2=A04?= =?UTF-8?q?)=20=20=20-=20initDatePicker()=20now=20starts=20from=20the=20Pa?= =?UTF-8?q?cific=20"today"=20date?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit addevent.js — 1 fix: - 'hh:mm:ss' → 'HH:mm:ss' in the preview time parser; the lowercase hh is 12-hour format and would misparse afternoon times like "14:30:00", causing the preview to display wrong end times for PM events main.js — 1 fix: - Same 'hh:mm:ss' → 'HH:mm:ss' fix for event time display in the calendar list view --- .../s2b_hugo_theme/assets/js/cal/addevent.js | 4 +-- .../assets/js/cal/datepicker.js | 25 +++++++++++++------ .../s2b_hugo_theme/assets/js/cal/main.js | 4 +-- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/site/themes/s2b_hugo_theme/assets/js/cal/addevent.js b/site/themes/s2b_hugo_theme/assets/js/cal/addevent.js index 6223b0822..633417ebf 100644 --- a/site/themes/s2b_hugo_theme/assets/js/cal/addevent.js +++ b/site/themes/s2b_hugo_theme/assets/js/cal/addevent.js @@ -323,9 +323,9 @@ var $form = $('#event-entry'); $.extend(previewEvent, shiftEvent, eventFromForm()); - previewEvent['displayStartTime'] = dayjs(previewEvent['time'], 'hh:mm:ss').format('h:mm A'); + previewEvent['displayStartTime'] = dayjs(previewEvent['time'], 'HH:mm:ss').format('h:mm A'); if ( previewEvent['eventduration'] ){ - var endTime = dayjs(previewEvent['time'], 'hh:mm:ss') + var endTime = dayjs(previewEvent['time'], 'HH:mm:ss') .add(previewEvent['eventduration'], 'minutes') .format('HH:mm'); previewEvent['endtime'] = endTime; // e.g. 18:00 diff --git a/site/themes/s2b_hugo_theme/assets/js/cal/datepicker.js b/site/themes/s2b_hugo_theme/assets/js/cal/datepicker.js index 43107fa00..ec2e9d128 100644 --- a/site/themes/s2b_hugo_theme/assets/js/cal/datepicker.js +++ b/site/themes/s2b_hugo_theme/assets/js/cal/datepicker.js @@ -125,17 +125,26 @@ return Mustache.render(dateStatusesTemplate, {dateStatuses}); } + // Return the current date in Pacific time as a YYYY-MM-DD string. + // Using Intl.DateTimeFormat ensures correctness regardless of the browser's local timezone. + function getPacificToday() { + return new Date().toLocaleDateString('en-CA', { + timeZone: 'America/Los_Angeles', + year: 'numeric', + month: '2-digit', + day: '2-digit' + }); + } + function isToday(date) { - return dayjs().isSame(date, 'day'); + return dayjs(date).format('YYYY-MM-DD') === getPacificToday(); } - // return the utc YYYY-MM-DD string of the passed date - // note: 'date' is sometimes a utc string, or a dayjs object. + // return the YYYY-MM-DD string of the passed date + // note: 'date' is sometimes a string, or a dayjs object. // see also: main.js viewEvents() - function toUtcString(date) { - // tbd: does the server actually handle dates as utc? - // i believe times ( ex. start times ) are assumed local. - return dayjs(date).utc().format('YYYY-MM-DD'); + function toUtcString(date) { + return dayjs(date).format('YYYY-MM-DD'); } function isSelected(date) { @@ -237,7 +246,7 @@ // fix: should this scroll the first scheduled day into view // ( ex. when editing existing events ) function initDatePicker() { - const now = dayjs(); + const now = dayjs(getPacificToday()); earliestMonth = now; latestMonth = now.add(1, 'month'); diff --git a/site/themes/s2b_hugo_theme/assets/js/cal/main.js b/site/themes/s2b_hugo_theme/assets/js/cal/main.js index dd913a1d2..ec50f948b 100755 --- a/site/themes/s2b_hugo_theme/assets/js/cal/main.js +++ b/site/themes/s2b_hugo_theme/assets/js/cal/main.js @@ -36,10 +36,10 @@ $(document).ready(function() { mustacheData.dates.push(groupedByDate[date]); } - value.displayStartTime = dayjs(value.time, 'hh:mm:ss').format('h:mm A'); + value.displayStartTime = dayjs(value.time, 'HH:mm:ss').format('h:mm A'); value.displayDate = dayjs(value.date).format('ddd, MMM D, YYYY'); if (value.endtime) { - value.displayEndTime = dayjs(value.endtime, 'hh:mm:ss').format('h:mm A'); + value.displayEndTime = dayjs(value.endtime, 'HH:mm:ss').format('h:mm A'); } value.audienceLabel = container.getAudienceLabel(value.audience);