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.linuxbox.enkive.statistics.removal.RemovalJob.java
/** * generates a date cooresponding to the amount of time each type of * statistic should be kept. For instance, if monthKeepTime is set to 3 then * 3 months will be subtracted from the current date and that date will be * returned// w w w.j a v a 2s . co m * * @param time * - the identifier corresponding to the amount of time to deduct */ private void setDate(int time) { Calendar cal = Calendar.getInstance(); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.MILLISECOND, 0); cal.set(Calendar.SECOND, 0); switch (time) { case REMOVAL_MONTH_ID:// month cal.add(Calendar.MONTH, -monthKeepTime); break; case REMOVAL_WEEK_ID:// week cal.add(Calendar.WEEK_OF_YEAR, -weekKeepTime); break; case REMOVAL_DAY_ID:// day cal.add(Calendar.DATE, -dayKeepTime); break; case REMOVAL_HOUR_ID:// hour cal.add(Calendar.HOUR, -hourKeepTime); break; case REMOVAL_RAW_ID:// raw cal.add(Calendar.HOUR, -rawKeepTime); } dateFilter = cal.getTime(); }
From source file:org.wso2.carbon.registry.eventing.RegistryEventDispatcher.java
public RegistryEventDispatcher() { digestQueues = new LinkedHashMap<String, Queue<DigestEntry>>(); for (String s : new String[] { "h", "d", "w", "f", "m", "y" }) { //TODO: Identify Queuing mechanisms. digestQueues.put(s, new ConcurrentLinkedQueue<DigestEntry>()); }//from ww w .ja va 2 s. c o m final ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor(); executorService.scheduleAtFixedRate(new Runnable() { public void run() { GregorianCalendar utc = new GregorianCalendar(SimpleTimeZone.getTimeZone("UTC")); Map<String, List<DigestEntry>> digestEntries = new HashMap<String, List<DigestEntry>>(); try { addToDigestEntryQueue(digestEntries, "h"); if (utc.get(Calendar.HOUR_OF_DAY) == 0) { addToDigestEntryQueue(digestEntries, "d"); if (utc.get(Calendar.DAY_OF_WEEK) == 1) { addToDigestEntryQueue(digestEntries, "w"); if (utc.get(Calendar.WEEK_OF_YEAR) % 2 != 0) { addToDigestEntryQueue(digestEntries, "f"); } } if (utc.get(Calendar.DAY_OF_MONTH) == 1) { addToDigestEntryQueue(digestEntries, "m"); if (utc.get(Calendar.DAY_OF_YEAR) == 1) { addToDigestEntryQueue(digestEntries, "y"); } } } for (Map.Entry<String, List<DigestEntry>> e : digestEntries.entrySet()) { List<DigestEntry> value = e.getValue(); Collections.sort(value, new Comparator<DigestEntry>() { public int compare(DigestEntry o1, DigestEntry o2) { if (o1.getTime() > o2.getTime()) { return -1; } else if (o1.getTime() < o2.getTime()) { return 1; } return 0; } }); StringBuffer buffer = new StringBuffer(); for (DigestEntry entry : value) { buffer.append(entry.getMessage()).append("\n\n"); } RegistryEvent<String> re = new RegistryEvent<String>(buffer.toString()); re.setTopic(RegistryEvent.TOPIC_SEPARATOR + "DigestEvent"); DispatchEvent de = new DispatchEvent(re, e.getKey(), true); Subscription subscription = new Subscription(); subscription.setTopicName(re.getTopic()); publishEvent(de, subscription, e.getKey(), true); } } catch (RuntimeException ignored) { // Eat any runtime exceptions that occurred, we don't care if the message went // or not. } } }, System.currentTimeMillis() % (1000 * 60 * 60), 1000 * 60 * 60, TimeUnit.MILLISECONDS); try { Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { executorService.shutdownNow(); } }); } catch (IllegalStateException e) { executorService.shutdownNow(); throw new IllegalStateException( "Unable to create registry event dispatcher during " + "shutdown process."); } }
From source file:edu.umm.radonc.ca_dash.model.TxInstanceFacade.java
public TreeMap<Date, SynchronizedDescriptiveStatistics> getWeeklySummaryStatsAbs(Date startDate, Date endDate, Long hospitalser, String filter, boolean includeWeekends, boolean ptflag, boolean scheduledFlag) { Calendar cal = new GregorianCalendar(); TreeMap<Date, SynchronizedDescriptiveStatistics> retval = new TreeMap<>(); //SET TO BEGINNING OF WK FOR ABSOLUTE CALC cal.setTime(startDate);/*from w w w . j ava 2s . c om*/ cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); startDate = cal.getTime(); List<Object[]> events = getDailyCounts(startDate, endDate, hospitalser, filter, false, ptflag, scheduledFlag); DateFormat df = new SimpleDateFormat("MM/dd/yy"); cal.setTime(startDate); cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); int wk = cal.get(Calendar.WEEK_OF_YEAR); int mo = cal.get(Calendar.MONTH); int yr = cal.get(Calendar.YEAR); if (mo == Calendar.DECEMBER && wk == 1) { yr = yr + 1; } else if (mo == Calendar.JANUARY && wk == 52) { yr = yr - 1; } String currYrWk = yr + "-" + String.format("%02d", wk); //String prevYrWk = ""; String prevYrWk = currYrWk; SynchronizedDescriptiveStatistics currStats = new SynchronizedDescriptiveStatistics(); int i = 0; while (cal.getTime().before(endDate) && i < events.size()) { Object[] event = events.get(i); Date d = (Date) event[0]; Long count = (Long) event[1]; cal.setTime(d); cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); wk = cal.get(Calendar.WEEK_OF_YEAR); mo = cal.get(Calendar.MONTH); yr = cal.get(Calendar.YEAR); if (mo == Calendar.DECEMBER && wk == 1) { yr = yr + 1; } else if (mo == Calendar.JANUARY && wk == 52) { yr = yr - 1; } currYrWk = yr + "-" + String.format("%02d", wk); if (!(prevYrWk.equals(currYrWk))) { GregorianCalendar lastMon = new GregorianCalendar(); lastMon.setTime(cal.getTime()); lastMon.add(Calendar.DATE, -7); retval.put(lastMon.getTime(), currStats); currStats = new SynchronizedDescriptiveStatistics(); } prevYrWk = currYrWk; currStats.addValue(count); i++; } retval.put(cal.getTime(), currStats); return retval; }
From source file:org.fire.platform.util.DateUtil.java
/** * /*from www. ja va2s .c o m*/ * */ public static int getWeek() { Calendar c = Calendar.getInstance(); c.setTime(new Date()); return c.get(Calendar.WEEK_OF_YEAR); }
From source file:com.zimbra.cs.mailbox.calendar.ZRecur.java
private Date estimateEndTimeByUntilAndHardLimits(ParsedDateTime dtStart) throws ServiceException { boolean forever = false; Calendar hardEnd = dtStart.getCalendarCopy(); Frequency freq = mFreq;//from w ww .j a va 2s . c o m if (freq == null) freq = Frequency.WEEKLY; switch (freq) { case WEEKLY: int weeks = sExpansionLimits.maxWeeks; if (weeks <= 0) forever = true; else hardEnd.add(Calendar.WEEK_OF_YEAR, weeks); break; case MONTHLY: int months = sExpansionLimits.maxMonths; if (months <= 0) forever = true; else hardEnd.add(Calendar.MONTH, months); break; case YEARLY: int years = sExpansionLimits.maxYears; if (years <= 0) forever = true; else hardEnd.add(Calendar.YEAR, years); break; case DAILY: int days = sExpansionLimits.maxDays; if (days <= 0) forever = true; else hardEnd.add(Calendar.DAY_OF_YEAR, days); break; default: int otherFreqYears = Math.max(sExpansionLimits.maxYearsOtherFreqs, 1); hardEnd.add(Calendar.YEAR, otherFreqYears); } Date d; if (forever) d = new Date(MAX_DATE_MILLIS); else d = hardEnd.getTime(); if (mUntil != null) { Date until = mUntil.getDateForRecurUntil(dtStart.getTimeZone()); if (until.before(d)) d = until; } return d; }
From source file:net.granoeste.commons.util.DateUtils.java
/** * ???// w w w. ja v a 2s. c o m * * @param cal * @param amount ex) last week : -1. the current week : 0. the next week : 1 */ public static void shiftDateOnMondayOfTheWeek(final Calendar cal, final int amount) { cal.add(Calendar.WEEK_OF_YEAR, amount); if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) { cal.add(Calendar.DATE, -6); } else { cal.add(Calendar.DATE, -cal.get(Calendar.DAY_OF_WEEK) + 2); } }
From source file:org.yccheok.jstock.charting.Utils.java
/** * Returns weekly chart data based on given stock history server. * /* w w w.j a va2s .c om*/ * @param stockHistoryServer the stock history server * @return list of weekly chart data */ public static List<ChartData> getWeeklyChartData(StockHistoryServer stockHistoryServer) { final int days = stockHistoryServer.size(); Calendar prevCalendar = null; List<ChartData> chartDatas = new ArrayList<ChartData>(); double prevPrice = 0; double openPrice = 0; double lastPrice = 0; double highPrice = Double.MIN_VALUE; double lowPrice = Double.MAX_VALUE; long volume = 0; long timestamp = 0; int count = 0; for (int i = 0; i < days; i++) { // First, determine the current data is same week as the previous // data. boolean isSameWeek = false; final long t = stockHistoryServer.getTimestamp(i); Stock stock = stockHistoryServer.getStock(t); final Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(t); if (prevCalendar != null) { int weekOfYear = calendar.get(Calendar.WEEK_OF_YEAR); int prevWeekOfYear = prevCalendar.get(Calendar.WEEK_OF_YEAR); // Is this the same week? isSameWeek = (weekOfYear == prevWeekOfYear); } else { // First time for us to enter this for loop. isSameWeek = true; openPrice = stock.getOpenPrice(); prevPrice = stock.getPrevPrice(); } if (isSameWeek == false) { // This is a new week. There must be data for previous week. assert (count > 0); ChartData chartData = ChartData.newInstance(prevPrice, openPrice, lastPrice / count, // Average last price. highPrice, lowPrice, volume / count, // Average volume. timestamp); chartDatas.add(chartData); // First day of the week. prevPrice = stock.getPrevPrice(); openPrice = stock.getOpenPrice(); lastPrice = stock.getLastPrice(); highPrice = stock.getHighPrice(); lowPrice = stock.getLowPrice(); volume = stock.getVolume(); timestamp = stock.getTimestamp(); count = 1; } else { // We will not update prevPrice and openPrice. They will remain // as the first day of the week's. lastPrice += stock.getLastPrice(); highPrice = Math.max(highPrice, stock.getHighPrice()); lowPrice = Math.min(lowPrice, stock.getLowPrice()); volume += stock.getVolume(); timestamp = stock.getTimestamp(); count++; } prevCalendar = calendar; } // Is there any data which is not being inserted yet? if (count > 0) { ChartData chartData = ChartData.newInstance(prevPrice, openPrice, lastPrice / count, highPrice, lowPrice, volume / count, timestamp); chartDatas.add(chartData); } return chartDatas; }
From source file:support.plus.reportit.rv.AllReportsRV.java
public void add_items_setup() { com.github.clans.fab.FloatingActionButton fbAddReport = (com.github.clans.fab.FloatingActionButton) findViewById( R.id.fbAddReport);/*from ww w. ja v a 2 s. c om*/ fbAddReport.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new MaterialDialog.Builder(AllReportsRV.this).title(R.string.add_report) .content(R.string.add_reportdesc) .inputType(InputType.TYPE_TEXT_FLAG_AUTO_CORRECT | InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES) .inputRange(1, 15).backgroundColor(getResources().getColor(R.color.cardColor)) .input(getString(R.string.example_work), "", new MaterialDialog.InputCallback() { @Override public void onInput(MaterialDialog dialog, CharSequence input) { String name = String.valueOf(input); File myFile2 = new File(Environment.getExternalStorageDirectory() + File.separator + "/ReportIt/Reports/" + name); if (myFile2.exists()) { Toast toast = Toast.makeText(AllReportsRV.this, R.string.error_file_exists, Toast.LENGTH_SHORT); toast.show(); return; } else { Calendar c = Calendar.getInstance(); int weekNo = c.get(Calendar.WEEK_OF_YEAR); itemTexte.add(name); rvadapter1.notifyDataSetChanged(); recyclerView1.smoothScrollToPosition(itemTexte.size()); try { File mydirectory = new File(Environment.getExternalStorageDirectory() + File.separator + "ReportIt"); boolean success = true; if (!mydirectory.exists()) { success = mydirectory.mkdir(); } if (success) { File reportsdirectory = new File( Environment.getExternalStorageDirectory() + File.separator + "/ReportIt/Reports"); boolean success2 = true; if (!reportsdirectory.exists()) { success2 = reportsdirectory.mkdir(); } if (success2) { File myFile = new File(Environment.getExternalStorageDirectory() + File.separator + "/ReportIt/Reports/" + name); if (!myFile.exists()) { myFile.createNewFile(); } } } else { } } catch (Exception e) { } } return; } }).cancelable(false).positiveText(R.string.add).negativeText(R.string.cancel).show(); } }); }
From source file:com.bjorsond.android.timeline.utilities.Utilities.java
public static Date getFirstDayOfWeek(Date dateInWeek) { Calendar cal1 = Calendar.getInstance(TimeZone.getTimeZone("Europe/Paris"), Locale.GERMANY); cal1.setTime(dateInWeek);//w w w.j ava2s . c o m int week = cal1.get(Calendar.WEEK_OF_YEAR); int year = cal1.get(Calendar.YEAR); cal1.clear(); cal1.set(Calendar.WEEK_OF_YEAR, week); cal1.set(Calendar.YEAR, year); // cal1.add(Calendar.DATE, 1);//To make the week start on monday. Not needed when locale is set as above? return cal1.getTime(); }
From source file:TripServlet.java
public Date getLastWeek() { Calendar c = Calendar.getInstance(); c = (Calendar) c.clone();/*from w ww . j a v a 2 s . c o m*/ c.add(Calendar.WEEK_OF_YEAR, -1);// last week c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek()); Date date = c.getTime(); return date; }