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:com.redhat.rhtracking.persistance.services.OpportunityPersistanceServiceHandler.java

@Override
public Map<String, Object> listAllOpportunities(Map<String, Object> event) {
    final boolean toExpire = event.containsKey("toExpire");

    return findList(new IterableQuery() {

        @Override/*from w  w w .  j  av  a 2  s.c  o m*/
        public Iterable<Opportunity> query() {
            if (toExpire) {
                TRConfig key = configRepository.findOne("opportunity.alert.endTime");
                int time = Integer.parseInt(key.getValue());
                Calendar c = Calendar.getInstance();
                c.setTime(new Date());
                c.add(Calendar.DAY_OF_YEAR, time);
                logger.debug("finding oppo who expire before " + c.getTime());
                return opportunityRepository.findAllByAboutToExpire(c.getTime());
            } else {
                return opportunityRepository.findAll();
            }
        }
    });
}

From source file:com.feilong.core.date.DateExtensionUtilTemp.java

/**
 *   <code>week</code> ?.//from   www. ja  v  a 2 s  .  co m
 * 
 * <h3>:</h3>
 * <blockquote>
 * 
 * <p>
 * ? 2016 ,
 * </p>
 * 
 * <pre class="code">
 * getWeekDateStringList(Calendar.THURSDAY, COMMON_DATE_AND_TIME_WITH_MILLISECOND)
 * </pre>
 * 
 * <b>:</b>
 * 
 * <pre class="code">
 * [
 * "2016-01-07 00:00:00.000",
 * "2016-01-14 00:00:00.000",
 * "2016-01-21 00:00:00.000",
 * "2016-01-28 00:00:00.000",
 * "2016-02-04 00:00:00.000",
 * "2016-02-11 00:00:00.000",
 * "2016-02-18 00:00:00.000",
 * "2016-02-25 00:00:00.000",
 * "2016-03-03 00:00:00.000",
 * "2016-03-10 00:00:00.000",
 * "2016-03-17 00:00:00.000",
 * "2016-03-24 00:00:00.000",
 * "2016-03-31 00:00:00.000",
 * "2016-04-07 00:00:00.000",
 * "2016-04-14 00:00:00.000",
 * "2016-04-21 00:00:00.000",
 * "2016-04-28 00:00:00.000",
 * "2016-05-05 00:00:00.000",
 * "2016-05-12 00:00:00.000",
 * "2016-05-19 00:00:00.000",
 * "2016-05-26 00:00:00.000",
 * "2016-06-02 00:00:00.000",
 * "2016-06-09 00:00:00.000",
 * "2016-06-16 00:00:00.000",
 * "2016-06-23 00:00:00.000",
 * "2016-06-30 00:00:00.000",
 * "2016-07-07 00:00:00.000",
 * "2016-07-14 00:00:00.000",
 * "2016-07-21 00:00:00.000",
 * "2016-07-28 00:00:00.000",
 * "2016-08-04 00:00:00.000",
 * "2016-08-11 00:00:00.000",
 * "2016-08-18 00:00:00.000",
 * "2016-08-25 00:00:00.000",
 * "2016-09-01 00:00:00.000",
 * "2016-09-08 00:00:00.000",
 * "2016-09-15 00:00:00.000",
 * "2016-09-22 00:00:00.000",
 * "2016-09-29 00:00:00.000",
 * "2016-10-06 00:00:00.000",
 * "2016-10-13 00:00:00.000",
 * "2016-10-20 00:00:00.000",
 * "2016-10-27 00:00:00.000",
 * "2016-11-03 00:00:00.000",
 * "2016-11-10 00:00:00.000",
 * "2016-11-17 00:00:00.000",
 * "2016-11-24 00:00:00.000",
 * "2016-12-01 00:00:00.000",
 * "2016-12-08 00:00:00.000",
 * "2016-12-15 00:00:00.000",
 * "2016-12-22 00:00:00.000",
 * "2016-12-29 00:00:00.000"
 * ]
 * </pre>
 * 
 * </blockquote>
 * 
 * @param week
 *            <br>
 *            1 ?2 3 4 5 6 7,<br>
 *             ? {@link Calendar#SUNDAY}, {@link Calendar#MONDAY}, {@link Calendar#TUESDAY},
 *            {@link Calendar#WEDNESDAY}, {@link Calendar#THURSDAY}, {@link Calendar#FRIDAY}, {@link Calendar#SATURDAY}
 * @param datePattern
 *            ??? see {@link DatePattern}
 * @return ?<br>
 *          <code>datePattern</code> null, {@link NullPointerException}<br>
 *          <code>datePattern</code> blank, {@link IllegalArgumentException}
 * @see org.apache.commons.lang3.time.DateUtils#iterator(Date, int)
 * @see Calendar#SUNDAY
 * @see Calendar#MONDAY
 * @see Calendar#TUESDAY
 * @see Calendar#WEDNESDAY
 * @see Calendar#THURSDAY
 * @see Calendar#FRIDAY
 * @see Calendar#SATURDAY
 */
public static List<String> getWeekDateStringList(int week, String datePattern) {
    Validate.notBlank(datePattern, "datePattern can't be blank!");
    Date now = new Date();
    Date firstWeekOfSpecifyDateYear = DateUtil.getFirstWeekOfSpecifyDateYear(now, week);
    //?
    Calendar calendarEnd = CalendarUtil.resetYearEnd(toCalendar(now));

    List<String> list = new ArrayList<String>();
    Calendar firstWeekOfSpecifyDateYearCalendar = toCalendar(firstWeekOfSpecifyDateYear);
    for (Calendar calendar = firstWeekOfSpecifyDateYearCalendar; calendar.before(calendarEnd); calendar
            .add(Calendar.DAY_OF_YEAR, 7)) {
        list.add(CalendarUtil.toString(calendar, datePattern));
    }
    return list;
}

From source file:com.tservice.Logica.PersistenceFacede.java

private boolean licenciaVigente(Publicante pu) {

    boolean vigente = false;
    List<Factura> facturas = new LinkedList<>();

    for (Factura fac : pu.getFacturas()) {
        facturas.add(fac);/*w w  w. j  a v a2s  . co m*/

        Factura facturaActual = getFacturaActual(facturas);

        //Si tiene factura actual
        if (facturaActual != null) {

            Date fechaActual = facturaActual.getFecha();
            int vigenciaDias = facturaActual.getLicencias().getVigenciaDias();
            Date fechaVencimiento;

            System.out.println("Dias vigencia " + vigenciaDias);
            //Sumar dias a fecha
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(fechaActual);
            calendar.add(Calendar.DAY_OF_YEAR, vigenciaDias);
            fechaVencimiento = calendar.getTime();

            System.out.println("Fecha " + vigenciaDias);

            //Si la fecha de vencimiento es menor o igual a la fecha actual
            vigente = fechaVencimiento.after(new Date()) || fechaVencimiento.equals(new Date());

        }
    }
    return vigente;
}

From source file:captureplugin.drivers.dreambox.connector.DreamboxConnector.java

/**
 * @param config//from   ww w.j av  a  2  s .  co m
 *          DreamboxConfig
 * @return List of recordings on the dreambox
 */
public ProgramTime[] getRecordings(DreamboxConfig config) {
    ArrayList<ProgramTime> programs = new ArrayList<ProgramTime>();

    ArrayList<HashMap<String, String>> timers = getTimers();

    if (timers == null) {
        return new ProgramTime[0];
    }

    for (HashMap<String, String> timer : timers) {

        DreamboxChannel channel = config.getDreamboxChannelForRef(timer.get("e2servicereference"));

        if (channel != null) {
            Channel tvbchannel = config.getChannel(channel);
            if (tvbchannel != null) {
                Calendar begin = Calendar.getInstance();
                begin.setTimeInMillis(getLong(timer.get("e2timebegin")) * 1000);
                int beginMinutes = begin.get(Calendar.HOUR_OF_DAY) * 60 + begin.get(Calendar.MINUTE);

                Calendar end = Calendar.getInstance();
                end.setTimeInMillis(getLong(timer.get("e2timeend")) * 1000);

                int endMinutes = end.get(Calendar.HOUR_OF_DAY) * 60 + end.get(Calendar.MINUTE);
                if (endMinutes < beginMinutes) {
                    endMinutes += 24 * 60;
                }

                Calendar runner = (Calendar) begin.clone();

                long days = end.get(Calendar.DAY_OF_YEAR) - begin.get(Calendar.DAY_OF_YEAR);
                if (end.get(Calendar.YEAR) != begin.get(Calendar.YEAR)) {
                    days = 1;
                }

                for (int i = 0; i <= days; i++) {
                    Iterator<Program> it = Plugin.getPluginManager().getChannelDayProgram(new Date(runner),
                            tvbchannel);
                    boolean found = false;

                    while (it.hasNext() && !found) {
                        Program prog = it.next();
                        int progTime = prog.getHours() * 60 + prog.getMinutes() + (i * 24 * 60);

                        if (progTime >= beginMinutes - 15 && progTime <= endMinutes + 15
                                && prog.getTitle().trim().equalsIgnoreCase(timer.get("e2name").trim())) {

                            found = true;
                            programs.add(new ProgramTime(prog, begin.getTime(), end.getTime()));
                        }
                    }

                    runner.add(Calendar.HOUR_OF_DAY, 24);
                }

            }
        }
    }

    return programs.toArray(new ProgramTime[programs.size()]);
}

From source file:com.fengduo.bee.commons.util.DateViewTools.java

public static Date getDateBefore(int before) {
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.DAY_OF_YEAR, -before);
    cal.set(Calendar.HOUR_OF_DAY, cal.getActualMaximum(Calendar.HOUR_OF_DAY));
    return cal.getTime();
}

From source file:com.webbfontaine.valuewebb.model.util.Utils.java

public static int daysNumberUntilYearEnd(Calendar cal) {

    int numberOfDaysInYear = isLeapYear(cal.get(Calendar.YEAR)) ? 366 : 365;

    return numberOfDaysInYear - cal.get(Calendar.DAY_OF_YEAR);
}

From source file:org.auraframework.integration.test.http.AuraFrameworkServletHttpTest.java

/**
 * Test that AuraFrameworkServlet inspects the date header in the request and sends 200 even though
 * If-Modified-Since header indicates that resource is not stale, but has no fwUid or nonce
 *//*from   w  ww.  java  2s.co  m*/
@Test
public void testResourceCachingWithoutUidNonce() throws Exception {
    Calendar stamp = Calendar.getInstance();
    stamp.add(Calendar.DAY_OF_YEAR, 45);

    Header[] headers = new Header[] { new BasicHeader(HttpHeaders.IF_MODIFIED_SINCE,
            new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz").format(stamp.getTime())) };

    HttpGet get = obtainGetMethod(sampleBinaryResourcePath, false, headers);
    HttpResponse httpResponse = perform(get);
    int statusCode = getStatusCode(httpResponse);
    String response = getResponseBody(httpResponse);
    get.releaseConnection();
    assertEquals("Expected server to return a 200 for unexpired cache without fwUid or nonce.",
            HttpStatus.SC_OK, statusCode);
    assertNotNull(response);
    assertDefaultAntiClickjacking(httpResponse, true, false);
}

From source file:com.adsapient.shared.service.FiltersService.java

public static int getImpressionsForCampainInDay(Integer campainId, boolean increaseCache,
        boolean isImpression) {
    StringBuffer stringBuffer = new StringBuffer();

    Calendar beginDate = Calendar.getInstance();

    int campainImpressionsLocal = 0;
    String key = new StringBuffer("campain").append(campainId).append("day")
            .append(beginDate.get(Calendar.DAY_OF_YEAR)).toString();

    if (campainImpressions.containsKey(key)) {
        campainImpressionsLocal = ((Integer) campainImpressions.get(key)).intValue();
    } else {/* w w  w . j  a  v a 2s. c om*/
        beginDate.add(Calendar.DAY_OF_YEAR, -1);

        Collection parametersCollection = new ArrayList();

        campainImpressions.put(key, new Integer(campainImpressionsLocal));
    }

    if (increaseCache && isImpression) {
        campainImpressionsLocal++;
        campainImpressions.put(key, new Integer(campainImpressionsLocal));
    }

    return campainImpressionsLocal;
}

From source file:com.fdu.jira.plugin.gadget.timesheet.GroupTimeSheetResource.java

protected Map<String, Object> getVelocityParams(int numOfWeeks, int reportingDay, String targetGroupName,
        Long projectId) {//from ww  w .j a  va  2  s. c  o m
    Map<String, Object> params = new HashMap<String, Object>();
    final User user = authenticationContext.getLoggedInUser();
    TimeZone timezone = timeZoneManager.getLoggedInUserTimeZone();

    params.put("loggedin", user != null);
    params.put("license", LicenseUtil.getStatus(licenseManager));

    /* anonymous access or gadget not configured */ {
        if (user == null || targetGroupName == null || targetGroupName.length() == 0)
            return params;
    }

    final I18nBean i18nBean = new I18nBean(user);

    final Calendar[] dates = CalendarUtil.getDatesRange(reportingDay, numOfWeeks, timezone);
    final Calendar startDate = dates[0], endDate = dates[1];

    try {
        Set<User> users = null;
        if (permissionManager.hasPermission(Permissions.USER_PICKER, user)) {
            users = userUtil.getAllUsersInGroupNames(Arrays.asList(new String[] { targetGroupName }));
        }

        // for better diagnosability
        params.put("targetGroup", targetGroupName);

        if (users == null || users.size() == 0) {
            return params;
        }

        // get time spents
        com.fdu.jira.plugin.report.timesheet.TimeSheet ts = new com.fdu.jira.plugin.report.timesheet.TimeSheet(
                dateTimeFormatterFactory, applicationProperties, permissionManager, worklogManager,
                issueManager, searchProvider, visibilityValidator, fieldVisibilityManager, userUtil,
                searchRequestService, authenticationContext, timeZoneManager, licenseManager);

        ts.getTimeSpents(user, startDate.getTime(), endDate.getTime(), null, false, null,
                new String[] { targetGroupName }, projectId, null, null, null, null);

        // pass parameters
        if (projectId != null) {
            Project project = projectManager.getProjectObj(projectId);
            params.put("project", project);
        }
        params.put("users", users);
        params.put("fieldVisibility", fieldVisibilityManager);
        String dpStartDate = CalendarUtil.toDatePickerString(startDate, dateTimeFormatterFactory,
                authenticationContext);
        params.put("startDate", dpStartDate);
        endDate.add(Calendar.DAY_OF_YEAR, -1); // timeshet report will add 1 day
        String dpEndDate = CalendarUtil.toDatePickerString(endDate, dateTimeFormatterFactory,
                authenticationContext);
        params.put("endDate", dpEndDate);
        params.put("textUtil", new TextUtil(i18nBean, timezone));
        params.put("outlookDate",
                dateTimeFormatterFactory.formatter().withStyle(DateTimeStyle.DATE).forLoggedInUser());
        params.put("weekDays", ts.getWeekDays());
        params.put("userWorkLog", ts.getUserWorkLog());
        params.put("weekTotalTimeSpents", ts.getWeekTotalTimeSpents());
    } catch (Exception e) {
        e.printStackTrace();
    }

    return params;

}

From source file:com.heliumv.api.machine.MachineApi.java

@GET
@Path("/planningview")
public PlanningView getPlanningView(@QueryParam(Param.USERID) String userId, @QueryParam("dateMs") Long dateMs,
        @QueryParam("days") Integer days, @QueryParam(Param.LIMIT) Integer limit,
        @QueryParam(Param.STARTINDEX) Integer startIndex, @QueryParam(Filter.HIDDEN) Boolean filterWithHidden,
        @QueryParam("filter_startdate") Boolean filterStartDate,
        @QueryParam(With.DESCRIPTION) Boolean withDescription)
        throws RemoteException, NamingException, EJBExceptionLP {
    PlanningView planningView = new PlanningView();
    if (connectClient(userId) == null)
        return planningView;

    planningView.setMachineList(getMachinesImpl(limit, startIndex, filterWithHidden));

    if (filterStartDate == null) {
        filterStartDate = new Boolean(false);
    }//from  w ww  .  j  av  a 2  s  . c om

    if (dateMs == null) {
        dateMs = new Long(System.currentTimeMillis());
    }
    if (days == null) {
        days = new Integer(1);
    }

    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(dateMs);
    c.add(Calendar.DAY_OF_YEAR, days);
    long endDateMs = c.getTimeInMillis();
    planningView.setOpenWorkList(productionApi.getOpenWorkEntriesImpl(limit, startIndex,
            filterStartDate ? dateMs : null, endDateMs));
    planningView.setMachineGroupList(getMachineGroupsImpl(limit, startIndex));
    Map<Integer, MachineAvailabilityEntryList> mapAvailability = new HashMap<Integer, MachineAvailabilityEntryList>();
    for (MachineEntry machine : planningView.getMachineList().getEntries()) {
        mapAvailability.put(machine.getId(),
                getAvailabilitiesImpl(machine.getId(), dateMs, days, withDescription));
    }
    planningView.setMachineAvailabilityMap(mapAvailability);
    return planningView;
}