Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed calendar to integrate usage of add #3885

Merged
merged 2 commits into from
Mar 15, 2025
Merged
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
33 changes: 12 additions & 21 deletions CodenameOne/src/com/codename1/ui/Calendar.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,6 @@ public class Calendar extends Container implements ActionSource {
private static final String[] MONTHS = new String[]{"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
private static final String[] DAYS = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
private static final String[] LABELS = {"Su", "M", "Tu", "W", "Th", "F", "Sa"};
static final long MINUTE = 1000 * 60;
static final long HOUR = MINUTE * 60;
static final long DAY = HOUR * 24;
static final long WEEK = DAY * 7;
private EventDispatcher dispatcher = new EventDispatcher();
private EventDispatcher dataChangedListeners = new EventDispatcher();
private EventDispatcher monthChangedListeners = new EventDispatcher();
Expand Down Expand Up @@ -1047,19 +1043,15 @@ private void setCurrentDay(long day, boolean force) {
cal.set(java.util.Calendar.DAY_OF_MONTH, 1);
long startDate = cal.getTime().getTime();
int dow = cal.get(java.util.Calendar.DAY_OF_WEEK);
cal.setTime(new Date(cal.getTime().getTime() - DAY));
cal.set(java.util.Calendar.HOUR, 1);
cal.set(java.util.Calendar.HOUR_OF_DAY, 1);
cal.set(java.util.Calendar.MINUTE, 0);
cal.set(java.util.Calendar.SECOND, 0);
cal.set(java.util.Calendar.MILLISECOND, 0);
cal.setTime(new Date(cal.getTime().getTime()));
cal.add(java.util.Calendar.DAY_OF_MONTH, -1);
int lastDay = cal.get(java.util.Calendar.DAY_OF_MONTH);
int i = 0;
if (dow > java.util.Calendar.SUNDAY) {
//last day of previous month

while (dow > java.util.Calendar.SUNDAY) {
cal.setTime(new Date(cal.getTime().getTime() - DAY));
cal.add(java.util.Calendar.DAY_OF_MONTH, -1);
dow = cal.get(java.util.Calendar.DAY_OF_WEEK);
}
int previousMonthSunday = cal.get(java.util.Calendar.DAY_OF_MONTH);
Expand All @@ -1071,8 +1063,9 @@ private void setCurrentDay(long day, boolean force) {
}
//last day of current month
cal.set(java.util.Calendar.MONTH, (month + 1) % 12);
cal.set(java.util.Calendar.DAY_OF_MONTH, 1);
cal.setTime(new Date(cal.getTime().getTime() - DAY));
while(cal.get(java.util.Calendar.MONTH) != month) {
cal.add(java.util.Calendar.DAY_OF_MONTH, -1);
}

lastDay = cal.get(java.util.Calendar.DAY_OF_MONTH);

Expand All @@ -1099,7 +1092,9 @@ private void setCurrentDay(long day, boolean force) {
}
}
updateButtonDayDate(components[j], yearNew, month, j - i + 1);
startDate += DAY;
cal.setTime(new Date(startDate));
cal.add(java.util.Calendar.DAY_OF_MONTH, 1);
startDate = cal.getTime().getTime();
}
int d = 1;
for (; j < components.length; j++) {
Expand Down Expand Up @@ -1156,16 +1151,12 @@ private void setMonth(int year, int month) {
cal.set(java.util.Calendar.DAY_OF_MONTH, 1);
cal.set(java.util.Calendar.YEAR, year);

Date date = cal.getTime();
long d = date.getTime();

// if this is past the last day of the month (e.g. going from January 31st
// to Febuary) we need to decrement the day until the month is correct
// to February) we need to decrement the day until the month is correct
while (cal.get(java.util.Calendar.MONTH) != month) {
d -= DAY;
cal.setTime(new Date(d));
cal.add(java.util.Calendar.DAY_OF_MONTH, -1);
}
setCurrentDay(d);
setCurrentDay(cal.getTime().getTime());
}

public void decrementMonth() {
Expand Down