In the Calendar, the month will incorrectly show the label for the previous month if a call to DateUtil.setDefaultDisplayTimezone is made where the offset specifies an early TimeZone than the server is running in.
So right now, given my server is in Eastern time (-04:00), if a call to setDefaultDisplayTimezone ("-03:00") is made and then the Calendar displayed, it will show "May" as the month even though the Calendar dates are in fact June.
(see attached images).
Using: SmartClient Version: v10.1p_2016-04-20/Pro Deployment (built 2016-04-20)
Below is sample code to reproduce the problem. Just use the "Set TimeZone" menu button and pick an offset earlier than your server and look at the label on the Month. Also (as seen in cal_bad image), if you select a date on the Calendar you will see it is the proper value of June ... for the actual Date.
So right now, given my server is in Eastern time (-04:00), if a call to setDefaultDisplayTimezone ("-03:00") is made and then the Calendar displayed, it will show "May" as the month even though the Calendar dates are in fact June.
(see attached images).
Using: SmartClient Version: v10.1p_2016-04-20/Pro Deployment (built 2016-04-20)
Below is sample code to reproduce the problem. Just use the "Set TimeZone" menu button and pick an offset earlier than your server and look at the label on the Month. Also (as seen in cal_bad image), if you select a date on the Calendar you will see it is the proper value of June ... for the actual Date.
Code:
public class CalTest implements EntryPoint { private DateDisplayFormatter dayFormatter = new DateDisplayFormatter() { @Override public String format(Date date) { if (date == null) return null; DateTimeFormat dateFormatter = DateTimeFormat.getFormat("dd"); return dateFormatter.format(date); } }; private Layout layout = new VLayout(10); private Set<Date> dates = new TreeSet<>(); private Label info = new Label(); private Calendar calendar; @Override public void onModuleLoad() { info.setWidth100(); info.setHeight(50); layout.setWidth100(); layout.setHeight100(); layout.setMargin(30); layout.addMember(info); createSetDefaultDisplayTimezone(); createCalendar(); layout.draw(); } private void createCalendar() { if (calendar != null) calendar.destroy(); calendar = new Calendar() { @Override public String getDayBodyHTML(Date date, CalendarEvent[] events, Calendar calendar, int rowNum, int colNum) { String returnStr = dayFormatter.format(date) + ""; if (dates.contains(date)) { returnStr += imgHTML("[SKIN]actions/approve.png", 16, 16, "image", null, null); } return returnStr; } }; calendar.setWidth(400); calendar.setHeight(220); calendar.setShowDayView(false); calendar.setShowWeekView(false); calendar.setShowOtherDays(false); calendar.setShowDayHeaders(false); calendar.setShowDatePickerButton(true); calendar.setShowAddEventButton(false); calendar.setDisableWeekends(false); calendar.setShowDateChooser(true); calendar.setCanCreateEvents(false); calendar.addDayBodyClickHandler(new DayBodyClickHandler() { @Override public void onDayBodyClick(DayBodyClickEvent event) { Date date = event.getDate(); if (dates.contains(date)) { info.setContents("" + date + " removed."); dates.remove(date); } else { info.setContents("" + date + " added."); dates.add(date); } calendar.markForRedraw(); } }); layout.addMember(calendar); } private void setTimezoneAndRecreateCalendar(String value) { if (value == null) return; DateUtil.setDefaultDisplayTimezone(value); info.setContents("DateUtil.setDefaultDisplayTimezone(" + value + ")"); layout.removeMember(calendar); createCalendar(); layout.markForRedraw(); } private void createSetDefaultDisplayTimezone() { Menu menu = new Menu(); for (int i = 3; i <= 9; i++) { String tz = "-0" + i + ":00"; final MenuItem item = new MenuItem(tz); item.addClickHandler(new com.smartgwt.client.widgets.menu.events.ClickHandler() { @Override public void onClick(MenuItemClickEvent event) { setTimezoneAndRecreateCalendar(item.getTitle()); } }); menu.addItem(item); } MenuButton mb = new MenuButton("Set TimeZone", menu); layout.addMember(mb); } }
Comment