List of usage examples for java.util Calendar WEEK_OF_YEAR
int WEEK_OF_YEAR
To view the source code for java.util Calendar WEEK_OF_YEAR.
Click Source Link
get
and set
indicating the week number within the current year. From source file:com.panet.imeta.job.entries.special.JobEntrySpecial.java
private long getNextWeeklyExecutionTime() { Calendar calendar = Calendar.getInstance(); long nowMillis = calendar.getTimeInMillis(); int amHour = hour; if (amHour > 12) { amHour = amHour - 12;//from w w w . j a v a 2s. c o m calendar.set(Calendar.AM_PM, Calendar.PM); } else { calendar.set(Calendar.AM_PM, Calendar.AM); } calendar.set(Calendar.HOUR, amHour); calendar.set(Calendar.MINUTE, minutes); calendar.set(Calendar.DAY_OF_WEEK, weekDay + 1); if (calendar.getTimeInMillis() <= nowMillis) { calendar.add(Calendar.WEEK_OF_YEAR, 1); } return calendar.getTimeInMillis() - nowMillis; }
From source file:de.ribeiro.android.gso.core.UntisProvider.java
/** * Synchronisiert alle verfgbaren WeekDatas im Stupid * * @param logger/*from w w w . ja v a2s .c om*/ * @param selectedStringDate * @param selectedElement * @param myType * @param htmlResponse * @param stupid * @return * @throws Exception */ public static List<ICalEvent> syncWeekData(GregorianCalendar gc, String selectedElement, Type myType, HtmlResponse htmlResponse, Stupid stupid) throws Exception { List<ICalEvent> result = new ArrayList<ICalEvent>(); int currentDayOfWeek = gc.get(Calendar.DAY_OF_WEEK); // den currentDay auf den folge Montag setzen if (currentDayOfWeek < 2) { // 1000*60*60*24 = 1 Tag! gc.setTimeInMillis(gc.getTimeInMillis() + (1000 * 60 * 60 * 24 * (2 - currentDayOfWeek))); } if (currentDayOfWeek > 6) { // 1000*60*60*24 = 1 Tag! gc.setTimeInMillis(gc.getTimeInMillis() + (1000 * 60 * 60 * 24 * 2)); } String date = ConvertToStupidDateString(gc); String selectedType = myType.type; String selectedClassIndex = getIndexOfSelectorValue(myType.elementList, selectedElement); if (selectedClassIndex == "-1" || selectedType.equalsIgnoreCase("")) { throw new Exception(selectedElement + " kann nicht synchronisiert werden! " + selectedElement + " wurde nicht in der Liste der verfgbaren Elemente gefunden!"); } while (selectedClassIndex.length() < 3) { selectedClassIndex = "0" + selectedClassIndex; } WeekData weekData = new WeekData(stupid); try { // URL setzten URL url = new URL( "https://webuntis.stadt-koeln.de/WebUntis/Ical.do?school=K175055&ajaxCommand=renderTimetable&rpt_sd=" + date + "&type=" + 1 + "&elemId=" + selectedClassIndex + "&elemType=" + selectedType); htmlResponse.dataReceived = false; htmlResponse.xmlContent = XmlOPs.readFromURL(url, Const.CONNECTIONTIMEOUT); if (htmlResponse.xmlContent.length() < 50) { // ende return null; } _logger.Info("Week downloaded!"); List<ICalEvent> events = Ical.Parse(htmlResponse.xmlContent); weekData.syncTime = new GregorianCalendar().getTimeInMillis(); weekData.addParameter("syncTime", String.valueOf(weekData.syncTime)); weekData.date = (Calendar) gc.clone(); weekData.elementId = selectedElement; weekData.addParameter("classId", selectedElement); weekData.events = events; weekData.weekId = String.valueOf(gc.get(Calendar.WEEK_OF_YEAR)); weekData.addParameter("weekId", weekData.weekId); weekData.typeId = myType.type; weekData.addParameter("typeId", weekData.typeId); weekData.weekDataVersion = "2"; weekData.addParameter("weekDataVersion", weekData.weekDataVersion); // stupid.stupidData.add(wd); } catch (Exception e) { throw e; } // prfen, ob bereits die Woche fr die Klasse und den typ vorliegt: WeekData existWeekData = null; // alle bestehden Wochen abrufen: for (int y = 0; y < stupid.stupidData.size(); y++) { existWeekData = stupid.stupidData.get(y); // prfen, ob das bestehende Element, dem neu hinzuzufgenden // entspricht(klasse,KW,Typ) if (existWeekData.elementId.equalsIgnoreCase(weekData.elementId) && existWeekData.weekId.equalsIgnoreCase(weekData.weekId) && existWeekData.typeId.equalsIgnoreCase(weekData.typeId)) { // ja,es ist eine gleiche Woche bereits vorhanden // jedes event der neuen woche prfen, ob dieses schon existiert for (int ev = 0; ev < weekData.events.size(); ev++) { ICalEvent newevent = weekData.events.get(ev); // die schulstunde vom neuen event heraussuchen int schulstunde = GetSchulstundeOfEvent(newevent); // damit die schulstunde vom bestenden stundeplan abrufen ICalEvent existingevent = GetSchulstunde(existWeekData, newevent.DTSTART.get(Calendar.DAY_OF_WEEK), schulstunde); if (existingevent != null) newevent.UID = existingevent.UID; // beide schulstunden vergleichen if (compareEvents(existingevent, newevent)) { // unterschiede gefunden newevent.UID = "diff"; if (existingevent == null) _logger.Info("Es wurden Unterschiede in den Events gefunden: Neues Event " + newevent.DESCRIPTION + " , " + newevent.SUMMARY + " , kein altes Event vorhanden!"); else { _logger.Info("Es wurden Unterschiede in den Events gefunden: Neues Event " + newevent.DESCRIPTION + " , " + newevent.SUMMARY + " , Altes Event " + existingevent.DESCRIPTION + " , " + existingevent.SUMMARY); } // ber unterschiede benachrichtigen result.add(newevent); } // das existierende event aus dem datensatz lschen existWeekData.events.remove(existingevent); } for (ICalEvent event : existWeekData.events) { event.UID = "deleted"; weekData.events.add(event); } // alle verbleibenden events aus dem existierenden datensatz // sind ausgefallene stunden // existiert schon...ersetzen weekData.isDirty = true; stupid.stupidData.set(y, weekData); return SummarizeChanges(result); } } stupid.stupidData.add(weekData); // fgt die geparste Woche den // // Hauptdaten // // hinzu stupid.sort(); return SummarizeChanges(result); }
From source file:com.redhat.rhn.frontend.action.monitoring.notification.BaseFilterEditAction.java
private List makeFrequencyTypes() { ArrayList result = new ArrayList(); result.add(lv("filter-form.jspf.daily", new Long(Calendar.DAY_OF_YEAR).toString())); result.add(lv("filter-form.jspf.weekly", new Long(Calendar.WEEK_OF_YEAR).toString())); result.add(lv("filter-form.jspf.monthly", new Long(Calendar.MONTH).toString())); localize(result);/* ww w .j a va 2s . c o m*/ return result; }
From source file:org.rapidandroid.activity.chart.ChartBroker.java
protected boolean isBefore(DateDisplayTypes displayType, Date date1, Date date2) { Calendar cal1 = Calendar.getInstance(); cal1.setTime(date1);/*from ww w. j ava 2s . c o m*/ Calendar cal2 = Calendar.getInstance(); cal2.setTime(date2); if (cal2.before(cal1)) { return false; } // i really feel like there should be a cleaner way to do this but it // escapes me if (cal1.get(Calendar.YEAR) < cal2.get(Calendar.YEAR)) { return true; } else if (cal1.get(Calendar.YEAR) > cal2.get(Calendar.YEAR) || displayType == DateDisplayTypes.Yearly) { return false; } // we know the years are the same and we're comparing less than years if (cal1.get(Calendar.MONTH) < cal2.get(Calendar.MONTH)) { return true; } else if (cal1.get(Calendar.MONTH) > cal2.get(Calendar.MONTH) || displayType == DateDisplayTypes.Monthly) { return false; } // we know months and years are the same and we're comparing less than // months if (cal1.get(Calendar.WEEK_OF_YEAR) < cal2.get(Calendar.WEEK_OF_YEAR)) { return true; } else if (cal1.get(Calendar.WEEK_OF_YEAR) > cal2.get(Calendar.WEEK_OF_YEAR) || displayType == DateDisplayTypes.Weekly) { return false; } // we know months, years, and weeks are the same and we're comparing // less than weeks if (cal1.get(Calendar.DATE) < cal2.get(Calendar.DATE)) { return true; } else if (cal1.get(Calendar.DATE) > cal2.get(Calendar.DATE) || displayType == DateDisplayTypes.Daily) { return false; } // we know months, years,weeks, and days are the same and we're // comparing less than days if (cal1.get(Calendar.HOUR) < cal2.get(Calendar.HOUR)) { return true; } // anything else is not before return false; }
From source file:com.example.sensorsample.MyActivity.java
private SessionReadRequest readSleepSession() { Log.i(TAG, "Reading History API results for session: " + SLEEP_SESSION_NAME); // [START build_read_session_request] // Set a start and end time for our query, using a start time of 1 week before this moment. Calendar cal = Calendar.getInstance(); Date now = new Date(); cal.setTime(now);/* w w w.j a va 2 s . co m*/ long endTime = cal.getTimeInMillis(); cal.add(Calendar.WEEK_OF_YEAR, -1); long startTime = cal.getTimeInMillis(); // Build a session read request SessionReadRequest readRequest = new SessionReadRequest.Builder() .setTimeInterval(startTime, endTime, TimeUnit.MILLISECONDS).read(DataType.TYPE_ACTIVITY_SEGMENT) .setSessionName(SLEEP_SESSION_NAME).build(); // [END build_read_session_request] return readRequest; }
From source file:org.olat.commons.calendar.ui.components.WeeklyCalendarComponentRenderer.java
private void renderAllDayGrid(final int year, final int weekOfYear, final List sortedAllDayEventsForWeek, final StringOutput sb, final URLBuilder ubu, final Translator translator) { final Calendar cal = CalendarUtils.getStartOfWeekCalendar(year, weekOfYear, translator.getLocale()); int dayToday = -1; final Calendar calNow = CalendarUtils.createCalendarInstance(translator.getLocale()); if ((calNow.get(Calendar.WEEK_OF_YEAR) == weekOfYear) && (calNow.get(Calendar.YEAR) == year)) { // if we are within current week, adjust dayToday dayToday = calNow.get(Calendar.DAY_OF_WEEK); }/*from w w w . j a v a 2 s .com*/ final StringOutput inset = new StringOutput(1024); int maxDayEvents = 0; for (int day = 1; day <= days; day++) { final int dayOfWeekIter = cal.get(Calendar.DAY_OF_WEEK); final Date periodBegin = cal.getTime(); inset.append("<div class=\"o_cal_wv_dlday o_cal_wv_row"); inset.append(day); if (dayOfWeekIter == dayToday) { // current day inset.append(" o_cal_wv_today"); } else if (dayOfWeekIter == Calendar.SATURDAY || dayOfWeekIter == Calendar.SUNDAY) { // holiday inset.append(" o_cal_wv_holiday"); } if (day == days) { // last day inset.append(" o_cal_wv_lastday"); } inset.append("\" style=\"height: 100%;\">"); cal.add(Calendar.DAY_OF_YEAR, 1); final Date periodEnd = cal.getTime(); // render daylong events int maxDayEventsThisDay = 0; for (final Iterator iter = sortedAllDayEventsForWeek.iterator(); iter.hasNext();) { final KalendarEventRenderWrapper eventWrapper = (KalendarEventRenderWrapper) iter.next(); final KalendarEvent event = eventWrapper.getEvent(); // skip if not within period if (event.getEnd().compareTo(periodBegin) < 0 || event.getBegin().compareTo(periodEnd) >= 0) { continue; } // increment count of number of dayevents maxDayEventsThisDay++; final boolean hideSubject = eventWrapper .getCalendarAccess() == KalendarRenderWrapper.ACCESS_READ_ONLY && !eventWrapper.getKalendarRenderWrapper().isImported() && event.getClassification() != KalendarEvent.CLASS_PUBLIC; final String escapedSubject = Formatter.escWithBR(event.getSubject()).toString(); inset.append("<div class=\"o_cal_wv_devent_wrapper\">"); inset.append("<div class=\"o_cal_wv_devent ") .append(eventWrapper.getKalendarRenderWrapper().getKalendarConfig().getCss()).append("\">"); inset.append("<div class=\"o_cal_wv_devent_content\">"); inset.append("<a href=\""); ubu.buildURI(inset, new String[] { WeeklyCalendarComponent.ID_CMD, WeeklyCalendarComponent.ID_PARAM }, new String[] { WeeklyCalendarComponent.CMD_EDIT, event.getCalendar().getCalendarID() + WeeklyCalendarComponent.ID_PARAM_SEPARATOR + event.getID() + WeeklyCalendarComponent.ID_PARAM_SEPARATOR + event.getBegin().getTime() }, isIframePostEnabled ? AJAXFlags.MODE_TOBGIFRAME : AJAXFlags.MODE_NORMAL); inset.append("\" "); if (isIframePostEnabled) { ubu.appendTarget(inset); } inset.append(" onclick=\"return o2cl();\">"); if (hideSubject) { inset.append("<i>").append(translator.translate("cal.eventdetails.hidden")).append("</i>"); } else { inset.append(escapedSubject); } inset.append("</a>"); // append any event links if (!hideSubject) { renderEventLinks(event, inset); } // closing devent_content inset.append("</div>"); // render event tooltip content renderEventTooltip(eventWrapper, escapedSubject, hideSubject, inset, ubu, translator.getLocale()); // closing devent and devent_wrapper inset.append("</div></div>"); } // events within day iterator inset.append("</div>"); if (maxDayEventsThisDay > maxDayEvents) { maxDayEvents = maxDayEventsThisDay; } } // day irterator // do not render anything if we do not have any allday events if (maxDayEvents == 0) { return; } sb.append("\n<div id=\"o_cal_wv_daylong\" style=\"height: ").append(maxDayEvents * dayEventHeightPixels) .append("px;\">"); sb.append("<div class=\"o_cal_wv_time o_cal_wv_row0\" style=\"height: 100%;\"></div>"); sb.append(inset); sb.append("</div>"); }
From source file:com.samknows.measurement.activity.SamKnowsAggregateStatViewerActivity.java
private void loadAverage(int num_weeks) { JSONArray jsonResult;// w ww. jav a2 s . c o m Calendar now = Calendar.getInstance(); long current_dtime = now.getTimeInMillis(); now.add(Calendar.WEEK_OF_YEAR, num_weeks * -1); long starting_dtime = now.getTimeInMillis(); jsonResult = dbHelper.getAverageResults(starting_dtime, current_dtime); String result = ""; for (int i = 0; i < jsonResult.length(); i++) { try { JSONObject json_data = jsonResult.getJSONObject(i); String value = json_data.getString("value"); String type = json_data.getString("type"); if (type.equals("" + TestResult.DOWNLOAD_TEST_ID)) { ((TextView) subview.findViewById(R.id.download_average)).setText("" + value); } if (type.equals("" + TestResult.UPLOAD_TEST_ID)) { ((TextView) subview.findViewById(R.id.upload_average)).setText("" + value); } if (type.equals("" + TestResult.LATENCY_TEST_ID)) { ((TextView) subview.findViewById(R.id.latency_average)).setText("" + value); } if (type.equals("" + TestResult.PACKETLOSS_TEST_ID)) { ((TextView) subview.findViewById(R.id.packetloss_average)).setText("" + value); } if (type.equals("" + TestResult.JITTER_TEST_ID)) { ((TextView) subview.findViewById(R.id.jitter_average)).setText("" + value); } } catch (JSONException e) { e.printStackTrace(); } } }
From source file:org.jfree.data.time.Week.java
/** * Returns the first millisecond of the week, evaluated using the supplied * calendar (which determines the time zone). * * @param calendar the calendar (<code>null</code> not permitted). * * @return The first millisecond of the week. * * @throws NullPointerException if <code>calendar</code> is * <code>null</code>.//from w ww. j a v a 2 s. c om */ @Override public long getFirstMillisecond(Calendar calendar) { Calendar c = (Calendar) calendar.clone(); c.clear(); c.set(Calendar.YEAR, this.year); c.set(Calendar.WEEK_OF_YEAR, this.week); c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek()); c.set(Calendar.HOUR, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); return c.getTimeInMillis(); }
From source file:org.wso2.siddhi.extension.time.DateAddFunctionExtension.java
public Calendar getProcessedCalenderInstance(String unit, Calendar calInstance, int expression) { if (unit.equals(TimeExtensionConstants.EXTENSION_TIME_UNIT_YEAR)) { calInstance.add(Calendar.YEAR, expression); } else if (unit.equals(TimeExtensionConstants.EXTENSION_TIME_UNIT_MONTH)) { calInstance.add(Calendar.MONTH, expression); } else if (unit.equals(TimeExtensionConstants.EXTENSION_TIME_UNIT_SECOND)) { calInstance.add(Calendar.SECOND, expression); } else if (unit.equals(TimeExtensionConstants.EXTENSION_TIME_UNIT_MINUTE)) { calInstance.add(Calendar.MINUTE, expression); } else if (unit.equals(TimeExtensionConstants.EXTENSION_TIME_UNIT_HOUR)) { calInstance.add(Calendar.HOUR, expression); } else if (unit.equals(TimeExtensionConstants.EXTENSION_TIME_UNIT_DAY)) { calInstance.add(Calendar.DAY_OF_MONTH, expression); } else if (unit.equals(TimeExtensionConstants.EXTENSION_TIME_UNIT_WEEK)) { calInstance.add(Calendar.WEEK_OF_YEAR, expression); } else if (unit.equals(TimeExtensionConstants.EXTENSION_TIME_UNIT_QUARTER)) { calInstance.add(Calendar.MONTH, expression * 3); }//w w w. j av a2 s. co m return calInstance; }
From source file:gov.noaa.pfel.erddap.dataset.EDDTableFromHttpGet.java
/** * This parses the directoryStructure specification. *//from w w w. ja v a 2 s .co m * @param specification e.g, stationID/10years/7days * @param dsSourceName will be filled, with [i] = a var sourceName or "". * sourceNames haven't been tested to see if they are in the dataset. * @param dsN will be filled, with [i] = the number of Calendar items, or -1 * @param dsCalendar will be filled, with [i] = the e.g., Calendar.MONTH, or -1 * @throws RuntimeException if trouble */ public static void parseDirectoryStructure(String specification, StringArray dsSourceName, IntArray dsN, IntArray dsCalendar) throws Exception { dsSourceName.clear(); dsN.clear(); dsCalendar.clear(); String parts[] = String2.split(specification, '/'); Pattern pattern = Pattern.compile("(\\d+)([A-Za-z]+)"); for (int p = 0; p < parts.length; p++) { Matcher matcher = pattern.matcher(parts[p]); if (matcher.matches()) { //e.g., 5days String units = matcher.group(2); int cal = Calendar2.unitsToConstant(units); //throws exception if (cal == Calendar.WEEK_OF_YEAR) throw new RuntimeException( String2.ERROR + " parsing directoryStructure: " + "units=" + units + " is invalid."); dsSourceName.add(""); dsN.add(String2.parseInt(matcher.group(1))); dsCalendar.add(cal); } else { dsSourceName.add(parts[p]); dsN.add(-1); dsCalendar.add(-1); } } }