Example usage for java.util Calendar DAY_OF_YEAR

List of usage examples for java.util Calendar DAY_OF_YEAR

Introduction

In this page you can find the example usage for java.util Calendar DAY_OF_YEAR.

Prototype

int DAY_OF_YEAR

To view the source code for java.util Calendar DAY_OF_YEAR.

Click Source Link

Document

Field number for get and set indicating the day number within the current year.

Usage

From source file:DateUtil.java

/**
 * Returns true if the two calendars represent dates that fall in the same
 * week, else false. A week here is defined by the Calendar.WEEK_OF_YEAR
 * package. Special provisions have been made to test weeks than may span the
 * end/beginning of a year, and returning true if the two calendars are
 * specifying dates within such a week, despite Calendar.WEEK_OF_YEAR being
 * unequal for the two Calendars./* w w w . ja  va  2 s. c o m*/
 * 
 * @param c1
 *          Calendar one.
 * @param c2
 *          Calendar two.
 * @return boolean.
 */
public static boolean inSameWeek(Calendar c1, Calendar c2) {
    if (inSameYear(c1, c2) && (c1.get(Calendar.WEEK_OF_YEAR) == c2.get(Calendar.WEEK_OF_YEAR)))
        return true;

    Calendar tmp;
    if (c1.before(c2)) {
        tmp = c2;
        c2 = c1;
        c1 = tmp;
    }

    int c1week = c1.get(Calendar.WEEK_OF_YEAR);
    int c2week = c1.get(Calendar.WEEK_OF_YEAR);

    if (c1.get(Calendar.YEAR) == c2.get(Calendar.YEAR) + 1) {
        if (c1week == c1.getActualMinimum(Calendar.WEEK_OF_YEAR)
                && c2week == c2.getActualMaximum(Calendar.WEEK_OF_YEAR)) {
            tmp = (Calendar) c2.clone();
            tmp.add(Calendar.DAY_OF_YEAR, 7);
            if (tmp.get(Calendar.WEEK_OF_YEAR) > c1week)
                return true;
        }
    }

    return false;
}

From source file:DateUtil.java

/**
 * Returns true if the two calendars represent dates that fall in the same
 * day, else false./* www . j a va2s .c  o m*/
 * 
 * @param c1
 *          Calendar one.
 * @param c2
 *          Calendar two.
 * @return boolean.
 */
public static boolean inSameDay(Calendar c1, Calendar c2) {
    if (inSameYear(c1, c2) && (c1.get(Calendar.DAY_OF_YEAR) == c2.get(Calendar.DAY_OF_YEAR)))
        return true;
    return false;
}

From source file:com.bt.heliniumstudentapp.ScheduleFragment.java

private int checkDatabase() {
    Boolean updated = false;/*from  www  .j a v a  2  s.com*/

    final GregorianCalendar currentDate = new GregorianCalendar(HeliniumStudentApp.LOCALE);
    final GregorianCalendar storedDate = new GregorianCalendar(HeliniumStudentApp.LOCALE);

    final String scheduleStart = PreferenceManager.getDefaultSharedPreferences(mainContext)
            .getString("schedule_start_0", null);

    if (scheduleStart == null) {
        return HeliniumStudentApp.DB_OK;
    } else {
        try {
            storedDate.setTime(HeliniumStudentApp.df_date().parse(scheduleStart));
        } catch (ParseException ignored) {
            return HeliniumStudentApp.DB_ERROR;
        }
    }

    for (int weekDays = 0; weekDays < 7; weekDays++) {
        if (currentDate.get(Calendar.YEAR) == storedDate.get(Calendar.YEAR)
                && currentDate.get(Calendar.MONTH) == storedDate.get(Calendar.MONTH)
                && currentDate.get(Calendar.DAY_OF_MONTH) == storedDate.get(Calendar.DAY_OF_MONTH)) {
            updated = true;
            break;
        }

        storedDate.add(Calendar.DAY_OF_YEAR, 1);
    }

    if (updated) {
        return HeliniumStudentApp.DB_OK;
    } else {
        scheduleFocus = currentDate.get(Calendar.WEEK_OF_YEAR);

        if (PreferenceManager.getDefaultSharedPreferences(mainContext).getString("schedule_1", null) == null) {
            if (MainActivity.isOnline()) {
                MainActivity.setStatusBar(mainContext);

                PreferenceManager.getDefaultSharedPreferences(mainContext).edit().putString("schedule_0", null)
                        .apply();
                PreferenceManager.getDefaultSharedPreferences(mainContext).edit().putString("schedule_1", null)
                        .apply();

                PreferenceManager.getDefaultSharedPreferences(mainContext).edit()
                        .putString("schedule_start_0", null).apply();
                PreferenceManager.getDefaultSharedPreferences(mainContext).edit()
                        .putString("schedule_start_1", null).apply();

                ScheduleFragment.getSchedule(HeliniumStudentApp.DIREC_CURRENT,
                        HeliniumStudentApp.ACTION_SHORT_IN);

                return HeliniumStudentApp.DB_REFRESHING; //TODO Handle by caller to avoid workarounds
            } else {
                Toast.makeText(mainContext,
                        mainContext.getString(R.string.error_database) + ". "
                                + mainContext.getString(R.string.error_conn_no) + ".",
                        Toast.LENGTH_SHORT).show();
                mainContext.finish();

                return HeliniumStudentApp.DB_ERROR; //TODO Throw error / in finally
            }
        } else
            try {
                currentDate.setTime(HeliniumStudentApp.df_date().parse(PreferenceManager
                        .getDefaultSharedPreferences(mainContext).getString("schedule_start_0", "1")));

                if (currentDate.get(Calendar.WEEK_OF_YEAR) - currentDate.get(Calendar.WEEK_OF_YEAR) == 1) {
                    PreferenceManager.getDefaultSharedPreferences(mainContext).edit()
                            .putString("schedule_0", PreferenceManager.getDefaultSharedPreferences(mainContext)
                                    .getString("schedule_1", null))
                            .apply();
                    PreferenceManager.getDefaultSharedPreferences(mainContext).edit()
                            .putString("schedule_1", null).apply();

                    PreferenceManager.getDefaultSharedPreferences(mainContext).edit()
                            .putString("pref_schedule_version_0",
                                    PreferenceManager.getDefaultSharedPreferences(mainContext)
                                            .getString("pref_schedule_version_1", null))
                            .apply();
                    PreferenceManager.getDefaultSharedPreferences(mainContext).edit()
                            .putString("pref_schedule_version_1", null).apply();

                    PreferenceManager.getDefaultSharedPreferences(mainContext).edit()
                            .putString("schedule_start_0",
                                    PreferenceManager.getDefaultSharedPreferences(mainContext)
                                            .getString("schedule_start_1", null))
                            .apply();
                    PreferenceManager.getDefaultSharedPreferences(mainContext).edit()
                            .putString("schedule_start_1", null).apply();

                    scheduleJson = PreferenceManager.getDefaultSharedPreferences(mainContext)
                            .getString("schedule_0", null);

                    return HeliniumStudentApp.DB_OK;
                } else {
                    if (MainActivity.isOnline()) {
                        MainActivity.setStatusBar(mainContext);

                        PreferenceManager.getDefaultSharedPreferences(mainContext).edit()
                                .putString("schedule_0", null).apply();
                        PreferenceManager.getDefaultSharedPreferences(mainContext).edit()
                                .putString("schedule_1", null).apply();

                        PreferenceManager.getDefaultSharedPreferences(mainContext).edit()
                                .putString("schedule_start_0", null).apply();
                        PreferenceManager.getDefaultSharedPreferences(mainContext).edit()
                                .putString("schedule_start_1", null).apply();

                        ScheduleFragment.getSchedule(HeliniumStudentApp.DIREC_CURRENT,
                                HeliniumStudentApp.ACTION_SHORT_IN);

                        return HeliniumStudentApp.DB_REFRESHING; //TODO Handle by caller to avoid workarounds
                    } else {
                        Toast.makeText(mainContext,
                                mainContext.getString(R.string.error_database) + ". "
                                        + mainContext.getString(R.string.error_conn_no) + ".",
                                Toast.LENGTH_SHORT).show();
                        mainContext.finish();

                        return HeliniumStudentApp.DB_ERROR; //TODO Throw error / in finally
                    }
                }
            } catch (ParseException ignored) {
            }

        return HeliniumStudentApp.DB_ERROR; //TODO Throw error / in finally
    }
}

From source file:org.sakaiproject.sitestats.impl.chart.ChartServiceImpl.java

private DefaultCategoryDataset getVisitsWeekDataSet(String siteId) {
    //      LOG.info("Generating visitsWeekDataSet");
    SummaryVisitsChartData svc = M_sm.getSummaryVisitsChartData(siteId, StatsManager.VIEW_WEEK);
    if (svc == null)
        return null;
    DefaultCategoryDataset visitsWeekDataSet = new DefaultCategoryDataset();
    String visits = msgs.getString("legend_visits");
    String uniqueVisits = msgs.getString("legend_unique_visitors");

    Calendar cal = Calendar.getInstance();
    cal.setTime(svc.getFirstDay());/*  ww  w. j  av a  2  s  . c  om*/
    Calendar currDay = (Calendar) cal.clone();

    long visitsData[] = svc.getVisits();
    long uniqueVisitsData[] = svc.getUniqueVisits();
    for (int i = 0; i < visitsData.length; i++) {
        visitsWeekDataSet.addValue(visitsData[i], visits,
                getWeekDaysMap().get(currDay.get(Calendar.DAY_OF_WEEK)));
        visitsWeekDataSet.addValue(uniqueVisitsData[i], uniqueVisits,
                getWeekDaysMap().get(currDay.get(Calendar.DAY_OF_WEEK)));
        currDay.add(Calendar.DAY_OF_YEAR, 1);
    }
    return visitsWeekDataSet;
}

From source file:com.alkacon.opencms.calendar.CmsCalendarDisplay.java

/**
 * Returns the next time range to show calendar entries for.<p>
 * Used for the navigation.// w  ww .  ja v a2  s  . co m
 * 
 * @param actual the actual date from which the next time range should be calculated
 * @param type the type of period
 * @return a date for which a list of calendar entries should be shown
 */
public Calendar getNextPeriod(Calendar actual, int type) {

    Calendar cal = (Calendar) actual.clone();
    switch (type) {
    case PERIOD_DAY:
        cal.add(Calendar.DAY_OF_YEAR, 1);
        break;
    case PERIOD_MONTH:
        cal.add(Calendar.MONTH, 1);
        break;
    case PERIOD_WEEK:
        cal.add(Calendar.WEEK_OF_YEAR, 1);
        break;
    case PERIOD_YEAR:
        cal.add(Calendar.YEAR, 1);
        break;
    default:
        break;
    }

    return cal;
}

From source file:arc.noaa.weather.activities.MainActivity.java

public static String formatTimeWithDayIfNotToday(Context context, long timeInMillis) {
    Calendar now = Calendar.getInstance();
    Calendar lastCheckedCal = new GregorianCalendar();
    lastCheckedCal.setTimeInMillis(timeInMillis);
    Date lastCheckedDate = new Date(timeInMillis);
    String timeFormat = android.text.format.DateFormat.getTimeFormat(context).format(lastCheckedDate);
    if (now.get(Calendar.YEAR) == lastCheckedCal.get(Calendar.YEAR)
            && now.get(Calendar.DAY_OF_YEAR) == lastCheckedCal.get(Calendar.DAY_OF_YEAR)) {
        // Same day, only show time
        return timeFormat;
    } else {/*from   w w  w. j  ava 2s  .c om*/
        return android.text.format.DateFormat.getDateFormat(context).format(lastCheckedDate) + " " + timeFormat;
    }
}

From source file:com.alkacon.opencms.calendar.CmsCalendarDisplay.java

/**
 * Returns the previous time range to show calendar entries for.<p>
 * Used for the navigation./*  w ww.  j a  v  a2s  . co  m*/
 * 
 * @param actual the actual date from which the previous time range should be calculated
 * @param type the type of period
 * @return a date for which a list of calendar entries should be shown
 */
public Calendar getPreviousPeriod(Calendar actual, int type) {

    Calendar cal = (Calendar) actual.clone();
    switch (type) {
    case PERIOD_DAY:
        cal.add(Calendar.DAY_OF_YEAR, -1);
        break;
    case PERIOD_MONTH:
        cal.add(Calendar.MONTH, -1);
        break;
    case PERIOD_WEEK:
        cal.add(Calendar.WEEK_OF_YEAR, -1);
        break;
    case PERIOD_YEAR:
        cal.add(Calendar.YEAR, -1);
        break;
    default:
        break;
    }

    return cal;
}

From source file:com.aurel.track.report.dashboard.AverageTimeToCloseItem.java

public static int getCalendarInterval(int timeInterval) {
    switch (timeInterval) {
    case TIME_INTERVAL.DAY:
        return Calendar.DAY_OF_YEAR;
    case TIME_INTERVAL.WEEK:
        return Calendar.WEEK_OF_YEAR;
    default:/*from   w  ww .j  a  v  a  2  s  . c o m*/
        return Calendar.MONTH;
    }
}

From source file:DateFormatUtils.java

/**
 * <p>Returns a list of Rules given a pattern.</p>
 * /* w  ww .  ja  v  a 2s .  c  om*/
 * @return a <code>List</code> of Rule objects
 * @throws IllegalArgumentException if pattern is invalid
 */
protected List parsePattern() {
    DateFormatSymbols symbols = new DateFormatSymbols(mLocale);
    List rules = new ArrayList();

    String[] ERAs = symbols.getEras();
    String[] months = symbols.getMonths();
    String[] shortMonths = symbols.getShortMonths();
    String[] weekdays = symbols.getWeekdays();
    String[] shortWeekdays = symbols.getShortWeekdays();
    String[] AmPmStrings = symbols.getAmPmStrings();

    int length = mPattern.length();
    int[] indexRef = new int[1];

    for (int i = 0; i < length; i++) {
        indexRef[0] = i;
        String token = parseToken(mPattern, indexRef);
        i = indexRef[0];

        int tokenLen = token.length();
        if (tokenLen == 0) {
            break;
        }

        Rule rule;
        char c = token.charAt(0);

        switch (c) {
        case 'G': // era designator (text)
            rule = new TextField(Calendar.ERA, ERAs);
            break;
        case 'y': // year (number)
            if (tokenLen >= 4) {
                rule = selectNumberRule(Calendar.YEAR, tokenLen);
            } else {
                rule = TwoDigitYearField.INSTANCE;
            }
            break;
        case 'M': // month in year (text and number)
            if (tokenLen >= 4) {
                rule = new TextField(Calendar.MONTH, months);
            } else if (tokenLen == 3) {
                rule = new TextField(Calendar.MONTH, shortMonths);
            } else if (tokenLen == 2) {
                rule = TwoDigitMonthField.INSTANCE;
            } else {
                rule = UnpaddedMonthField.INSTANCE;
            }
            break;
        case 'd': // day in month (number)
            rule = selectNumberRule(Calendar.DAY_OF_MONTH, tokenLen);
            break;
        case 'h': // hour in am/pm (number, 1..12)
            rule = new TwelveHourField(selectNumberRule(Calendar.HOUR, tokenLen));
            break;
        case 'H': // hour in day (number, 0..23)
            rule = selectNumberRule(Calendar.HOUR_OF_DAY, tokenLen);
            break;
        case 'm': // minute in hour (number)
            rule = selectNumberRule(Calendar.MINUTE, tokenLen);
            break;
        case 's': // second in minute (number)
            rule = selectNumberRule(Calendar.SECOND, tokenLen);
            break;
        case 'S': // millisecond (number)
            rule = selectNumberRule(Calendar.MILLISECOND, tokenLen);
            break;
        case 'E': // day in week (text)
            rule = new TextField(Calendar.DAY_OF_WEEK, tokenLen < 4 ? shortWeekdays : weekdays);
            break;
        case 'D': // day in year (number)
            rule = selectNumberRule(Calendar.DAY_OF_YEAR, tokenLen);
            break;
        case 'F': // day of week in month (number)
            rule = selectNumberRule(Calendar.DAY_OF_WEEK_IN_MONTH, tokenLen);
            break;
        case 'w': // week in year (number)
            rule = selectNumberRule(Calendar.WEEK_OF_YEAR, tokenLen);
            break;
        case 'W': // week in month (number)
            rule = selectNumberRule(Calendar.WEEK_OF_MONTH, tokenLen);
            break;
        case 'a': // am/pm marker (text)
            rule = new TextField(Calendar.AM_PM, AmPmStrings);
            break;
        case 'k': // hour in day (1..24)
            rule = new TwentyFourHourField(selectNumberRule(Calendar.HOUR_OF_DAY, tokenLen));
            break;
        case 'K': // hour in am/pm (0..11)
            rule = selectNumberRule(Calendar.HOUR, tokenLen);
            break;
        case 'z': // time zone (text)
            if (tokenLen >= 4) {
                rule = new TimeZoneNameRule(mTimeZone, mTimeZoneForced, mLocale, TimeZone.LONG);
            } else {
                rule = new TimeZoneNameRule(mTimeZone, mTimeZoneForced, mLocale, TimeZone.SHORT);
            }
            break;
        case 'Z': // time zone (value)
            if (tokenLen == 1) {
                rule = TimeZoneNumberRule.INSTANCE_NO_COLON;
            } else {
                rule = TimeZoneNumberRule.INSTANCE_COLON;
            }
            break;
        case '\'': // literal text
            String sub = token.substring(1);
            if (sub.length() == 1) {
                rule = new CharacterLiteral(sub.charAt(0));
            } else {
                rule = new StringLiteral(sub);
            }
            break;
        default:
            throw new IllegalArgumentException("Illegal pattern component: " + token);
        }

        rules.add(rule);
    }

    return rules;
}

From source file:br.com.atmatech.sac.view.ViewListaAtendimento.java

private void formComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentShown
    // TODO add your handling code here:
    if (this.inicializatela) {
        this.jTatendimento.requestFocusInWindow();
        Timestamp dtini = new Timestamp(new Date().getTime());
        Date dtin = new Date();
        Calendar c = Calendar.getInstance();
        c.add(Calendar.DAY_OF_YEAR, -30);
        jDinicial.setDate(c.getTime());/*w w w .  ja v  a2 s . co m*/
        jDfinal.setDate(new Timestamp(new Date().getTime()));

        if (new UsuarioLogadoBeans().getTecnico()) {
            if (new UsuarioLogadoBeans().getTecnico()) {
                jCtecnico.doClick();
            } else {
                // jCtecnico.setSelected(new UsuarioLogadoBeans().getTecnico());
                desativaPpesquisa();
            }
        } else if (this.buscaatendimento) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    buscaAtendimento(getTipoSelected(), "'ABERTO','INICIADO','PENDENTE'",
                            new UsuarioLogadoBeans().getIdusuario(), jDinicial.getDate(), jDfinal.getDate(),
                            "dtabertura");
                }
            }).start();

        }

        trocaCor();
        this.inicializatela = false;
    }
}