Java Code Examples for java.util.Calendar.getMaximum()

The following are Jave code examples for showing how to use getMaximum() of the java.util.Calendar class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: PasswordSafe-AndroidClient   File: AccountModel.java   View Source Code Vote up 8 votes
public boolean NeedsUpdate() {
    Calendar today = Calendar.getInstance();

    _logger.Debug("Today:\n" + today.toString());
    _logger.Debug("LastUpdate:\n" + _lastUpdate.toString());

    int daysSinceLastUpdate = today.get(Calendar.DAY_OF_YEAR) - _lastUpdate.get(Calendar.DAY_OF_YEAR);
    if (daysSinceLastUpdate < 0) {
        daysSinceLastUpdate += today.getMaximum(Calendar.DAY_OF_YEAR);
    }

    if (daysSinceLastUpdate >= _updateInterval) {
        _logger.Warn("Account needs update! " + String.valueOf(daysSinceLastUpdate));
        return true;
    }

    _logger.Debug("Account does not need an update!");

    return false;
}
 
Example 2
Project: airgram   File: FastDatePrinter.java   View Source Code Vote up 6 votes
/**
 * {@inheritDoc}
 */
@Override
public void appendTo(final StringBuffer buffer, final Calendar calendar) {
    int value = calendar.get(Calendar.HOUR_OF_DAY);
    if (value == 0) {
        value = calendar.getMaximum(Calendar.HOUR_OF_DAY) + 1;
    }
    mRule.appendTo(buffer, value);
}
 
Example 3
Project: lams   File: FastDateFormat.java   View Source Code Vote up 6 votes
/**
 * {@inheritDoc}
 */
public void appendTo(StringBuffer buffer, Calendar calendar) {
    int value = calendar.get(Calendar.HOUR_OF_DAY);
    if (value == 0) {
        value = calendar.getMaximum(Calendar.HOUR_OF_DAY) + 1;
    }
    mRule.appendTo(buffer, value);
}
 
Example 4
Project: PlusGram   File: FastDatePrinter.java   View Source Code Vote up 6 votes
/**
 * {@inheritDoc}
 */
@Override
public void appendTo(final StringBuffer buffer, final Calendar calendar) {
    int value = calendar.get(Calendar.HOUR_OF_DAY);
    if (value == 0) {
        value = calendar.getMaximum(Calendar.HOUR_OF_DAY) + 1;
    }
    mRule.appendTo(buffer, value);
}
 
Example 5
Project: openjdk-jdk10   File: CalendarRegression.java   View Source Code Vote up 6 votes
/**
 * Make sure maximum for HOUR field is 11, not 12.
 */
public void Test4118384() {
    Calendar cal = Calendar.getInstance();
    if (cal.getMaximum(HOUR) != 11
            || cal.getLeastMaximum(HOUR) != 11
            || cal.getActualMaximum(HOUR) != 11) {
        errln("Fail: maximum of HOUR field should be 11");
    }
}
 
Example 6
Project: ImageClassify   File: CalendarView.java   View Source Code Vote up 6 votes
/**
 * 界面渲染
 */
private void renderCalendar() {
    SimpleDateFormat sdf = new SimpleDateFormat(displayFormat);
    txtDate.setText(sdf.format(curDate.getTime()));
    selectedDate = curDate.getTime();

    if (cells == null) {
        cells = new ArrayList<>();
    } else {
        cells.clear();
    }
    Calendar calendar = (Calendar) curDate.clone();

    calendar.set(Calendar.DAY_OF_MONTH, 1);
    int prevDays = calendar.get(Calendar.DAY_OF_WEEK) - 1;
    calendar.add(Calendar.DAY_OF_MONTH, -prevDays);

    int maxCellCount;
    int maxDayNum = calendar.getMaximum(Calendar.DAY_OF_MONTH) + prevDays;
    //确定cells的数量
    if (maxDayNum > 5 * 7) {
        maxCellCount = 6 * 7;
    } else if (maxDayNum > 4 * 7) {
        maxCellCount = 5 * 7;
    } else {
        maxCellCount = 4 * 7;
    }
    while (cells.size() < maxCellCount) {
        cells.add(calendar.getTime());
        calendar.add(Calendar.DAY_OF_MONTH, 1);
    }
    calendarAdapter = new CalendarAdapter(getContext(), cells);
    calendarGridView.setAdapter(calendarAdapter);
}
 
Example 7
Project: incubator-netbeans   File: StringUtils.java   View Source Code Vote up 5 votes
private static int getDaysDifference(Calendar before, Calendar after) {
    int diff = after.get(Calendar.DAY_OF_YEAR) - before.get(Calendar.DAY_OF_YEAR);
    diff = diff + (before.getMaximum(Calendar.DAY_OF_YEAR) * (after.get(Calendar.YEAR) - before.get(Calendar.YEAR)));

    return diff;
}
 
Example 8
Project: incubator-netbeans   File: StringUtils.java   View Source Code Vote up 5 votes
private static int getWeekDifference(Calendar before, Calendar after) {
    int diff = after.get(Calendar.WEEK_OF_YEAR) - before.get(Calendar.WEEK_OF_YEAR);
    diff = diff + (before.getMaximum(Calendar.WEEK_OF_YEAR) * (after.get(Calendar.YEAR) - before.get(Calendar.YEAR)));

    return diff;
}
 
Example 9
Project: Tasks   File: TaskListFragment.java   View Source Code Vote up 5 votes
private void addRepeatTask(Task task){
    task.setAlreadyRepeating(true);

    Calendar repeatCalender = Calendar.getInstance();
    repeatCalender.setTimeInMillis(dateDialog.getDatePicker().getMaxDate());

    Calendar taskCalender = task.getTaskDate();

    int currentYear = taskCalender.get(Calendar.YEAR);
    int maxYear = repeatCalender.get(Calendar.YEAR);

    switch (task.getRepeatCategory()){
        case 1:
            int currentWeek = taskCalender.get(Calendar.WEEK_OF_YEAR);
            int maxWeek = repeatCalender.getMaximum(Calendar.WEEK_OF_YEAR);
            Log.d(TAG, "Adding weekly repeat task");
            while (currentYear < maxYear){
                if (currentYear > todayCalender.get(Calendar.YEAR)){
                    currentWeek = repeatCalender.getMinimum(Calendar.WEEK_OF_YEAR)- 1;
                }
                taskCalender.set(Calendar.YEAR, currentYear);
                while (currentWeek < maxWeek){
                    taskCalender.set(Calendar.WEEK_OF_YEAR, ++currentWeek);
                    task.setTaskDate(taskCalender);
                    presenter.addTask(task, true);
                    Log.d(TAG, "Adding for week - " + currentWeek);
                }
                currentYear++;
                Log.d(TAG, "Adding for year - " + currentYear);
            }
            break;
        case 2:
            int currentMonth = taskCalender.get(Calendar.MONTH);
            int maxMonth = repeatCalender.getMaximum(Calendar.MONTH);
            Log.d(TAG, "Adding monthly repeat task");
            while (currentYear < maxYear){
                if (currentYear > todayCalender.get(Calendar.YEAR)){
                    currentMonth = repeatCalender.getMinimum(Calendar.MONTH) - 1;
                }
                taskCalender.set(Calendar.YEAR, currentYear);
                while (currentMonth < maxMonth){
                    taskCalender.set(Calendar.MONTH,
                            ++currentMonth);
                    task.setTaskDate(taskCalender);
                    presenter.addTask(task, true);
                }
                currentYear++;
            }
            break;
        case 3:
            while (currentYear < maxYear){
                Log.d(TAG, "Adding yearly repeat task");
                taskCalender.set(Calendar.YEAR,
                        ++currentYear);
                task.setTaskDate(taskCalender);
                presenter.addTask(task, true);
            }
            break;
    }
}