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.davidmendoza.esu.web.EstudiaController.java
@SuppressWarnings("unchecked") @RequestMapping(value = "/popular/{posicion}", method = RequestMethod.GET) @ResponseBody/*from w w w. j ava 2 s. co m*/ public Map popular(@PathVariable Integer posicion) throws ParseException { log.info("Populares Estudia({})", posicion); Map resultado = new HashMap(); SimpleDateFormat sdf = new SimpleDateFormat("EEEE", new Locale("es")); Popular popular = publicacionService.obtieneSiguientePopularEstudia(posicion); popular.getPublicacion().getArticulo() .setVistas(publicacionService.agregarVista(popular.getPublicacion().getArticulo())); Trimestre t = trimestreService .obtiene(popular.getPublicacion().getAnio() + popular.getPublicacion().getTrimestre()); if (t != null) { Calendar cal = new GregorianCalendar(Locale.ENGLISH); cal.setTime(t.getInicia()); cal.add(Calendar.SECOND, 1); cal.set(Calendar.DAY_OF_WEEK, obtieneDia(popular.getPublicacion().getDia())); NumberFormat nf = NumberFormat.getInstance(); int weeks = ((Long) nf.parse(popular.getPublicacion().getLeccion().substring(1))).intValue(); if (popular.getPublicacion().getDia().equals("sabado")) { weeks--; } cal.add(Calendar.WEEK_OF_YEAR, weeks); Date hoy = cal.getTime(); resultado.put("dia", hoy); resultado.put("diaString", sdf.format(hoy)); } resultado.put("publicacion", popular.getPublicacion()); resultado.put("posicion", popular.getId()); return resultado; }
From source file:com.bjorsond.android.timeline.utilities.Utilities.java
public static int getWeekOfDate(Date date) { Calendar cal1 = Calendar.getInstance(); cal1.setTime(date);/* www . ja v a2s . c o m*/ return cal1.get(Calendar.WEEK_OF_YEAR); }
From source file:DateUtil.java
/** * Returns the milliseconds until the next Period, as based on the difference * between the current cursor and the Period. If the current cursor is at the * start of a Period, ignoring milliseconds, 0 is returned. * /*from w w w . j a va 2s . c om*/ * @param u * @return milliseconds until next period. */ public long msToNextPeriod(Period u) { long ms = 0; switch (u) { case YEAR: mCal.set(mCursor.mYear + 1, 0, 0, 0, 0, 0); ms = mCal.getTimeInMillis() - mCursor.mMillis; if (ms == YEAR_MS) ms = 0; break; case QUARTER: if (mCursor.mMonth >= 9) mCal.set(mCursor.mYear + 1, 0, 0, 0, 0, 0); else if (mCursor.mMonth >= 6) mCal.set(mCursor.mYear, 9, 0, 0, 0, 0); else if (mCursor.mMonth >= 3) mCal.set(mCursor.mYear, 6, 0, 0, 0, 0); else mCal.set(mCursor.mYear, 3, 0, 0, 0, 0); ms = mCal.getTimeInMillis() - mCursor.mMillis; if (ms == QUARTER_MS) ms = 0; break; case MONTH: if (mCursor.mMonth == 11) mCal.set(mCursor.mYear + 1, 0, 0, 0, 0, 0); else mCal.set(mCursor.mYear, mCursor.mMonth + 1, 0, 0, 0, 0); ms = mCal.getTimeInMillis() - mCursor.mMillis; if (ms == MONTH_MS) ms = 0; break; case WEEK: mCal.setTimeInMillis(mCursor.mMillis); int first = mCal.getFirstDayOfWeek(); mCal.add(Calendar.WEEK_OF_YEAR, 1); mCal.set(Calendar.DAY_OF_WEEK, first); mCal.set(Calendar.HOUR_OF_DAY, 0); mCal.set(Calendar.MINUTE, 0); mCal.set(Calendar.SECOND, 0); mCal.set(Calendar.MILLISECOND, 0); ms = mCal.getTimeInMillis() - mCursor.mMillis; if (ms == WEEK_MS) ms = 0; break; case DAY: if (mCursor.mMinute == 0 && mCursor.mHour == 0) return 0; ms = ((60 - mCursor.mMinute) + (60 * (24 - mCursor.mHour))) * MINUTE_MS; break; case AMPM: if (mCursor.mMinute == 0 && (mCursor.mHour == 0 || mCursor.mHour == 12)) return 0; ms = ((60 - mCursor.mMinute) + (60 * (24 - (mCursor.mHour % 12)))) * MINUTE_MS; break; case HOUR: if (mCursor.mMinute == 0) return 0; ms = (60 - mCursor.mMinute) * MINUTE_MS; break; case MINUTE: default: if (mCursor.mSecond == 0) return 0; ms = (60 - mCursor.mSecond) * SECOND_MS; break; } return ms; }
From source file:org.openmrs.module.dominicamodule.web.controller.EditPatientDrugsPortletController.java
Date getExpireDateFromDuration(Date date, DrugOrderExtension doe) { Calendar cal = Calendar.getInstance(); cal.setTime(date);//w ww. j a v a 2 s . co m switch (DurationUnit.values()[doe.getDurationUnit()]) { case hours: cal.add(Calendar.HOUR, doe.getDuration()); break; case days: cal.add(Calendar.DAY_OF_YEAR, doe.getDuration()); break; case weeks: cal.add(Calendar.WEEK_OF_YEAR, doe.getDuration()); break; case months: cal.add(Calendar.MONTH, doe.getDuration()); break; case years: cal.add(Calendar.YEAR, doe.getDuration()); break; } return cal.getTime(); }
From source file:edu.jhuapl.graphs.jfreechart.JFreeChartTimeSeriesGraphSourceTestCase.java
private JFreeChartTimeSeriesGraphSource getComplexGraph() throws GraphException { Calendar base = Calendar.getInstance(); base.set(Calendar.WEEK_OF_YEAR, 6); Random r = new Random(); List<TimePoint> ps1 = new LinkedList<TimePoint>(); List<TimePoint> ps2 = new LinkedList<TimePoint>(); List<TimePoint> ps3 = new LinkedList<TimePoint>(); for (int count = 0; count < 4; count += 1) { base.set(Calendar.DAY_OF_WEEK, 2); addPoint(base.getTime(), ps2, r); // now generate five points for ps1 and p23, the daily sets addPoint(base.getTime(), ps1, r); addPoint(base.getTime(), ps3, r, "showPoint?week=" + count + "&day=0", null); for (int i = 1; i < 5; i += 1) { base.add(Calendar.DAY_OF_WEEK, 1); addPoint(base.getTime(), ps1, r); addPoint(base.getTime(), ps3, r, "showPoint?week=" + count + "&day=" + i, null); }/*w ww . j a va 2 s . co m*/ base.set(Calendar.DAY_OF_WEEK, 1); base.add(Calendar.WEEK_OF_YEAR, 1); } List<DefaultTimeSeries> series = new LinkedList<DefaultTimeSeries>(); Map<String, Object> s1Md = new HashMap<String, Object>(); s1Md.put(GraphSource.SERIES_TIME_RESOLUTION, TimeResolution.DAILY); s1Md.put(GraphSource.SERIES_SHAPE, new Ellipse2D.Float(-5, -5, 10, 10)); s1Md.put(GraphSource.SERIES_TITLE, "Frederick County Counts"); series.add(new DefaultTimeSeries(ps1, s1Md)); Map<String, Object> s2Md = new HashMap<String, Object>(); s2Md.put(GraphSource.SERIES_TIME_RESOLUTION, TimeResolution.WEEKLY); s2Md.put(GraphSource.SERIES_SHAPE, new Ellipse2D.Float(-7, -7, 14, 14)); s2Md.put(GraphSource.SERIES_TITLE, "NCR Counts"); series.add(new DefaultTimeSeries(ps2, s2Md)); Map<String, Object> s3Md = new HashMap<String, Object>(); s3Md.put(GraphSource.SERIES_TIME_RESOLUTION, TimeResolution.DAILY); s3Md.put(GraphSource.SERIES_SHAPE, new Rectangle2D.Float(-3, -3, 6, 6)); s3Md.put(GraphSource.SERIES_TITLE, "Carroll County Counts"); series.add(new DefaultTimeSeries(ps3, s3Md)); Map<String, Object> params = new HashMap<String, Object>(); params.put(GraphSource.BACKGROUND_COLOR, Color.BLUE); params.put(GraphSource.GRAPH_TITLE, "Counts"); params.put(GraphSource.GRAPH_X_LABEL, "Time"); params.put(GraphSource.GRAPH_Y_LABEL, "Total Counts"); return new JFreeChartTimeSeriesGraphSource(series, params); }
From source file:org.jfree.data.time.Week.java
/** * Creates a time period for the week in which the specified date/time * falls, calculated relative to the specified time zone. * * @param time the date/time (<code>null</code> not permitted). * @param zone the time zone (<code>null</code> not permitted). * @param locale the locale (<code>null</code> not permitted). * * @since 1.0.7/* w w w. j a v a 2s . co m*/ */ public Week(Date time, TimeZone zone, Locale locale) { ParamChecks.nullNotPermitted(time, "time"); ParamChecks.nullNotPermitted(zone, "zone"); ParamChecks.nullNotPermitted(locale, "locale"); Calendar calendar = Calendar.getInstance(zone, locale); calendar.setTime(time); // sometimes the last few days of the year are considered to fall in // the *first* week of the following year. Refer to the Javadocs for // GregorianCalendar. int tempWeek = calendar.get(Calendar.WEEK_OF_YEAR); if (tempWeek == 1 && calendar.get(Calendar.MONTH) == Calendar.DECEMBER) { this.week = 1; this.year = (short) (calendar.get(Calendar.YEAR) + 1); } else { this.week = (byte) Math.min(tempWeek, LAST_WEEK_IN_YEAR); int yyyy = calendar.get(Calendar.YEAR); // alternatively, sometimes the first few days of the year are // considered to fall in the *last* week of the previous year... if (calendar.get(Calendar.MONTH) == Calendar.JANUARY && this.week >= 52) { yyyy--; } this.year = (short) yyyy; } peg(calendar); }
From source file:org.codice.ddf.commands.catalog.CqlCommands.java
protected long getFilterStartTime() { if (lastSeconds > 0) { return filterCurrentTime - TimeUnit.SECONDS.toMillis(lastSeconds); } else if (lastMinutes > 0) { return filterCurrentTime - TimeUnit.MINUTES.toMillis(lastMinutes); } else if (lastHours > 0) { return filterCurrentTime - TimeUnit.HOURS.toMillis(lastHours); } else if (lastDays > 0) { return filterCurrentTime - TimeUnit.DAYS.toMillis(lastDays); } else if (lastWeeks > 0) { Calendar weeks = GregorianCalendar.getInstance(); weeks.setTimeInMillis(filterCurrentTime); weeks.add(Calendar.WEEK_OF_YEAR, -1 * lastWeeks); return weeks.getTimeInMillis(); } else if (lastMonths > 0) { Calendar months = GregorianCalendar.getInstance(); months.setTimeInMillis(filterCurrentTime); months.add(Calendar.MONTH, -1 * lastMonths); return months.getTimeInMillis(); } else {//from w ww . j a v a 2 s .c om return 0; } }
From source file:org.op4j.functions.FnCalendar.java
/** * <p>/*from w w w.ja va2 s . c o m*/ * Modifies a Calendar by setting the "week" property (<tt>java.util.Calendar.WEEK_OF_YEAR</tt>) * to the specified value. * </p> * * @param value the new value for the property * @return the modified Calendar */ public static final Function<Calendar, Calendar> setWeek(final int value) { return new Set(Calendar.WEEK_OF_YEAR, value); }
From source file:org.op4j.functions.FnDate.java
/** * <p>//from w w w . j a v a2 s .c o m * Modifies a Date by setting the "week" property (<tt>java.util.Calendar.WEEK_OF_YEAR</tt>) * to the specified value. * </p> * * @param value the new value for the property * @return the modified Date */ public static final Function<Date, Date> setWeek(final int value) { return new Set(Calendar.WEEK_OF_YEAR, value); }
From source file:org.nuclos.common2.DateUtils.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); cal.set(2012, 11, 24, 0, 0, 1);//ww w.j ava 2s.c om System.out.println("date: " + cal.getTime()); long l = getMillis(cal.getTime(), Calendar.WEEK_OF_YEAR); System.out.println("millis: " + l); }