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:org.craftercms.social.services.notification.impl.NotificationServiceImpl.java
protected Date getStartDateByType(final String type) { Calendar cal = Calendar.getInstance(); if (type.equalsIgnoreCase(NotificationService.WEEKLY)) { cal.add(Calendar.WEEK_OF_YEAR, -1); return cal.getTime(); } else if (type.equalsIgnoreCase(NotificationService.DAILY)) { cal.add(Calendar.DAY_OF_MONTH, -1); return cal.getTime(); } else if (type.equalsIgnoreCase(NotificationService.INSTANT)) { return lastInstantFire; } else {/*from w ww.j a v a2 s.c o m*/ return null; } }
From source file:onl.netfishers.netshot.work.Task.java
/** * Gets the next execution date.//from w w w. j a v a2s . c o m * * @return the next execution date */ @Transient @XmlElement public Date getNextExecutionDate() { Calendar reference = Calendar.getInstance(); reference.setTime(this.scheduleReference); Calendar target = Calendar.getInstance(); Calendar inOneMinute = Calendar.getInstance(); inOneMinute.add(Calendar.MINUTE, 1); switch (this.scheduleType) { case AT: return this.scheduleReference; case DAILY: target.set(Calendar.HOUR_OF_DAY, reference.get(Calendar.HOUR_OF_DAY)); target.set(Calendar.MINUTE, reference.get(Calendar.MINUTE)); target.set(Calendar.SECOND, reference.get(Calendar.SECOND)); target.set(Calendar.MILLISECOND, 0); if (target.before(inOneMinute)) { target.add(Calendar.DAY_OF_MONTH, 1); } return target.getTime(); case WEEKLY: target.set(Calendar.HOUR_OF_DAY, reference.get(Calendar.HOUR_OF_DAY)); target.set(Calendar.MINUTE, reference.get(Calendar.MINUTE)); target.set(Calendar.SECOND, reference.get(Calendar.SECOND)); target.set(Calendar.MILLISECOND, 0); target.set(Calendar.DAY_OF_WEEK, reference.get(Calendar.DAY_OF_WEEK)); if (target.before(inOneMinute)) { target.add(Calendar.WEEK_OF_YEAR, 1); } return target.getTime(); case MONTHLY: target.set(Calendar.HOUR_OF_DAY, reference.get(Calendar.HOUR_OF_DAY)); target.set(Calendar.MINUTE, reference.get(Calendar.MINUTE)); target.set(Calendar.SECOND, reference.get(Calendar.SECOND)); target.set(Calendar.MILLISECOND, 0); target.set(Calendar.DAY_OF_MONTH, reference.get(Calendar.DAY_OF_MONTH)); if (target.before(inOneMinute)) { target.add(Calendar.MONTH, 1); } return target.getTime(); case ASAP: default: return null; } }
From source file:org.davidmendoza.esu.service.impl.InicioServiceImpl.java
@Override public Inicio ayer(Inicio inicio) { Inicio ayer = new Inicio(); Integer anio = new Integer(inicio.getAnio()); String trimestre = inicio.getTrimestre(); String leccion = inicio.getLeccion(); String dia = inicio.getDia(); if (StringUtils.isBlank(dia)) { dia = obtieneDia(new GregorianCalendar(Locale.ENGLISH).get(Calendar.DAY_OF_WEEK)); }//ww w.j a v a 2 s .c o m Trimestre t = trimestreService.obtiene(anio + trimestre); if (t != null) { try { Calendar cal = new GregorianCalendar(Locale.ENGLISH); cal.setTime(t.getInicia()); cal.add(Calendar.SECOND, 1); cal.set(Calendar.DAY_OF_WEEK, obtieneDia(dia)); int weeks = ((Long) nf.parse(leccion.substring(1))).intValue(); if (dia.equals("sabado")) { weeks--; } cal.add(Calendar.WEEK_OF_YEAR, weeks); cal.add(Calendar.DAY_OF_MONTH, -1); Date hoy = cal.getTime(); ayer.setHoy(hoy); t = trimestreService.obtiene(hoy); DateTime a = new DateTime(t.getInicia()); DateTime b = new DateTime(hoy); Weeks c = Weeks.weeksBetween(a, b); weeks = c.getWeeks(); weeks++; leccion = "l" + dosDigitos.format(weeks); ayer.setAnio(t.getNombre().substring(0, 4)); ayer.setTrimestre(t.getNombre().substring(4)); ayer.setLeccion(leccion); ayer.setDia(obtieneDia(cal.get(Calendar.DAY_OF_WEEK))); return ayer; } catch (ParseException e) { log.error("No pude poner la fecha de ayer", e); } } return null; }
From source file:com.datatorrent.apps.logstream.DimensionOperator.java
/** * returns list of time buckets for the given timestamp * * @param time// w w w .java 2 s. c om * @return */ protected List<String> getTimeBucketList(long time) { calendar.setTimeInMillis(time); List<String> timeBucketList = new ArrayList<String>(); if ((timeBucketFlags & LogstreamUtil.TIMEBUCKET_YEAR) != 0) { timeBucketList.add(String.format("Y|%04d", calendar.get(Calendar.YEAR))); } if ((timeBucketFlags & LogstreamUtil.TIMEBUCKET_MONTH) != 0) { timeBucketList.add( String.format("M|%04d%02d", calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1)); } if ((timeBucketFlags & LogstreamUtil.TIMEBUCKET_WEEK) != 0) { timeBucketList.add( String.format("W|%04d%02d", calendar.get(Calendar.YEAR), calendar.get(Calendar.WEEK_OF_YEAR))); } if ((timeBucketFlags & LogstreamUtil.TIMEBUCKET_DAY) != 0) { timeBucketList.add(String.format("D|%04d%02d%02d", calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.DAY_OF_MONTH))); } if ((timeBucketFlags & LogstreamUtil.TIMEBUCKET_HOUR) != 0) { timeBucketList.add(String.format("h|%04d%02d%02d%02d", calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.DAY_OF_MONTH), calendar.get(Calendar.HOUR_OF_DAY))); } if ((timeBucketFlags & LogstreamUtil.TIMEBUCKET_MINUTE) != 0) { timeBucketList.add(String.format("m|%04d%02d%02d%02d%02d", calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.DAY_OF_MONTH), calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE))); } if ((timeBucketFlags & LogstreamUtil.TIMEBUCKET_SECOND) != 0) { timeBucketList.add(String.format("s|%04d%02d%02d%02d%02d%02d", calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.DAY_OF_MONTH), calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), calendar.get(Calendar.SECOND))); } return timeBucketList; }
From source file:es.eucm.rage.realtime.states.elasticsearch.EsState.java
public void updatePerformanceArray(String performanceIndex, String classId, String timestamp, String name, float score) { try {//from w ww. ja va2 s .c o m GetRequest getRequest2 = new GetRequest(performanceIndex, ESUtils.getResultsType(), classId); getRequest2.fetchSourceContext(new FetchSourceContext(false)); getRequest2.storedFields("_none_"); boolean exists2 = hClient.exists(getRequest2); if (!exists2) { IndexRequest indexRequest = new IndexRequest(performanceIndex, ESUtils.getResultsType(), classId); indexRequest.source(new HashMap()); try { hClient.index(indexRequest); } catch (Exception exp) { LOG.info("Not created index"); exp.printStackTrace(); } } UpdateRequest update = new UpdateRequest(performanceIndex, ESUtils.getResultsType(), classId); Date date = new SimpleDateFormat("yyyy-MM-dd").parse(timestamp); Calendar cal = Calendar.getInstance(); cal.setTime(date); int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH); int week = cal.get(Calendar.WEEK_OF_YEAR); Map params = new HashMap(3); params.put("name", name); params.put("score", score); params.put("year", year + ""); params.put("month", month + ""); params.put("week", week + ""); Map obj = new HashMap(); List list = new ArrayList(); Map student = new HashMap(); student.put("student", name); student.put("score", score); student.put("n", 1); list.add(student); obj.put("students", list); params.put("obj", obj); Map months = new HashMap(); Map tmpStudents = new HashMap(); tmpStudents.put("students", list); months.put(month + "", tmpStudents); params.put("months", months); Map weeks = new HashMap(); weeks.put(week + "", tmpStudents); params.put("weeks", weeks); String script = "" + "if (!ctx._source.containsKey(params.year)) {" + " ctx._source[params.year] = params.obj;" + "} else if (!ctx._source[params.year].containsKey(\"students\")) {" + " ctx._source[params.year][\"students\"] = params.obj.students;" + "} else {" + " def found = false;" + " for(int i = 0; i < ctx._source[params.year].students.length; ++i){" + " def val = ctx._source[params.year].students[i];" + " if(!found && val.student == params.name){" + " found = true;" + " def n = val.n + 1;" + " val.score = ((val.score * val.n) / (n)) + (params.score / n);" + " val.n = n;" + " }" + " }" + " if (!found) {" + " ctx._source[params.year].students.add(params.obj.students[0]);" + " }" + "}" + "" + "if (!ctx._source[params.year].containsKey(\"months\")) {" + " ctx._source[params.year][\"months\"] = params.months;" + "} else if (!ctx._source[params.year][\"months\"].containsKey(params.month)) {" + " ctx._source[params.year][\"months\"][params.month] = params.months[params.month];" + "} else if (!ctx._source[params.year][\"months\"][params.month].containsKey(\"students\")) {" + " ctx._source[params.year][\"months\"][params.month][\"students\"] = params.months[params.month].students;" + "} else {" + " def found = false;" + " for(int i = 0; i < ctx._source[params.year].months[params.month].students.length; ++i){" + " def val = ctx._source[params.year].months[params.month].students[i];" + " if(!found && val.student == params.name){" + " found = true;" + " def n = val.n + 1;" + " val.score = ((val.score * val.n) / (n)) + (params.score / n);" + " val.n = n;" + " }" + " }" + " if (!found) {" + " ctx._source[params.year].months[params.month].students.add(params.months[params.month].students[0]);" + " }" + "}" + "" + "if (!ctx._source[params.year].containsKey(\"weeks\")) {" + " ctx._source[params.year][\"weeks\"] = params.weeks;" + "} else if (!ctx._source[params.year][\"weeks\"].containsKey(params.week)) {" + " ctx._source[params.year][\"weeks\"][params.week] = params.weeks[params.week];" + "} else if (!ctx._source[params.year][\"weeks\"][params.week].containsKey(\"students\")) {" + " ctx._source[params.year][\"weeks\"][params.week][\"students\"] = params.weeks[params.week].students;" + "} else {" + " def found = false;" + " for(int i = 0; i < ctx._source[params.year].weeks[params.week].students.length; ++i){" + " def val = ctx._source[params.year].weeks[params.week].students[i];" + " if(!found && val.student == params.name){" + " found = true;" + " def n = val.n + 1;" + " val.score = ((val.score * val.n) / (n)) + (params.score / n);" + " val.n = n;" + " }" + " }" + " if (!found) {" + " ctx._source[params.year].weeks[params.week].students.add(params.weeks[params.week].students[0]);" + " }" + "}"; update.script(new Script(ScriptType.INLINE, "painless", script, params)); update.scriptedUpsert(); update.retryOnConflict(50); hClient.update(update); } catch (Exception e) { LOG.error("updatePerformanceArray has failures : {}", e); } }
From source file:edu.jhuapl.openessence.controller.ReportController.java
public ReportController() { intervalMap = new HashMap<String, Integer>(); intervalMap.put("hourly", Calendar.HOUR_OF_DAY); intervalMap.put(DAILY, Calendar.DAY_OF_MONTH); intervalMap.put(WEEKLY, Calendar.WEEK_OF_YEAR); intervalMap.put(MONTHLY, Calendar.MONTH); }
From source file:com.xunlei.util.DateUtils.java
/** * <p>/*from w ww . j av a2 s.c om*/ * Checks if two calendar objects are on the same week ignoring time. * </p> * <p> * 28 Mar 2002 13:45 and 28 Mar 2002 06:01 would return true. 28 Mar 2002 13:45 and 12 Mar 2002 13:45 would return false. * </p> * * @param date1 the first date, not altered, not null * @param date2 the second date, not altered, not null * @return true if they represent the same day * @throws IllegalArgumentException if either date is <code>null</code> * @author Weapon Chung * @since 2011-4-2 10:48:50 */ public static boolean isSameWeek(Calendar cal1, Calendar cal2) { if (cal1 == null || cal2 == null) { throw new IllegalArgumentException("The date must not be null"); } return (cal1.get(Calendar.ERA) == cal2.get(Calendar.ERA) && cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) && cal1.get(Calendar.WEEK_OF_YEAR) == cal2.get(Calendar.WEEK_OF_YEAR)); }
From source file:com.baidu.rigel.biplatform.tesseract.meta.impl.TimeDimensionMemberServiceImpl.java
/** * ??/*from w w w . j av a 2s. com*/ * * @param year * @return */ private List<MiniCubeMember> genDayMembersWithWeekParentForAll(Level level, Member parentMember) throws Exception { List<MiniCubeMember> members = Lists.newArrayList(); Calendar cal = Calendar.getInstance(); int year = cal.get(Calendar.YEAR); int weekNow = cal.get(Calendar.WEEK_OF_YEAR); cal.set(Calendar.MONTH, Calendar.JANUARY); cal.set(Calendar.DATE, 1); Date firstWeek = getFirstDayOfWeek(cal.getTime()); cal.setTime(firstWeek); int week = 1; SimpleDateFormat sf = new SimpleDateFormat("yyyyMMdd"); while (week <= weekNow) { String day = sf.format(cal.getTime()); MiniCubeMember dayMember = new MiniCubeMember(day); String caption = year + "" + week + "-" + day; dayMember.setCaption(caption); dayMember.setLevel(level); dayMember.setParent(parentMember); dayMember.setName(day); dayMember.setVisible(true); for (int i = 0; i <= 6; i++) { day = sf.format(cal.getTime()); dayMember.getQueryNodes().add(day); cal.add(Calendar.DATE, 1); } members.add(dayMember); // cal.add(Calendar.DATE, 1); week++; } return members; }
From source file:com.jabyftw.easiercommands.Util.java
/** * Source: Essentials (found through Ban-Management) * <b>Letters used:</b> y mo w d h m s * * @param time string with the time, eg: "3w4h" - three weeks and four hours * @return the time in milliseconds/*from w w w.j a v a 2s . c om*/ * @see <a href=https://github.com/BanManagement/BanManager/blob/master/src/main/java/me/confuser/banmanager/util/DateUtils.java>Credits to Essentials</a> */ public static long parseTimeDifference(@NotNull String time) { Pattern timePattern = Pattern.compile("(?:([0-9]+)\\s*y[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*mo[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*w[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*d[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*h[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*m[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*(?:s[a-z]*)?)?", Pattern.CASE_INSENSITIVE); Matcher matcher = timePattern.matcher(time); int years = 0, months = 0, weeks = 0, days = 0, hours = 0, minutes = 0, seconds = 0; boolean found = false; while (matcher.find()) { if (matcher.group() == null || matcher.group().isEmpty()) { continue; } for (int i = 0; i < matcher.groupCount(); i++) { if (matcher.group(i) != null && !matcher.group(i).isEmpty()) { found = true; break; } } if (found) { if (matcher.group(1) != null && !matcher.group(1).isEmpty()) years = Integer.parseInt(matcher.group(1)); if (matcher.group(2) != null && !matcher.group(2).isEmpty()) months = Integer.parseInt(matcher.group(2)); if (matcher.group(3) != null && !matcher.group(3).isEmpty()) weeks = Integer.parseInt(matcher.group(3)); if (matcher.group(4) != null && !matcher.group(4).isEmpty()) days = Integer.parseInt(matcher.group(4)); if (matcher.group(5) != null && !matcher.group(5).isEmpty()) hours = Integer.parseInt(matcher.group(5)); if (matcher.group(6) != null && !matcher.group(6).isEmpty()) minutes = Integer.parseInt(matcher.group(6)); if (matcher.group(7) != null && !matcher.group(7).isEmpty()) seconds = Integer.parseInt(matcher.group(7)); break; } } if (!found) throw new IllegalArgumentException("Date can't be parsed"); if (years > 20) throw new IllegalArgumentException("Date is too big"); Calendar calendar = new GregorianCalendar(); if (years > 0) calendar.add(Calendar.YEAR, years); if (months > 0) calendar.add(Calendar.MONTH, months); if (weeks > 0) calendar.add(Calendar.WEEK_OF_YEAR, weeks); if (days > 0) calendar.add(Calendar.DAY_OF_MONTH, days); if (hours > 0) calendar.add(Calendar.HOUR_OF_DAY, hours); if (minutes > 0) calendar.add(Calendar.MINUTE, minutes); if (seconds > 0) calendar.add(Calendar.SECOND, seconds); return calendar.getTimeInMillis() - System.currentTimeMillis(); }
From source file:org.mule.el.context.ServerContextTestCase.java
@Test public void dateTimeWeekOfYear() { assertEquals(Calendar.getInstance().get(Calendar.WEEK_OF_YEAR), evaluate("server.dateTime.weekOfYear")); }