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:msec.org.Tools.java

static public String getPreviousDate(String date, int beforeday) {
    if (beforeday == 0)
        return date;
    int d = Integer.parseInt(date);
    Calendar cal = Calendar.getInstance();
    cal.set(d / 10000, d % 10000 / 100 - 1, d % 100);
    cal.add(Calendar.DAY_OF_YEAR, beforeday * -1);
    SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
    return format.format(cal.getTime());
}

From source file:com.google.gwt.benchmark.dashboard.server.controller.BenchmarkController.java

private WeekSpan createWeekSpan(long commitTimeMsEpoch) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(new Date(commitTimeMsEpoch));
    int week = cal.get(Calendar.WEEK_OF_YEAR);
    int year = cal.get(Calendar.YEAR);

    Calendar calendar = Calendar.getInstance();
    calendar.clear();/*from w w  w  .jav a2  s  . co  m*/
    calendar.set(Calendar.WEEK_OF_YEAR, week);
    calendar.set(Calendar.YEAR, year);
    long startSearch = calendar.getTimeInMillis();

    calendar.add(Calendar.DAY_OF_YEAR, 7);
    long endSearch = calendar.getTimeInMillis();

    return new WeekSpan(week, year, startSearch, endSearch);
}

From source file:org.adempiere.apps.graph.ChartBuilder.java

private Date increment(Date lastDate, String timeUnit, int qty) {

    if (lastDate == null)
        return null;

    Calendar cal = Calendar.getInstance();
    cal.setTime(lastDate);/*from   w  w  w.  j  a  va 2s  .  c  om*/

    if (timeUnit.equals(MChart.TIMEUNIT_Day))
        cal.add(Calendar.DAY_OF_YEAR, qty);
    else if (timeUnit.equals(MChart.TIMEUNIT_Week))
        cal.add(Calendar.WEEK_OF_YEAR, qty);
    else if (timeUnit.equals(MChart.TIMEUNIT_Month))
        cal.add(Calendar.MONTH, qty);
    else if (timeUnit.equals(MChart.TIMEUNIT_Quarter))
        cal.add(Calendar.MONTH, 3 * qty);
    else if (timeUnit.equals(MChart.TIMEUNIT_Year))
        cal.add(Calendar.YEAR, qty);

    return cal.getTime();
}

From source file:cn.mljia.common.notify.utils.DateUtils.java

public static Date addYear(Date date, int year) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);/*from  w  ww.  j  a va  2s. c  om*/
    calendar.add(Calendar.DAY_OF_YEAR, 365 * year);
    return calendar.getTime();
}

From source file:com.aoyun.serviceOld.GetValForYKPOne.java

/**
 * @param dateStr/*  www  .j a va 2 s .c o  m*/
 * @return
 * @throws ParseException
 */
public boolean isTrue(String dateStr) throws ParseException {
    Calendar now = Calendar.getInstance();
    now.add(Calendar.DAY_OF_YEAR, -Constantz.beforeDate);
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
    String mDateTime = formatter.format(now.getTime());
    Date old = formatter.parse(dateStr);
    Date before = formatter.parse(mDateTime);
    if (old.compareTo(before) >= 0) {
        return true;
    }
    return false;
}

From source file:com.gumtreescraper.scraper.GumtreeScraper.java

private boolean needToScrapeNextPage(String dateStr) {
    Date today = new Date();
    if (DateUtils.isSameDay(today, lastEditedDate)) { // check why lastEditedDate is null
        if (dateStr.toLowerCase().contains("minutes") || dateStr.toLowerCase().contains("hours")) {
            return true;
        }/*from   w  w  w.j a  v  a 2  s.  c  o  m*/

        if (dateStr.toLowerCase().contains("yesterday")) {
            return false;
        }
    }

    Calendar cal = Calendar.getInstance();
    cal.setTime(today);
    cal.add(Calendar.DAY_OF_YEAR, -1);
    Date yesterday = cal.getTime();

    if (DateUtils.isSameDay(yesterday, lastEditedDate)) {
        if (dateStr.toLowerCase().contains("yesterday")) {
            return true;
        }
    }

    Date d = GumtreeUtils.convertStringToDate(dateStr);
    if (d == null) {
        return false;
    }

    return DateUtils.isSameDay(d, lastEditedDate);

    //        return true;
}

From source file:py.una.pol.karaku.test.test.DateUtilsTest.java

@Test
public void testGetEdad() {

    assertEquals(DateUtils.getEdad(new Date()), "1 da");
    assertEquals(DateUtils.getEdad(null), null);
    // prueba con aos
    Calendar dateClear = Calendar.getInstance();
    Calendar c1 = Calendar.getInstance();
    dateClear.set(Calendar.DAY_OF_YEAR, 1);
    dateClear.set(Calendar.MONTH, 1);
    dateClear.set(Calendar.YEAR, 1);
    assertEquals(DateUtils.getEdad(dateClear.getTime()),
            DateUtils.calculateYearsFromNow(dateClear.getTime()) + " aos");
    // prueba con ao
    dateClear = Calendar.getInstance();
    dateClear.set(Calendar.DAY_OF_YEAR, c1.get(Calendar.DAY_OF_YEAR));
    dateClear.set(Calendar.MONTH, c1.get(Calendar.MONTH));
    dateClear.set(Calendar.YEAR, c1.get(Calendar.YEAR) - 1);
    assertEquals(DateUtils.getEdad(dateClear.getTime()), "1 ao");

    // prueba con mes
    dateClear.set(Calendar.DAY_OF_MONTH, c1.get(Calendar.DAY_OF_MONTH));
    if (c1.get(Calendar.MONTH) == 0) {
        dateClear.set(Calendar.MONTH, 11);
    } else {/*  w ww. j  av a2s  .c  o  m*/
        dateClear.set(Calendar.MONTH, c1.get(Calendar.MONTH) - 1);
    }

    dateClear.set(Calendar.YEAR, c1.get(Calendar.YEAR));
    assertEquals(DateUtils.getEdad(dateClear.getTime()), "1 mes");

}

From source file:models.Schedule.java

private boolean areAllSetRangesUnitsEqual(final Calendar lastRunCalendar, final Calendar calendar,
        final List<Integer> nonDefaultUnits) {
    boolean eq = true;

    for (int unitType : nonDefaultUnits) {
        switch (unitType) {
        case Calendar.MINUTE:
            eq = (lastRunCalendar.get(Calendar.MINUTE) == calendar.get(Calendar.MINUTE)
                    && lastRunCalendar.get(Calendar.HOUR_OF_DAY) == calendar.get(Calendar.HOUR_OF_DAY)
                    && lastRunCalendar.get(Calendar.DAY_OF_YEAR) == calendar.get(Calendar.DAY_OF_YEAR)
                    && lastRunCalendar.get(Calendar.YEAR) == calendar.get(Calendar.YEAR));
            break;
        case Calendar.HOUR_OF_DAY:
            eq = (lastRunCalendar.get(Calendar.HOUR_OF_DAY) == calendar.get(Calendar.HOUR_OF_DAY)
                    && lastRunCalendar.get(Calendar.DAY_OF_YEAR) == calendar.get(Calendar.DAY_OF_YEAR)
                    && lastRunCalendar.get(Calendar.YEAR) == calendar.get(Calendar.YEAR));
            break;
        case Calendar.DAY_OF_MONTH:
            eq = (lastRunCalendar.get(Calendar.DAY_OF_MONTH) == calendar.get(Calendar.DAY_OF_MONTH)
                    && lastRunCalendar.get(Calendar.DAY_OF_YEAR) == calendar.get(Calendar.DAY_OF_YEAR)
                    && lastRunCalendar.get(Calendar.YEAR) == calendar.get(Calendar.YEAR));
            break;
        case Calendar.DAY_OF_WEEK:
            eq = (lastRunCalendar.get(Calendar.DAY_OF_WEEK) == calendar.get(Calendar.DAY_OF_WEEK)
                    && lastRunCalendar.get(Calendar.DAY_OF_YEAR) == calendar.get(Calendar.DAY_OF_YEAR)
                    && lastRunCalendar.get(Calendar.YEAR) == calendar.get(Calendar.YEAR));
            break;
        case Calendar.YEAR:
            eq = lastRunCalendar.get(Calendar.YEAR) == calendar.get(Calendar.YEAR);
            break;
        }//from   ww  w  . java2s .c o  m

        if (!eq) {
            // any one unit check is different, so not all equal
            return eq;
        }
    }

    return eq; // they were _all_ equal
}

From source file:com.li.bus.utils.DateUtils.java

/**
 * ???// w  w w. j  a v a2 s.c o  m
 * @param date_begin
 * @param date_end
 * @return
 */
public static List<Date> getDates(Calendar date_begin, Calendar date_end) {
    List<Date> result = new ArrayList<Date>();
    Calendar temp = date_begin;
    while (temp.before(date_end)) {
        result.add(temp.getTime());
        temp.add(Calendar.DAY_OF_YEAR, 1);
    }
    return result;
}

From source file:es.ficonlan.web.backend.test.eventservice.EventServiceTest.java

@Test
public void testRemoveActivity() throws ServiceException {
    Session anonymousSession = userService.newAnonymousSession();
    Session s = userService.login(anonymousSession.getSessionId(), ADMIN_LOGIN, ADMIN_PASS);
    Calendar dateStart = Calendar.getInstance();
    Calendar dateEnd = Calendar.getInstance();
    dateEnd.add(Calendar.DAY_OF_YEAR, 1);
    Event event = new Event(0, "FicOnLan 2014", "FicOnLan 2014", 150, dateStart, dateEnd, dateStart, dateEnd,
            null, null, null, null, null);
    eventDao.save(event);/*from  w ww . j  av a 2 s  . c  om*/
    Activity activity = eventService.addActivity(s.getSessionId(), event.getEventId(),
            new Activity(event, "Torneo de Lol", "Torneo de Lol", 10, ActivityType.Tournament, true, dateStart,
                    dateEnd, dateStart, dateEnd));
    eventService.removeActivity(s.getSessionId(), activity.getActivityId());
    try {
        activityDao.find(activity.getActivityId());
        fail("This should have thrown an exception");
    } catch (InstanceException e) {
    }
}