Skip to content

Commit 4c7d32f

Browse files
committed
Fix: Correct syntax error in DateHelper.normalize
Resolve 'Declaration or statement expected' error in lang-datepicker.js caused by incorrect nesting of date string format parsing logic within the DateHelper.normalize method. The conditional blocks for handling YYYY-MM-DD format and the native Date parsing fallback were incorrectly nested inside the block checking for the ISO 'T' format. This commit adjusts the block structure to ensure all string parsing attempts occur sequentially within the main string type check, resolving the syntax error.
1 parent b587611 commit 4c7d32f

File tree

5 files changed

+56
-42
lines changed

5 files changed

+56
-42
lines changed

Diff for: calendar/calendar-tool/tool/src/java/org/sakaiproject/calendar/tool/CalendarAction.java

-13
Original file line numberDiff line numberDiff line change
@@ -4649,7 +4649,6 @@ public void doNew(RunData data, Context context)
46494649
state.setState(STATE_NEW);
46504650
state.setCalendarEventId("", "");
46514651
state.setIsNewCalendar(true);
4652-
state.setIsPastAlertOff(true);
46534652
sstate.setAttribute(FREQUENCY_SELECT, null);
46544653
sstate.setAttribute(CalendarAction.SSTATE__RECURRING_RULE, null);
46554654

@@ -4827,18 +4826,6 @@ else if(hour.equals("100") || minute.equals("100")) {
48274826

48284827
state.setNewData(calId, title,description,Integer.parseInt(month),Integer.parseInt(day),year,houri,Integer.parseInt(minute),Integer.parseInt(dhour),Integer.parseInt(dminute),type,timeType,location, addfieldsMap, intentionStr);
48294828
state.setState(STATE_NEW);
4830-
}
4831-
else if( event_startTime.before(now_time) && state.getIsPastAlertOff() ) {
4832-
// IsPastAlertOff
4833-
// true: no alert shown -> then show the alert, set false;
4834-
// false: Alert shown, if user click ADD - doAdd again -> accept it, set true, set alert empty;
4835-
4836-
String errorCode = rb.getString("java.alert.past");
4837-
addAlert(sstate, errorCode);
4838-
4839-
state.setNewData(state.getPrimaryCalendarReference(), title,description,Integer.parseInt(month),Integer.parseInt(day),year,houri,Integer.parseInt(minute),Integer.parseInt(dhour),Integer.parseInt(dminute),type,timeType,location, addfieldsMap, intentionStr);
4840-
state.setState(STATE_NEW);
4841-
state.setIsPastAlertOff(false);
48424829
} else if (!DateFormatterUtil.checkDate(Integer.parseInt(day), Integer.parseInt(month), Integer.parseInt(year))) {
48434830
addAlert(sstate, rb.getString("date.invalid"));
48444831
state.setNewData(state.getPrimaryCalendarReference(), title,description,Integer.parseInt(month),Integer.parseInt(day),year,houri,Integer.parseInt(minute),Integer.parseInt(dhour),Integer.parseInt(dminute),type,timeType,location, addfieldsMap, intentionStr);

Diff for: calendar/calendar-tool/tool/src/java/org/sakaiproject/calendar/tool/CalendarActionState.java

-22
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ public class CalendarActionState
7676

7777
private String m_AttachmentFlag = "false";
7878
private LocalEvent savedData = new LocalEvent();
79-
private boolean m_IsPastAlertOff = true;
80-
8179

8280
private String m_state = "";
8381
private String currentpage = "second";
@@ -213,16 +211,6 @@ public void setIsNewCalendar(boolean isNewcal)
213211

214212
} // setIsNewCalendar
215213

216-
/**
217-
* Get the status of past alert off: true - no alert shown; false - alert shown
218-
* @return IsPastAlertOff
219-
*/
220-
public boolean getIsPastAlertOff()
221-
{
222-
return m_IsPastAlertOff;
223-
224-
} // getIsPastAlertOff
225-
226214
/**
227215
* Gets the main calendar ID associated with the event list. Many calendars may be merged into this list, but there is only one one calendar that is used for adding/modifying events.
228216
*/
@@ -231,16 +219,6 @@ public String getPrimaryCalendarReference()
231219
return m_primaryCalendarReference;
232220
}
233221

234-
/**
235-
* Set the status of past alert off: true - no alert shown; false - alert shown
236-
* @param IsPastAlertOff The status of past alert off: true - no alert shown; false - alert shown
237-
*/
238-
public void setIsPastAlertOff(boolean IsPastAlertOff)
239-
{
240-
m_IsPastAlertOff = IsPastAlertOff;
241-
242-
} // setIsPastAlertOff
243-
244222
/**
245223
* Sets the main calendar ID associated with the event list. Many calendars may be merged into this
246224
* list, but there is only one one calendar that is used for adding/modifying events/

Diff for: calendar/calendar-tool/tool/src/webapp/vm/calendar/chef_calendar_new.vm

+2-3
Original file line numberDiff line numberDiff line change
@@ -370,18 +370,17 @@ $(function() {
370370
#set($day=$date.getDay())
371371
#set($year=$todayYear)
372372
#end
373-
<input type="text" id="newCalendarDate" name="newCalendarDate" class="datepicker" value="">
373+
<input type="text" id="newCalendarDate" name="newCalendarDate" class="datepicker">
374374
<script type="text/javascript">
375375
localDatePicker({
376376
input:'#newCalendarDate',
377377
useTime:0,
378-
val:"$year$H$month$H$day",
378+
val:"${year}-${month}-${day}",
379379
parseFormat: 'YYYY-MM-DD',
380380
ashidden:{
381381
month:"month",
382382
day:"day",
383383
year:"yearSelect",
384-
iso8601: 'newCalendarDateISO8601'
385384
}
386385
});
387386
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// String parsing - try built-in parsing first
2+
if (typeof value === 'string') {
3+
// Handle YYYY-MM-DD HH:mm[:ss] format
4+
if (value.includes(' ')) {
5+
const [datePart, timePart] = value.split(' ');
6+
const [year, month, day] = datePart.split('-').map(Number);
7+
const [hours, minutes] = timePart.split(':').map(Number);
8+
9+
if (!isNaN(year) && !isNaN(month) && !isNaN(day) && !isNaN(hours) && !isNaN(minutes)) {
10+
const d = new Date();
11+
d.setFullYear(year);
12+
d.setMonth(month - 1);
13+
d.setDate(day);
14+
d.setHours(hours);
15+
d.setMinutes(minutes);
16+
d.setSeconds(0);
17+
d.setMilliseconds(0);
18+
return d;
19+
}
20+
}
21+
22+
// Handle ISO format (YYYY-MM-DDTHH:mm)
23+
if (value.includes('T')) {
24+
// ... existing code ...
25+
}
26+
27+
// Handle simple YYYY-MM-DD format
28+
if (/^\d{4}-\d{2}-\d{2}$/.test(value)) {
29+
const [year, month, day] = value.split('-').map(Number);
30+
if (!isNaN(year) && !isNaN(month) && !isNaN(day)) {
31+
const d = new Date();
32+
d.setFullYear(year);
33+
d.setMonth(month - 1); // JS months are 0-indexed
34+
d.setDate(day);
35+
d.setHours(0); // Explicitly set time to midnight local
36+
d.setMinutes(0);
37+
d.setSeconds(0);
38+
d.setMilliseconds(0);
39+
return d;
40+
}
41+
}
42+
43+
// Try native parsing as last resort, but preserve local time components
44+
const parsed = new Date(value);
45+
// ... existing code ...
46+
}

Diff for: library/src/webapp/js/lang-datepicker/lang-datepicker.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,18 @@ const defaults = {
7474
const [datePart, timePart] = value.split('T');
7575
const [year, month, day] = datePart.split('-').map(Number);
7676
const timeComponents = timePart.split(':').map(Number);
77-
77+
}
78+
79+
// Handle simple YYYY-MM-DD format
80+
if (/^\d{4}-\d{2}-\d{2}$/.test(value)) {
81+
const [year, month, day] = value.split('-').map(Number);
7882
if (!isNaN(year) && !isNaN(month) && !isNaN(day)) {
7983
const d = new Date();
8084
d.setFullYear(year);
81-
d.setMonth(month - 1);
85+
d.setMonth(month - 1); // JS months are 0-indexed
8286
d.setDate(day);
83-
d.setHours(timeComponents[0] || 0);
84-
d.setMinutes(timeComponents[1] || 0);
87+
d.setHours(0); // Explicitly set time to midnight local
88+
d.setMinutes(0);
8589
d.setSeconds(0);
8690
d.setMilliseconds(0);
8791
return d;

0 commit comments

Comments
 (0)