Skip to content
Closed
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
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ permissions:
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:

concurrency:
Expand Down
87 changes: 76 additions & 11 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,40 @@ async function deleteSingleEvent(ev){
const count=await removeHistoryEvents(e=>e.id===ev.id);
if(count)await notify(currentLang==='he'?'האירוע נמחק':'Event deleted','success');
}
function parseHebrewNumeral(value){
const raw=String(value||'').replace(/[\u0591-\u05C7״׳'".,\s]/g,'');
if(/^\d+$/.test(raw))return Number(raw);
const values={א:1,ב:2,ג:3,ד:4,ה:5,ו:6,ז:7,ח:8,ט:9,י:10,כ:20,ך:20,ל:30,מ:40,ם:40,נ:50,ן:50,ס:60,ע:70,פ:80,ף:80,צ:90,ץ:90,ק:100,ר:200,ש:300,ת:400};
if(!raw||![...raw].every(ch=>values[ch]))return NaN;
return [...raw].reduce((sum,ch)=>sum+values[ch],0);
}
function parseHebrewDateTimestamp(dateText,timeText){
const tokens=String(dateText||'').trim().split(/\s+/).filter(Boolean);
if(tokens.length<3)return NaN;
let day=parseHebrewNumeral(tokens[0]),year=parseHebrewNumeral(tokens[tokens.length-1]);
if(!Number.isFinite(day)||!Number.isFinite(year))return NaN;
if(year<1000)year+=5000;
const month=tokens.slice(1,-1).join(' ').replace(/[״׳'".]/g,'').replace(/\s+/g,' ').trim();
const normalize=s=>String(s||'').replace(/[״׳'".]/g,'').replace(/\s+/g,' ').trim();
const time=/^(\d{1,2}):(\d{2})$/.exec(timeText||'');
if(!time)return NaN;
const hours=Number(time[1]),minutes=Number(time[2]);
if(hours>23||minutes>59)return NaN;
const formatter=new Intl.DateTimeFormat('he-IL-u-ca-hebrew',{day:'numeric',month:'long',year:'numeric'});
const gregorianYear=year-3761;
const cursor=new Date(gregorianYear-1,0,1,12,0,0,0);
const limit=new Date(gregorianYear+2,0,1,12,0,0,0);
for(;cursor<limit;cursor.setDate(cursor.getDate()+1)){
const parts={};
for(const part of formatter.formatToParts(cursor))if(part.type!=='literal')parts[part.type]=part.value;
const actualYear=Number(String(parts.year||'').replace(/[^0-9]/g,''));
const actualDay=Number(String(parts.day||'').replace(/[^0-9]/g,''));
if(actualYear===year&&actualDay===day&&normalize(parts.month)===month){
return new Date(cursor.getFullYear(),cursor.getMonth(),cursor.getDate(),hours,minutes,0,0).getTime();
}
}
return NaN;
}
async function deleteDateRange(){
const he=currentLang==='he';
const picked=await new Promise(resolve=>{
Expand All @@ -618,25 +652,50 @@ async function deleteDateRange(){
ov=showModal(he?'מחיקת היסטוריה לפי טווח':'Delete history by date range',body=>{
const form=document.createElement('form');form.className='dateRangeDeleteForm';
const intro=document.createElement('p');intro.className='dialogMessage';intro.textContent=he?'בחר תאריכים ושעות. המחיקה חלה על האירועים בציר הזמן בלבד.':'Choose start and end times. This removes Timeline events only.';
const inputs=[];
const calendar=document.createElement('select');calendar.className='nativeDialogInput';
calendar.setAttribute('aria-label',he?'לוח תאריכים':'Calendar');
calendar.innerHTML=he?'<option value="hebrew">לוח עברי</option><option value="gregory">לוח לועזי</option>':'<option value="gregory">Gregorian calendar</option><option value="hebrew">Hebrew calendar</option>';
calendar.value=usingHebrewCalendar()?'hebrew':'gregory';
const calendarWrap=document.createElement('label');calendarWrap.className='dateRangeDeleteField';calendarWrap.textContent=he?'בחירת לוח':'Calendar';calendarWrap.appendChild(calendar);
form.appendChild(calendarWrap);
const groups=[];
for(const [key,title] of [['start',he?'מתאריך ושעה':'Start date and time'],['end',he?'עד תאריך ושעה':'End date and time']]){
const wrap=document.createElement('label');wrap.className='dateRangeDeleteField';wrap.textContent=title;
const input=document.createElement('input');input.type='datetime-local';input.required=true;input.name=key;input.className='nativeDialogInput';wrap.appendChild(input);form.appendChild(wrap);inputs.push(input);
const wrap=document.createElement('div');wrap.className='dateRangeDeleteField';
const label=document.createElement('span');label.textContent=title;wrap.appendChild(label);
const gregorian=document.createElement('input');gregorian.type='datetime-local';gregorian.required=true;gregorian.name=key+'Gregorian';gregorian.className='nativeDialogInput';
const hebrewWrap=document.createElement('div');hebrewWrap.className='hebrewDateEntry';
const hebrew=document.createElement('input');hebrew.type='text';hebrew.autocomplete='off';hebrew.dir='rtl';hebrew.placeholder='י״ד חשוון תשפ״ז';hebrew.setAttribute('aria-label',he?title+' — תאריך עברי':title+' — Hebrew date');
const time=document.createElement('input');time.type='time';time.value=key==='start'?'00:00':'23:59';time.setAttribute('aria-label',he?'שעה':'Time');
const hint=document.createElement('small');hint.className='dateRangeHebrewHint';hint.textContent=he?'יש להזין יום, חודש ושנה, למשל: י״ד חשוון תשפ״ז':'Enter day, Hebrew month, and year, e.g. 14 Cheshvan 5787';
hebrewWrap.append(hebrew,time,hint);wrap.append(gregorian,hebrewWrap);form.appendChild(wrap);
groups.push({gregorian,hebrew,time,hebrewWrap});
}
const getTimestamp=(group)=>{
if(calendar.value==='hebrew')return parseHebrewDateTimestamp(group.hebrew.value,group.time.value);
return group.gregorian.value?new Date(group.gregorian.value).getTime():NaN;
};
const syncCalendar=()=>{
for(const group of groups){
group.gregorian.hidden=calendar.value==='hebrew';
group.hebrewWrap.hidden=calendar.value!=='hebrew';
}
update();
};
const count=document.createElement('p');count.className='dialogMessage';
const actions=document.createElement('div');actions.className='dialogActions';
const cancel=document.createElement('button');cancel.type='button';cancel.className='actionGhost';cancel.textContent=tr('cancel');cancel.onclick=()=>finish(null);
const submit=document.createElement('button');submit.type='submit';submit.className='actionWarning';submit.textContent=he?'המשך למחיקה':'Continue to delete';submit.disabled=true;
const update=()=>{
const [from,to]=inputs.map(x=>x.value?new Date(x.value).getTime():NaN);
const [from,to]=groups.map(getTimestamp);
const valid=Number.isFinite(from)&&Number.isFinite(to)&&from<=to;
const total=valid?events.filter(e=>Number(e.time)>=from&&Number(e.time)<=to).length:0;
count.textContent=!valid?(he?'בחר טווח תאריכים תקין':'Choose a valid date range'):(he?'אירועים למחיקה: ':'Events to delete: ')+total;
submit.disabled=!valid||!total;
};
const actions=document.createElement('div');actions.className='dialogActions';
const cancel=document.createElement('button');cancel.type='button';cancel.className='actionGhost';cancel.textContent=tr('cancel');cancel.onclick=()=>finish(null);
const submit=document.createElement('button');submit.type='submit';submit.className='actionWarning';submit.textContent=he?'המשך למחיקה':'Continue to delete';submit.disabled=true;
inputs.forEach(x=>x.addEventListener('input',update));
form.onsubmit=e=>{e.preventDefault();if(!submit.disabled)finish(inputs.map(x=>new Date(x.value).getTime()))};
actions.append(cancel,submit);body.append(intro,form,count,actions);form.appendChild(actions);update();
groups.forEach(group=>[group.gregorian,group.hebrew,group.time].forEach(input=>input.addEventListener('input',update)));
calendar.addEventListener('change',syncCalendar);
form.onsubmit=e=>{e.preventDefault();if(!submit.disabled)finish(groups.map(getTimestamp))};
actions.append(cancel,submit);body.append(intro,form,count);form.appendChild(actions);syncCalendar();
});
ov.__requestClose=()=>finish(null);
});
Expand Down Expand Up @@ -1896,7 +1955,13 @@ function switchScreen(name){
if(name!=='settings'&&$('settingsScreen'))$('settingsScreen').classList.remove('settingsDialogOpen');
const valid=['timeline','overview','restore','analytics','diagnostics','settings'];
if(!valid.includes(name))name='timeline';
document.querySelectorAll('[data-screen-panel]').forEach(p=>{const active=p.dataset.screenPanel===name;p.classList.toggle('active',active);p.setAttribute('aria-hidden',active?'false':'true')});
document.querySelectorAll('[data-screen-panel]').forEach(p=>{
const isSettings=p.dataset.screenPanel==='settings';
const keepBehind=name==='settings'&&p.dataset.screenPanel===settingsScreenReturn;
const active=p.dataset.screenPanel===name||keepBehind;
p.classList.toggle('active',active);
p.setAttribute('aria-hidden',p.dataset.screenPanel===name?'false':'true');
});
document.querySelectorAll('.nav-item[data-screen]').forEach(b=>{
const active=b.dataset.screen===name;
b.classList.toggle('active',active);
Expand Down
22 changes: 21 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1165,8 +1165,12 @@
grid-template-columns:minmax(0,1fr) auto;
align-items:center;
gap:8px;
margin-bottom:8px;
margin:0;
order:0;
}
#settingsScreen .feedbackCompact{display:flex;flex-direction:column}
#settingsScreen .feedbackCompact .feedbackToolbar{order:0}
#settingsScreen .feedbackCompact .feedbackBox{order:1;margin-top:8px}
#settingsScreen .feedbackToolbar .appDropdown{width:100%;min-width:0;max-width:100%}
#settingsScreen .feedbackToolbar .btn{margin:0}
#settingsScreen .feedbackBox{
Expand Down Expand Up @@ -1669,6 +1673,22 @@
.dateRangeDeleteField{display:flex;flex-direction:column;gap:0.4rem;color:var(--color-on-surface);font-size:0.95rem}
.dateRangeDeleteField input{width:100%;min-height:2.5rem;color:var(--color-on-surface);background:var(--color-surface-container-high);border:1px solid var(--color-outline-variant);border-radius:var(--radius-sm);padding:0.5rem;font:inherit}
.dateRangeDeleteField input:focus-visible{outline:2px solid var(--color-primary);outline-offset:2px}
/* Feedback from users: keep the action row above the free-text field. */
#settingsScreen .feedbackCompact{display:flex;flex-direction:column}
#settingsScreen .feedbackCompact .feedbackToolbar{order:0;margin:0}
#settingsScreen .feedbackCompact .feedbackBox{order:1;margin-top:8px}

/* Settings are a sheet over the current screen, not a replacement screen. */
body.settings-sheet-visible::before{
content:"";position:fixed;inset:0;z-index:440;
background:color-mix(in srgb,var(--color-scrim) 28%,transparent);
pointer-events:none;
}
.modalOverlay{z-index:600}
.dateRangeDeleteField input[hidden],.hebrewDateEntry[hidden]{display:none}
.hebrewDateEntry{display:flex;flex-direction:column;gap:6px}
.hebrewDateEntry input{width:100%;min-height:2.5rem;color:var(--color-on-surface);background:var(--color-surface-container-high);border:1px solid var(--color-outline-variant);border-radius:var(--radius-sm);padding:0.5rem;font:inherit}
.dateRangeHebrewHint{color:var(--color-on-surface-variant);font-size:.78rem}
</style>
</head>
<body>
Expand Down
14 changes: 14 additions & 0 deletions tests/runtime-smoke.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,3 +306,17 @@ console.log('Dynamic 20-level heatmaps OK');

if(!app.includes("if(e.type==='setting'){const r=await call('navigation.goTo',{target:'settings'})"))throw new Error('Setting event navigation missing');
console.log('Setting event navigation guard OK');


// Hebrew-calendar date-range parsing regression checks.
const hebrewHelpersStart=app.indexOf('function parseHebrewNumeral');
const hebrewHelpersEnd=app.indexOf('async function deleteDateRange',hebrewHelpersStart);
if(hebrewHelpersStart<0||hebrewHelpersEnd<0) throw new Error('Hebrew date parsing helpers are missing');
const hebrewHelpers=app.slice(hebrewHelpersStart,hebrewHelpersEnd);
const hebrewDateTools=require('vm').runInNewContext(hebrewHelpers+';({parseHebrewNumeral,parseHebrewDateTimestamp})',{Intl,Date,Number,String,NaN});
if(hebrewDateTools.parseHebrewNumeral('י״ד')!==14) throw new Error('Hebrew day numeral parsing failed');
if(hebrewDateTools.parseHebrewNumeral('תשפ״ז')!==787) throw new Error('Hebrew year numeral parsing failed');
const hebrewTimestamp=hebrewDateTools.parseHebrewDateTimestamp('י״ד חשוון תשפ״ז','12:30');
if(!Number.isFinite(hebrewTimestamp)) throw new Error('Valid Hebrew date should convert to a timestamp');
if(Number.isFinite(hebrewDateTools.parseHebrewDateTimestamp('ל״א חשוון תשפ״ז','12:30'))) throw new Error('Invalid Hebrew date must be rejected');
console.log('Hebrew-calendar date-range parsing OK');
Loading