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:es.ficonlan.web.backend.test.eventservice.EventServiceTest.java

@Test
public void testAddParticipantToActivity() throws ServiceException {
    Session anonymousSession = userService.newAnonymousSession();
    Session s = userService.login(anonymousSession.getSessionId(), ADMIN_LOGIN, ADMIN_PASS);
    User user = userService.addUser(anonymousSession.getSessionId(),
            new User("User1", "login1", "pass", "12345678R", "user1@gmail.com", "690047407", "L"));
    Calendar dateStart = Calendar.getInstance();
    dateStart.add(Calendar.DAY_OF_YEAR, -1);
    Calendar dateEnd = Calendar.getInstance();
    dateEnd.add(Calendar.DAY_OF_YEAR, 1);

    Event event = eventService.createEvent(s.getSessionId(), new Event(0, "FicOnLan 2014", "FicOnLan 2014", 150,
            dateStart, dateEnd, dateStart, dateEnd, null, null, null, null, null));
    eventService.addParticipantToEvent(s.getSessionId(), user.getUserId(), event.getEventId());
    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.addParticipantToActivity(s.getSessionId(), user.getUserId(), activity.getActivityId());
    assertTrue(activity.getParticipants().contains(user));
}

From source file:com.metasoft.claim.service.impl.claim.ClaimServiceImpl.java

@Override
public List<ClaimSearchResultVo> searchExport(String paramJobDateStart, String paramJobDateEnd,
        String paramPartyInsuranceId, String paramTotalDayOfMaturity, String paramClaimTypeId,
        String paramClaimNumber, String paramJobStatusId) {
    Date jobDateStart = null;/*from w w  w.j a va  2 s  .c  om*/
    Date jobDateEnd = null;
    StdInsurance partyInsurance = null;
    Date maturityDate = null;
    ClaimType claimType = null;
    JobStatus jobStatus = null;
    if (StringUtils.isNotBlank(paramJobDateStart)) {
        jobDateStart = DateToolsUtil.convertStringToDate(paramJobDateStart, DateToolsUtil.LOCALE_TH);
    }

    if (StringUtils.isNotBlank(paramJobDateEnd)) {
        jobDateEnd = DateToolsUtil.convertStringToDate(paramJobDateEnd, DateToolsUtil.LOCALE_TH);
    }

    if (StringUtils.isNotBlank(paramPartyInsuranceId)) {
        partyInsurance = insuranceService.findById(Integer.parseInt(paramPartyInsuranceId));
    }

    if (StringUtils.isNotBlank(paramTotalDayOfMaturity)) {
        int totalDayOfMaturity = NumberToolsUtil.parseToInteger(paramTotalDayOfMaturity);
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DAY_OF_YEAR, +totalDayOfMaturity);
        maturityDate = cal.getTime();
    }

    if (StringUtils.isNotBlank(paramClaimTypeId)) {
        claimType = ClaimType.getById(Integer.parseInt(paramClaimTypeId));
    }

    if (StringUtils.isNotBlank(paramJobStatusId)) {
        jobStatus = JobStatus.getById(Integer.parseInt(paramJobStatusId));
    }

    return searchExport(jobDateStart, jobDateEnd, partyInsurance, maturityDate, claimType, paramClaimNumber,
            jobStatus);
}

From source file:com.aurel.track.linkType.MsProjectLinkTypeBL.java

/**
 * This method subtracts steps from dateParam and returns. If withCheckingFreeDays == true
 * then weekends, and free days doesn't treats as work day.
 * @param dateParam/*from  w w w. j av a2s .c o  m*/
 * @param steps
 * @param withCheckingFreeDays
 * @return
 */
public static Date stepBack(Date dateParam, int steps, boolean withCheckingFreeDays) {
    if (dateParam == null) {
        return null;
    }
    int actualSteps = 0;
    Calendar cal = Calendar.getInstance();
    cal.setTime(dateParam);
    Date newDate = new Date();
    while (actualSteps < steps) {
        cal.add(Calendar.DAY_OF_YEAR, -1);
        newDate = cal.getTime();
        if (withCheckingFreeDays) {
            if (!WorkDaysConfigImplementation.isSaturday(newDate)
                    && !WorkDaysConfigImplementation.isSunday(newDate)
                    && !WorkDaysConfigImplementation.isFreeDay(newDate)) {
                actualSteps++;
            }
        } else {
            actualSteps++;
        }
    }
    return newDate;
}

From source file:org.onebusaway.nyc.vehicle_tracking.webapp.controllers.VehicleLocationSimulationController.java

private Date getTime(HttpSession session, Date time) {

    if (time == null)
        time = new Date();

    String calendarOffset = (String) session.getAttribute(CALENDAR_OFFSET_KEY);

    if (calendarOffset != null) {

        Matcher m = CALENDAR_OFFSET_PATTERN.matcher(calendarOffset);
        if (m.matches()) {

            int amount = Integer.parseInt(m.group(1));
            String type = m.group(2);

            Calendar c = Calendar.getInstance();
            c.setTime(time);//  www.j a v a 2s.  c  o  m

            if (type.equals("M"))
                c.add(Calendar.MONTH, amount);
            else if (type.equals("w"))
                c.add(Calendar.WEEK_OF_YEAR, amount);
            else if (type.equals("d"))
                c.add(Calendar.DAY_OF_YEAR, amount);
            else if (type.equals("h"))
                c.add(Calendar.HOUR, amount);
            time = c.getTime();
        }
    }

    return time;
}

From source file:com.cloud.server.StatsCollector.java

private void init(Map<String, String> configs) {
    _executor = Executors.newScheduledThreadPool(6, new NamedThreadFactory("StatsCollector"));

    hostOutOfBandManagementStatsInterval = OutOfBandManagementService.SyncThreadInterval.value();
    hostStatsInterval = NumbersUtil.parseLong(configs.get("host.stats.interval"), 60000L);
    hostAndVmStatsInterval = NumbersUtil.parseLong(configs.get("vm.stats.interval"), 60000L);
    storageStatsInterval = NumbersUtil.parseLong(configs.get("storage.stats.interval"), 60000L);
    volumeStatsInterval = NumbersUtil.parseLong(configs.get("volume.stats.interval"), -1L);
    autoScaleStatsInterval = NumbersUtil.parseLong(configs.get("autoscale.stats.interval"), 60000L);
    vmDiskStatsInterval = NumbersUtil.parseInt(configs.get("vm.disk.stats.interval"), 0);

    /* URI to send statistics to. Currently only Graphite is supported */
    String externalStatsUri = configs.get("stats.output.uri");
    if (externalStatsUri != null && !externalStatsUri.equals("")) {
        try {// ww  w  .  j a  va  2s  . c o m
            URI uri = new URI(externalStatsUri);
            String scheme = uri.getScheme();

            try {
                externalStatsType = ExternalStatsProtocol.valueOf(scheme.toUpperCase());
            } catch (IllegalArgumentException e) {
                s_logger.info(scheme
                        + " is not a valid protocol for external statistics. No statistics will be send.");
            }

            if (!StringUtils.isEmpty(uri.getHost())) {
                externalStatsHost = uri.getHost();
            }

            externalStatsPort = uri.getPort();

            if (!StringUtils.isEmpty(uri.getPath())) {
                externalStatsPrefix = uri.getPath().substring(1);
            }

            /* Append a dot (.) to the prefix if it is set */
            if (!StringUtils.isEmpty(externalStatsPrefix)) {
                externalStatsPrefix += ".";
            } else {
                externalStatsPrefix = "";
            }

            externalStatsEnabled = true;
        } catch (URISyntaxException e) {
            s_logger.debug("Failed to parse external statistics URI: " + e.getMessage());
        }
    }

    if (hostStatsInterval > 0) {
        _executor.scheduleWithFixedDelay(new HostCollector(), 15000L, hostStatsInterval, TimeUnit.MILLISECONDS);
    }

    if (hostOutOfBandManagementStatsInterval > 0) {
        _executor.scheduleWithFixedDelay(new HostOutOfBandManagementStatsCollector(), 15000L,
                hostOutOfBandManagementStatsInterval, TimeUnit.MILLISECONDS);
    }

    if (hostAndVmStatsInterval > 0) {
        _executor.scheduleWithFixedDelay(new VmStatsCollector(), 15000L, hostAndVmStatsInterval,
                TimeUnit.MILLISECONDS);
    }

    if (storageStatsInterval > 0) {
        _executor.scheduleWithFixedDelay(new StorageCollector(), 15000L, storageStatsInterval,
                TimeUnit.MILLISECONDS);
    }

    if (autoScaleStatsInterval > 0) {
        _executor.scheduleWithFixedDelay(new AutoScaleMonitor(), 15000L, autoScaleStatsInterval,
                TimeUnit.MILLISECONDS);
    }

    if (vmDiskStatsInterval > 0) {
        if (vmDiskStatsInterval < 300)
            vmDiskStatsInterval = 300;
        _executor.scheduleAtFixedRate(new VmDiskStatsTask(), vmDiskStatsInterval, vmDiskStatsInterval,
                TimeUnit.SECONDS);
    }

    //Schedule disk stats update task
    _diskStatsUpdateExecutor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("DiskStatsUpdater"));
    String aggregationRange = configs.get("usage.stats.job.aggregation.range");
    _usageAggregationRange = NumbersUtil.parseInt(aggregationRange, 1440);
    _usageTimeZone = configs.get("usage.aggregation.timezone");
    if (_usageTimeZone == null) {
        _usageTimeZone = "GMT";
    }
    TimeZone usageTimezone = TimeZone.getTimeZone(_usageTimeZone);
    Calendar cal = Calendar.getInstance(usageTimezone);
    cal.setTime(new Date());
    long endDate = 0;
    int HOURLY_TIME = 60;
    final int DAILY_TIME = 60 * 24;
    if (_usageAggregationRange == DAILY_TIME) {
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        cal.roll(Calendar.DAY_OF_YEAR, true);
        cal.add(Calendar.MILLISECOND, -1);
        endDate = cal.getTime().getTime();
        _dailyOrHourly = true;
    } else if (_usageAggregationRange == HOURLY_TIME) {
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        cal.roll(Calendar.HOUR_OF_DAY, true);
        cal.add(Calendar.MILLISECOND, -1);
        endDate = cal.getTime().getTime();
        _dailyOrHourly = true;
    } else {
        endDate = cal.getTime().getTime();
        _dailyOrHourly = false;
    }
    if (_usageAggregationRange < UsageUtils.USAGE_AGGREGATION_RANGE_MIN) {
        s_logger.warn("Usage stats job aggregation range is to small, using the minimum value of "
                + UsageUtils.USAGE_AGGREGATION_RANGE_MIN);
        _usageAggregationRange = UsageUtils.USAGE_AGGREGATION_RANGE_MIN;
    }
    _diskStatsUpdateExecutor.scheduleAtFixedRate(new VmDiskStatsUpdaterTask(),
            (endDate - System.currentTimeMillis()), (_usageAggregationRange * 60 * 1000),
            TimeUnit.MILLISECONDS);

}

From source file:Time.java

/**
 * Return the day number of year this day represents. January 1 = 1 and so on.
 * //w  w w.  j  a  va  2s .  c  o m
 * @return day number of year.
 */
public int getDayOfYear() {
    return calendar_.get(Calendar.DAY_OF_YEAR);
}

From source file:org.hellojavaer.testcase.generator.TestCaseGenerator.java

@SuppressWarnings({ "unchecked", "rawtypes" })
private static <T> T produceBean(Class<T> clazz, ControlParam countrolParam, Stack<Class> parseClassList) {
    try {/*from ww  w .ja v a 2s.c o  m*/
        T item = clazz.newInstance();
        for (PropertyDescriptor pd : BeanUtils.getPropertyDescriptors(clazz)) {
            Method writeMethod = pd.getWriteMethod();
            if (writeMethod == null || pd.getReadMethod() == null || //
                    countrolParam.getExcludeFieldList() != null
                            && countrolParam.getExcludeFieldList().contains(pd.getName())//
            ) {//
                continue;
            }
            Class fieldClazz = pd.getPropertyType();
            Long numIndex = countrolParam.getNumIndex();
            // int enumIndex = countrolParam.getEnumIndex();
            Random random = countrolParam.getRandom();
            long strIndex = countrolParam.getStrIndex();
            int charIndex = countrolParam.getCharIndex();
            Calendar time = countrolParam.getTime();
            if (TypeUtil.isBaseType(fieldClazz)) {
                if (TypeUtil.isNumberType(fieldClazz)) {
                    if (fieldClazz == Byte.class) {
                        writeMethod.invoke(item, Byte.valueOf((byte) (numIndex & 0x7F)));
                    } else if (fieldClazz == Short.class) {
                        writeMethod.invoke(item, Short.valueOf((short) (numIndex & 0x7FFF)));
                    } else if (fieldClazz == Integer.class) {
                        writeMethod.invoke(item, Integer.valueOf((int) (numIndex & 0x7FFFFFFF)));
                    } else if (fieldClazz == Long.class) {
                        writeMethod.invoke(item, Long.valueOf((long) numIndex));
                    } else if (fieldClazz == Float.class) {
                        writeMethod.invoke(item, Float.valueOf((float) numIndex));
                    } else if (fieldClazz == Double.class) {
                        writeMethod.invoke(item, Double.valueOf((double) numIndex));
                    } else if (fieldClazz == byte.class) {//
                        writeMethod.invoke(item, (byte) (numIndex & 0x7F));
                    } else if (fieldClazz == short.class) {
                        writeMethod.invoke(item, (short) (numIndex & 0x7FFF));
                    } else if (fieldClazz == int.class) {
                        writeMethod.invoke(item, (int) (numIndex & 0x7FFFFFFF));
                    } else if (fieldClazz == long.class) {
                        writeMethod.invoke(item, (long) numIndex);
                    } else if (fieldClazz == float.class) {
                        writeMethod.invoke(item, (float) numIndex);
                    } else if (fieldClazz == double.class) {
                        writeMethod.invoke(item, (double) numIndex);
                    }
                    numIndex++;
                    if (numIndex < 0) {
                        numIndex &= 0x7FFFFFFFFFFFFFFFL;
                    }
                    countrolParam.setNumIndex(numIndex);
                } else if (fieldClazz == boolean.class) {
                    writeMethod.invoke(item, random.nextBoolean());
                } else if (fieldClazz == Boolean.class) {
                    writeMethod.invoke(item, Boolean.valueOf(random.nextBoolean()));
                } else if (fieldClazz == char.class) {
                    writeMethod.invoke(item, CHAR_RANGE[charIndex]);
                    charIndex++;
                    if (charIndex >= CHAR_RANGE.length) {
                        charIndex = 0;
                    }
                    countrolParam.setCharIndex(charIndex);
                } else if (fieldClazz == Character.class) {
                    writeMethod.invoke(item, Character.valueOf(CHAR_RANGE[charIndex]));
                    charIndex++;
                    if (charIndex >= CHAR_RANGE.length) {
                        charIndex = 0;
                    }
                    countrolParam.setCharIndex(charIndex);
                } else if (fieldClazz == String.class) {
                    if (countrolParam.getUniqueFieldList() != null
                            && countrolParam.getUniqueFieldList().contains(pd.getName())) {
                        StringBuilder sb = new StringBuilder();
                        convertNum(strIndex, STRING_RANGE, countrolParam.getRandom(), sb);
                        writeMethod.invoke(item, sb.toString());
                        strIndex += countrolParam.getStrStep();
                        if (strIndex < 0) {
                            strIndex &= 0x7FFFFFFFFFFFFFFFL;
                        }
                        countrolParam.setStrIndex(strIndex);
                    } else {
                        writeMethod.invoke(item, String.valueOf(CHAR_RANGE[charIndex]));
                        charIndex++;
                        if (charIndex >= CHAR_RANGE.length) {
                            charIndex = 0;
                        }
                        countrolParam.setCharIndex(charIndex);
                    }

                } else if (fieldClazz == Date.class) {
                    writeMethod.invoke(item, time.getTime());
                    time.add(Calendar.DAY_OF_YEAR, 1);
                } else if (fieldClazz.isEnum()) {
                    int index = random.nextInt(fieldClazz.getEnumConstants().length);
                    writeMethod.invoke(item, fieldClazz.getEnumConstants()[index]);
                } else {
                    //
                    throw new RuntimeException("out of countrol Class " + fieldClazz.getName());
                }
            } else {
                parseClassList.push(fieldClazz);
                // TODO ?
                Set<Class> set = new HashSet<Class>(parseClassList);
                if (parseClassList.size() - set.size() <= countrolParam.getRecursiveCycleLimit()) {
                    Object bean = produceBean(fieldClazz, countrolParam, parseClassList);
                    writeMethod.invoke(item, bean);
                }
                parseClassList.pop();
            }
        }
        return item;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:jp.co.ctc_g.jfw.core.util.Dates.java

/**
 * ??????????.//ww w .j av  a  2  s.  c  om
 * @return ????????
 */
public static int getDayOfYear() {

    Calendar currentCalendar = Dates.getCalendarInstance();
    return currentCalendar.get(Calendar.DAY_OF_YEAR);
}

From source file:com.joinsystem.goku.common.utils.DateUtil.java

/**
 * //from  w  ww  .  j av  a  2  s .c o m
 * 
 * @param d1
 * @param d2
 * @return
 */
public static int diffDays(Calendar d1, Calendar d2) {
    if (d1.after(d2)) {
        java.util.Calendar swap = d1;
        d1 = d2;
        d2 = swap;
    }
    int days = d2.get(Calendar.DAY_OF_YEAR) - d1.get(Calendar.DAY_OF_YEAR);
    int y2 = d2.get(Calendar.YEAR);
    if (d1.get(Calendar.YEAR) != y2) {
        d1 = (Calendar) d1.clone();
        do {
            days += d1.getActualMaximum(Calendar.DAY_OF_YEAR);// 
            d1.add(Calendar.YEAR, 1);
        } while (d1.get(Calendar.YEAR) != y2);
    }
    return days;
}

From source file:com.px100systems.util.SpringELCtx.java

/**
 * Period start//from w  w  w.  j  a v  a2s .c o m
 * @param date time
 * @param arg d/w/M/y
 * @return adjusted time
 */
public static Date periodStart(Date date, String arg) {
    if (date == null)
        return null;

    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);

    if (arg.endsWith("d"))
        return cal.getTime();
    else if (arg.endsWith("M")) {
        cal.set(Calendar.DAY_OF_MONTH, 1);
        return cal.getTime();
    } else if (arg.endsWith("y")) {
        cal.set(Calendar.DAY_OF_YEAR, 1);
        return cal.getTime();
    } else if (arg.endsWith("w")) {
        cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek());
        return cal.getTime();
    }

    return date;
}