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.nma.util.sdcardtrac.GraphFragment.java
public void setViewport(boolean redraw) { Calendar calcView[];/*from w w w. ja v a2 s. c o m*/ // Start time calcView = new Calendar[2]; calcView[0] = Calendar.getInstance(); calcView[0].setTimeInMillis(viewPortStart); calcView[1] = (Calendar) calcView[0].clone(); if (timeInterval == null) timeInterval = "Day"; // Override with setting if (timeInterval.equals("Hour")) calcView[1].add(Calendar.HOUR_OF_DAY, -1); else if (timeInterval.equals("Day")) calcView[1].add(Calendar.DAY_OF_MONTH, -1); else if (timeInterval.equals("Week")) calcView[1].add(Calendar.WEEK_OF_YEAR, -1); else if (timeInterval.equals("Month")) calcView[1].add(Calendar.MONTH, -1); else calcView[1].add(Calendar.YEAR, -1); viewPortWidth = calcView[0].getTimeInMillis() - calcView[1].getTimeInMillis(); //Calendar.getInstance().getTimeInMillis() - calcView.getTimeInMillis(); secondSelect = false; if (storageGraph != null) { storageGraph.setViewPort(viewPortStart, viewPortWidth); if (viewPortWidth > (endTime - startTime)) storageGraph.setScrollable(false); else { storageGraph.setScrollable(true); if (!redraw) storageGraph.scrollToEnd(); } Log.d("GraphFrag", "Updated viewport to " + timeInterval + ", " + viewPortStart + " - " + viewPortWidth); } }
From source file:com.leclercb.taskunifier.gui.translations.TranslationsUtils.java
public static String translateRepeat(Repeat repeat) { if (repeat instanceof RepeatWithParent) { return Translations.getString("repeat.with_parent"); }/* w ww . j a v a 2s.co m*/ if (repeat instanceof RepeatEveryX) { if (((RepeatEveryX) repeat).getType() == Calendar.DAY_OF_MONTH) return Translations.getString("repeat.every_x_days", ((RepeatEveryX) repeat).getValue()); if (((RepeatEveryX) repeat).getType() == Calendar.WEEK_OF_YEAR) return Translations.getString("repeat.every_x_weeks", ((RepeatEveryX) repeat).getValue()); if (((RepeatEveryX) repeat).getType() == Calendar.MONTH) return Translations.getString("repeat.every_x_months", ((RepeatEveryX) repeat).getValue()); if (((RepeatEveryX) repeat).getType() == Calendar.YEAR) return Translations.getString("repeat.every_x_years", ((RepeatEveryX) repeat).getValue()); } if (repeat instanceof RepeatEveryXWeekOnDays) { List<String> days = new ArrayList<String>(); for (int i = 0; i < ((RepeatEveryXWeekOnDays) repeat).getDays().length; i++) days.add(StringValueDayOfWeek.INSTANCE.getString(((RepeatEveryXWeekOnDays) repeat).getDays()[i])); return Translations.getString("repeat.every_x_weeks_on", ((RepeatEveryXWeekOnDays) repeat).getValue(), StringUtils.join(days, ", ")); } if (repeat instanceof RepeatEveryXMonthOnDayX) { return Translations.getString("repeat.every_x_months_day_x", ((RepeatEveryXMonthOnDayX) repeat).getDay(), ((RepeatEveryXMonthOnDayX) repeat).getValue()); } if (repeat instanceof RepeatEveryXMonthOnWeekX) { return Translations.getString("repeat.every_x_months_day_of_week", StringValueWeekOfMonth.INSTANCE.getString(((RepeatEveryXMonthOnWeekX) repeat).getWeek()), StringValueDayOfWeek.INSTANCE.getString(((RepeatEveryXMonthOnWeekX) repeat).getDay()), ((RepeatEveryXMonthOnWeekX) repeat).getValue()); } return "#" + repeat.getClass().getSimpleName() + "#"; }
From source file:Time.java
/** * Return the week number of year, this day belongs to. 1st=1 and so on. * /* w w w. j av a 2 s . c om*/ * @return Week number of year of this day. */ public int getWeekOfYear() { return calendar_.get(Calendar.WEEK_OF_YEAR); }
From source file:com.frey.repo.DateUtil.java
/***************************************** * @return interger//from w w w. ja v a 2 s . co m * @ ?? ****************************************/ public static String getYearWeekFirstDay(int yearNum, int weekNum) throws ParseException { Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, yearNum); cal.set(Calendar.WEEK_OF_YEAR, weekNum); cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); // ???? String tempYear = Integer.toString(yearNum); String tempMonth = Integer.toString(cal.get(Calendar.MONTH) + 1); String tempDay = Integer.toString(cal.get(Calendar.DATE)); String tempDate = tempYear + "-" + tempMonth + "-" + tempDay; return setDateFormat(tempDate, "yyyy-MM-dd"); }
From source file:com.google.android.gms.fit.samples.basichistorysessions.MainActivity.java
/** * Return a {@link SessionReadRequest} for all speed data in the past week. *//* www. j a v a 2s . com*/ private SessionReadRequest readFitnessSession() { Log.i(TAG, "Reading History API results for session: " + SAMPLE_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); 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_SPEED) .setSessionName(SAMPLE_SESSION_NAME).build(); // [END build_read_session_request] return readRequest; }
From source file:org.eclipse.dirigible.repository.local.FileSystemRepository.java
@Override public void cleanupOldVersions() throws IOException { String versionsRoot = getVersionsPath(); synchronized (this.getClass()) { GregorianCalendar last = new GregorianCalendar(); last.add(Calendar.WEEK_OF_YEAR, -1); thresholdDate = last.getTime();/* w w w. ja v a2 s. c om*/ cleanOlderFiles(new File(versionsRoot)); } }
From source file:com.artemchep.horario.ui.fragments.master.LessonsFragment.java
private void setWeekCycle(int weekCycle) { mWeekCycle = Math.max(weekCycle, 1); if (mVirgin) { Calendar calendar = Calendar.getInstance(); int woy = calendar.get(Calendar.WEEK_OF_YEAR); int week = (woy % mWeekCycle) + 1; mWeekView.setWeekNumber(week);/* w w w . j a va 2 s .co m*/ } if (mWeekMenuItem != null) { // it can be called before creating menu mWeekMenuItem.setVisible(mWeekCycle > 1); updateWeekNumberMenuItemText(); } }
From source file:com.frey.repo.DateUtil.java
/***************************************** * @return interger/*from ww w . j a v a 2 s. c o m*/ * @ ??? ****************************************/ public static String getYearWeekEndDay(int yearNum, int weekNum) throws ParseException { Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, yearNum); cal.set(Calendar.WEEK_OF_YEAR, weekNum + 1); cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); // ???? String tempYear = Integer.toString(yearNum); String tempMonth = Integer.toString(cal.get(Calendar.MONTH) + 1); String tempDay = Integer.toString(cal.get(Calendar.DATE)); String tempDate = tempYear + "-" + tempMonth + "-" + tempDay; return setDateFormat(tempDate, "yyyy-MM-dd"); }
From source file:org.nuclos.common2.DateUtils.java
/** * Add a amount of field to given Calendar. * The returned date is always after given date if amount is positive. *//*from www. ja v a2 s . com*/ public static void montoneAdd(Calendar cal, int field, int amount) { if (amount == 0) { return; } final int sign = amount > 0 ? 1 : -1; final long millis = cal.getTimeInMillis(); if (field == QUARTER) { cal.add(Calendar.MONTH, amount * 3); } else { cal.add(field, amount); } while ((sign > 0 && cal.getTimeInMillis() < millis) || (sign < 0 && cal.getTimeInMillis() > millis)) { switch (field) { case Calendar.WEEK_OF_YEAR: field = Calendar.YEAR; cal.add(field, sign); break; case Calendar.DAY_OF_WEEK: field = Calendar.WEEK_OF_YEAR; cal.add(field, sign); break; case Calendar.DAY_OF_MONTH: field = Calendar.MONTH; cal.add(field, sign); break; case Calendar.MONTH: field = Calendar.YEAR; cal.add(field, sign); break; case QUARTER: field = Calendar.YEAR; cal.add(field, sign); break; case Calendar.YEAR: // do nothing break; default: throw new IllegalArgumentException(); } } }
From source file:org.neo4j.gis.spatial.OsmAnalysisTest.java
private SortedMap<String, Layer> exportPoints(String layerPrefix, SpatialDatabaseService spatialService, Set<User> users) {//from ww w . j av a 2 s .c o m SortedMap<String, Layer> layers = new TreeMap<String, Layer>(); int startYear = 2009; int endYear = 2011; for (int y = startYear; y <= endYear; y++) { for (int w = 1; w <= 52; w++) { if (y == 2011 && w == 36) { break; } String name = layerPrefix + "-" + y + "_"; if (w >= 10) name += w; else name += "0" + w; EditableLayerImpl layer = (EditableLayerImpl) spatialService.createLayer(name, WKBGeometryEncoder.class, EditableLayerImpl.class); layer.setExtraPropertyNames( new String[] { "user_id", "user_name", "year", "month", "dayOfMonth", "weekOfYear" }); // EditableLayerImpl layer = (EditableLayerImpl) // spatialService.getLayer(name); layers.put(name, layer); } } for (User user : users) { Node userNode = graphDb().getNodeById(user.id); System.out.println("analyzing user: " + userNode.getProperty("name")); for (Relationship r : userNode.getRelationships(Direction.INCOMING, OSMRelation.USER)) { Node changeset = r.getStartNode(); if (changeset.hasProperty("changeset")) { System.out.println("analyzing changeset: " + changeset.getProperty("changeset")); try (Transaction tx = graphDb().beginTx()) { for (Relationship nr : changeset.getRelationships(Direction.INCOMING, OSMRelation.CHANGESET)) { Node changedNode = nr.getStartNode(); if (changedNode.hasProperty("node_osm_id") && changedNode.hasProperty("timestamp")) { long timestamp = (Long) changedNode.getProperty("timestamp"); Calendar c = Calendar.getInstance(); c.setTimeInMillis(timestamp); int nodeYear = c.get(Calendar.YEAR); int nodeWeek = c.get(Calendar.WEEK_OF_YEAR); if (layers.containsKey(layerPrefix + "-" + nodeYear + "_" + nodeWeek)) { EditableLayer l = (EditableLayer) layers .get(layerPrefix + "-" + nodeYear + "_" + nodeWeek); l.add(l.getGeometryFactory() .createPoint(new Coordinate((Double) changedNode.getProperty("lon"), (Double) changedNode.getProperty("lat"))), new String[] { "user_id", "user_name", "year", "month", "dayOfMonth", "weekOfYear" }, new Object[] { user.internalId, user.name, c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH), c.get(Calendar.WEEK_OF_YEAR) }); } } } tx.success(); } } } } return layers; }